Skip to content

Modern Docker Management, Designed for Everyone

chore: cleanup go syntax

Kyle Mendell1aaf95c82436
diff --git a/backend/api/handlers/events_test.go b/backend/api/handlers/events_test.go
index 11ccf3f01..9a3b589bd 100644
--- a/backend/api/handlers/events_test.go
+++ b/backend/api/handlers/events_test.go
@@ -69,7 +69,7 @@ func TestAgentEventIngestionRequiresAgentTokenAndPersists(t *testing.T) {
Severity: models.EventSeverityInfo,
Title: "Container started: web",
Description: "Container 'web' has been started",
- EnvironmentID: ptrStringInternal("0"),
+ EnvironmentID: new("0"),
Metadata: models.JSON{"source": "agent"},
}
body, err := json.Marshal(payload)
diff --git a/backend/internal/services/activity_service.go b/backend/internal/services/activity_service.go
index c5a99c290..51e3881b5 100644
--- a/backend/internal/services/activity_service.go
+++ b/backend/internal/services/activity_service.go
@@ -549,8 +549,7 @@ func (s *ActivityService) ResolveStaleAutoUpdateActivities(ctx context.Context)
status = models.ActivityStatusSuccess
message = "Auto-update completed — Arcane restarted with the updated image"
} else {
- errText := message
- errMessage = &errText
+ errMessage = new(message)
}
if _, err := s.CompleteActivity(ctx, stale[i].ID, status, message, errMessage); err != nil {
resolveErrs = append(resolveErrs, fmt.Errorf("resolve stale auto-update activity %s: %w", stale[i].ID, err))
@@ -873,8 +872,7 @@ func clampProgressPtrInternal(value *int) *int {
if value == nil {
return nil
}
- clamped := min(max(*value, 0), 100)
- return &clamped
+ return new(min(max(*value, 0), 100))
}
func cloneJSONInternal(input models.JSON) models.JSON {
diff --git a/backend/internal/services/container_registry_service.go b/backend/internal/services/container_registry_service.go
index 73fd45dd2..1d935a9a7 100644
--- a/backend/internal/services/container_registry_service.go
+++ b/backend/internal/services/container_registry_service.go
@@ -519,8 +519,7 @@ func ensureRateLimitUsedInternal(rateLimit *updaterregistry.RateLimitInfo) {
if rateLimit == nil || rateLimit.Used != nil || rateLimit.Limit == nil || rateLimit.Remaining == nil {
return
}
- used := max(*rateLimit.Limit-*rateLimit.Remaining, 0)
- rateLimit.Used = &used
+ rateLimit.Used = new(max(*rateLimit.Limit-*rateLimit.Remaining, 0))
}
func (s *ContainerRegistryService) getObservedPullsInternal(ctx context.Context, registryHost string) int64 {
diff --git a/backend/internal/services/federated_credential_service.go b/backend/internal/services/federated_credential_service.go
index 1cc3a5aa1..247757a95 100644
--- a/backend/internal/services/federated_credential_service.go
+++ b/backend/internal/services/federated_credential_service.go
@@ -256,8 +256,7 @@ func (s *FederatedCredentialService) Get(ctx context.Context, id string) (*feder
}
return nil, fmt.Errorf("failed to get federated credential: %w", err)
}
- dto := toFederatedCredentialDTOInternal(&credential)
- return &dto, nil
+ return new(toFederatedCredentialDTOInternal(&credential)), nil
}
func (s *FederatedCredentialService) Update(ctx context.Context, callerUserID string, id string, req federatedtypes.UpdateFederatedCredential) (*federatedtypes.FederatedCredential, error) {
diff --git a/backend/internal/services/federated_credential_service_test.go b/backend/internal/services/federated_credential_service_test.go
index 15490ddc8..466a606ec 100644
--- a/backend/internal/services/federated_credential_service_test.go
+++ b/backend/internal/services/federated_credential_service_test.go
@@ -311,9 +311,8 @@ func TestFederatedCredentialServiceUpdateDisableRevokesIssuedSessionsInternal(t
require.NoError(t, err)
require.NotNil(t, resp)
- disabled := false
_, err = service.Update(ctx, "admin-user", "cred-github-actions", federatedtypes.UpdateFederatedCredential{
- Enabled: &disabled,
+ Enabled: new(false),
})
require.NoError(t, err)
diff --git a/backend/internal/services/image_update_service_test.go b/backend/internal/services/image_update_service_test.go
index 5c4c1a36c..b31e02de0 100644
--- a/backend/internal/services/image_update_service_test.go
+++ b/backend/internal/services/image_update_service_test.go
@@ -546,7 +546,6 @@ func TestImageUpdateService_CheckMultipleImages_SkippedDigestPinnedReferenceClea
pinnedDigest := digest.FromString("stale-pinned-newt").String()
imageRef := "ghcr.io/fosrl/newt@" + pinnedDigest
repository := "ghcr.io/fosrl/newt"
- staleError := "failed to get remote digest"
recordID := buildSyntheticImageUpdateRecordIDInternal(repository, "latest")
require.NoError(t, db.Create(&models.ImageUpdateRecord{
ID: recordID,
@@ -555,7 +554,7 @@ func TestImageUpdateService_CheckMultipleImages_SkippedDigestPinnedReferenceClea
HasUpdate: false,
UpdateType: "digest",
CurrentVersion: "latest",
- LastError: &staleError,
+ LastError: new("failed to get remote digest"),
CheckTime: time.Now().Add(-time.Hour),
}).Error)
svc := NewImageUpdateService(db, nil, nil, nil, nil, nil, nil)
diff --git a/backend/internal/services/notification_service_test.go b/backend/internal/services/notification_service_test.go
index d0045b9f7..429e58799 100644
--- a/backend/internal/services/notification_service_test.go
+++ b/backend/internal/services/notification_service_test.go
@@ -465,9 +465,7 @@ func TestNotificationCredentialInternal_ReturnsErrorForCorruptedCiphertext(t *te
ciphertext, err := base64.StdEncoding.DecodeString(encrypted)
require.NoError(t, err)
ciphertext[len(ciphertext)-1] ^= 0xff
- corrupted := base64.StdEncoding.EncodeToString(ciphertext)
-
- require.Error(t, notifications.DecryptStringCredential(&corrupted))
+ require.Error(t, notifications.DecryptStringCredential(new(base64.StdEncoding.EncodeToString(ciphertext))))
}
func TestNotificationCredentialInternal_LeavesEmptyValuesEmpty(t *testing.T) {
diff --git a/backend/internal/services/project_service_test.go b/backend/internal/services/project_service_test.go
index ea116b2d9..aee7ac167 100644
--- a/backend/internal/services/project_service_test.go
+++ b/backend/internal/services/project_service_test.go
@@ -1596,12 +1596,11 @@ func TestProjectService_UpdateProject_AppliesStagedProjectFileChanges(t *testing
_, revision, err := projects.ReadProjectFileTree(project.Path, config.Load().ProjectScanMaxDepth, config.Load().ProjectScanSkipDirs, "compose.yaml")
require.NoError(t, err)
- content := "hello\n"
updated := "updated\n"
_, err = svc.UpdateProject(ctx, project.ID, nil, nil, nil, &revision, []projecttypes.ProjectFileChange{
{Operation: "create_folder", RelativePath: "config"},
{Operation: "create_folder", RelativePath: "archive"},
- {Operation: "create_file", RelativePath: "config/app.yaml", Content: &content},
+ {Operation: "create_file", RelativePath: "config/app.yaml", Content: new("hello\n")},
{Operation: "update_file", RelativePath: "config/app.yaml", Content: &updated},
{Operation: "rename", RelativePath: "config/app.yaml", NewName: "renamed.yaml"},
{Operation: "move", RelativePath: "config/renamed.yaml", NewParentPath: "archive"},
@@ -1640,9 +1639,8 @@ func TestProjectService_UpdateProject_RejectsStaleProjectFileRevision(t *testing
require.NoError(t, err)
require.NoError(t, os.WriteFile(filepath.Join(project.Path, "external.txt"), []byte("external\n"), 0o644))
- content := "new\n"
_, err = svc.UpdateProject(ctx, project.ID, nil, nil, nil, &revision, []projecttypes.ProjectFileChange{
- {Operation: "create_file", RelativePath: "notes.txt", Content: &content},
+ {Operation: "create_file", RelativePath: "notes.txt", Content: new("new\n")},
}, models.User{
BaseModel: models.BaseModel{ID: "u1"},
Username: "tester",
@@ -1683,9 +1681,8 @@ func TestProjectService_UpdateProject_RejectsStaleDeepProjectFileRevision(t *tes
require.NoError(t, os.MkdirAll(deepParent, 0o755))
require.NoError(t, os.WriteFile(filepath.Join(deepParent, "external.txt"), []byte("external\n"), 0o644))
- content := "new\n"
_, err = svc.UpdateProject(ctx, project.ID, nil, nil, nil, &details.FileTreeRevision, []projecttypes.ProjectFileChange{
- {Operation: "create_file", RelativePath: "notes.txt", Content: &content},
+ {Operation: "create_file", RelativePath: "notes.txt", Content: new("new\n")},
}, models.User{
BaseModel: models.BaseModel{ID: "u1"},
Username: "tester",
diff --git a/backend/internal/services/system_upgrade_service.go b/backend/internal/services/system_upgrade_service.go
index ec6547aeb..cab01f8dc 100644
--- a/backend/internal/services/system_upgrade_service.go
+++ b/backend/internal/services/system_upgrade_service.go
@@ -529,9 +529,8 @@ func (s *SystemUpgradeService) ResumeUpdateAllOnStartup(ctx context.Context) {
// result and close the job — do not re-run the agents phase.
s.recordManagerResultInternal(job, action.managerSucceeded, info.CurrentVersion)
- completedAt := time.Now()
job.Status = models.EnvironmentUpdateJobStatusCompleted
- job.CompletedAt = &completedAt
+ job.CompletedAt = new(time.Now())
if err := s.persistUpdateAllJobInternal(ctx, job); err != nil {
slog.WarnContext(ctx, "Failed to finalize resumed update-all job", "jobId", job.ID, "error", err)
return
@@ -625,9 +624,8 @@ func (s *SystemUpgradeService) runAgentsPhaseInternal(ctx context.Context, jobID
return
}
- completedAt := time.Now()
job.Status = models.EnvironmentUpdateJobStatusCompleted
- job.CompletedAt = &completedAt
+ job.CompletedAt = new(time.Now())
if err := s.persistUpdateAllJobInternal(ctx, job); err != nil {
slog.WarnContext(ctx, "update-all: failed to mark job completed", "jobId", job.ID, "error", err)
}
@@ -728,8 +726,7 @@ func updateAllAgentFailureStatusInternal(err error) models.EnvironmentUpdateResu
return models.EnvironmentUpdateResultStatusFailed
}
// The environment answered with a non-success status — reached, not offline.
- var statusErr *remenv.StatusError
- if errors.As(err, &statusErr) {
+ if _, ok := errors.AsType[*remenv.StatusError](err); ok {
return models.EnvironmentUpdateResultStatusFailed
}
return models.EnvironmentUpdateResultStatusSkippedOffline
@@ -817,10 +814,9 @@ func (s *SystemUpgradeService) persistUpdateAllJobInternal(ctx context.Context,
}
func (s *SystemUpgradeService) markUpdateAllFailedInternal(ctx context.Context, job *models.EnvironmentUpdateJob, reason string) {
- completedAt := time.Now()
job.Status = models.EnvironmentUpdateJobStatusFailed
job.Error = &reason
- job.CompletedAt = &completedAt
+ job.CompletedAt = new(time.Now())
for i := range job.Results {
if job.Results[i].Status == models.EnvironmentUpdateResultStatusUpdating {
job.Results[i].Status = models.EnvironmentUpdateResultStatusFailed
diff --git a/backend/internal/services/user_service_test.go b/backend/internal/services/user_service_test.go
index a59742b08..b49ea1d97 100644
--- a/backend/internal/services/user_service_test.go
+++ b/backend/internal/services/user_service_test.go
@@ -142,8 +142,7 @@ func TestUpdateUserPersistsFontSizeAndMapsToDto(t *testing.T) {
u := createTestUser(t, userSvc, "user-1", "fontuser")
require.Nil(t, u.FontSize, "new users default to no explicit font size")
- size := 16
- u.FontSize = &size
+ u.FontSize = new(16)
_, err := userSvc.UpdateUser(ctx, u)
require.NoError(t, err)
diff --git a/backend/pkg/libarcane/activity/writer.go b/backend/pkg/libarcane/activity/writer.go
index 3cccb3ca4..06309d28c 100644
--- a/backend/pkg/libarcane/activity/writer.go
+++ b/backend/pkg/libarcane/activity/writer.go
@@ -224,8 +224,7 @@ func (w *Writer) updateLayerProgressInternal(id, status string, rawDetail any) *
}
}
- progress := max(min(int((weighted/float64(len(w.layers)))*100), 100), 0)
- return &progress
+ return new(max(min(int((weighted/float64(len(w.layers)))*100), 100), 0))
}
func (w *Writer) enqueueMessageInternal(message writerAppendMessage) {
diff --git a/backend/pkg/projects/compose.go b/backend/pkg/projects/compose.go
index fd63d5e54..ce382fa53 100644
--- a/backend/pkg/projects/compose.go
+++ b/backend/pkg/projects/compose.go
@@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/flags"
"github.com/docker/compose/v5/pkg/api"
- composev2 "github.com/docker/compose/v5/pkg/compose"
+ "github.com/docker/compose/v5/pkg/compose"
"github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane"
"github.com/moby/moby/client"
)
@@ -29,8 +29,8 @@ func NewClient(ctx context.Context) (*Client, error) {
}
composeCLI := wrapDockerCLIWithInspectCompatibilityInternal(cli)
- svc, err := composev2.NewComposeService(composeCLI,
- composev2.WithPrompt(composev2.AlwaysOkPrompt()),
+ svc, err := compose.NewComposeService(composeCLI,
+ compose.WithPrompt(compose.AlwaysOkPrompt()),
)
if err != nil {
return nil, err
diff --git a/backend/pkg/projects/project_files.go b/backend/pkg/projects/project_files.go
index 4af7c410d..a13d65b1b 100644
--- a/backend/pkg/projects/project_files.go
+++ b/backend/pkg/projects/project_files.go
@@ -144,8 +144,7 @@ func ApplyProjectFileDrafts(projectPath string, drafts []project.ProjectFileDraf
if draft.IsDirectory {
operation = project.FileOpCreateFolder
} else {
- contentValue := draft.Content
- content = &contentValue
+ content = new(draft.Content)
}
changes = append(changes, project.ProjectFileChange{
Operation: operation,
diff --git a/backend/pkg/projects/project_files_test.go b/backend/pkg/projects/project_files_test.go
index 822786923..bb88912a7 100644
--- a/backend/pkg/projects/project_files_test.go
+++ b/backend/pkg/projects/project_files_test.go
@@ -81,9 +81,6 @@ func TestApplyProjectFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testing.
projectDir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(projectDir, "compose.yaml"), []byte("services: {}\n"), 0o644))
- content := "safe\n"
- protectedDescendantContent := "bad\n"
- binaryContent := string([]byte{0})
testCases := []struct {
name string
change project.ProjectFileChange
@@ -93,7 +90,7 @@ func TestApplyProjectFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testing.
change: project.ProjectFileChange{
Operation: "create_file",
RelativePath: "../escape.txt",
- Content: &content,
+ Content: new("safe\n"),
},
},
{
@@ -116,7 +113,7 @@ func TestApplyProjectFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testing.
change: project.ProjectFileChange{
Operation: "create_file",
RelativePath: "compose.yaml/child.yaml",
- Content: &protectedDescendantContent,
+ Content: new("bad\n"),
},
},
{
@@ -124,7 +121,7 @@ func TestApplyProjectFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testing.
change: project.ProjectFileChange{
Operation: "create_file",
RelativePath: "binary.txt",
- Content: &binaryContent,
+ Content: new(string([]byte{0})),
},
},
}
@@ -201,9 +198,8 @@ func TestApplyProjectFileChanges_UsesRevisionConflictDetection(t *testing.T) {
require.NoError(t, err)
require.NoError(t, os.WriteFile(filepath.Join(projectDir, "notes.txt"), []byte("changed elsewhere\n"), 0o644))
- content := "new\n"
err = ApplyProjectFileChanges(projectDir, []project.ProjectFileChange{
- {Operation: "update_file", RelativePath: "notes.txt", Content: &content},
+ {Operation: "update_file", RelativePath: "notes.txt", Content: new("new\n")},
}, ProjectFileApplyOptions{
ExpectedRevision: revision,
ComposeFileName: "compose.yaml",
@@ -219,11 +215,10 @@ func TestApplyProjectFileChanges_AppliesOrderedTextFileOperations(t *testing.T)
projectDir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(projectDir, "compose.yaml"), []byte("services: {}\n"), 0o644))
- content := "hello\n"
updated := "updated\n"
err := ApplyProjectFileChanges(projectDir, []project.ProjectFileChange{
{Operation: "create_folder", RelativePath: "config"},
- {Operation: "create_file", RelativePath: "config/app.yaml", Content: &content},
+ {Operation: "create_file", RelativePath: "config/app.yaml", Content: new("hello\n")},
{Operation: "update_file", RelativePath: "config/app.yaml", Content: &updated},
{Operation: "rename", RelativePath: "config/app.yaml", NewName: "renamed.yaml"},
}, ProjectFileApplyOptions{ComposeFileName: "compose.yaml"})
diff --git a/backend/pkg/utils/cache/cache_util_test.go b/backend/pkg/utils/cache/cache_util_test.go
index 286e72f88..349b1dc3d 100644
--- a/backend/pkg/utils/cache/cache_util_test.go
+++ b/backend/pkg/utils/cache/cache_util_test.go
@@ -9,8 +9,7 @@ func TestKeyedCacheGetSet(t *testing.T) {
t.Fatal("expected miss for unset key")
}
- v := 42
- c.Set("hit", &v)
+ c.Set("hit", new(42))
got, ok := c.Get("hit")
if !ok || got == nil || *got != 42 {
t.Fatalf("expected cached value 42, got %v (ok=%v)", got, ok)