Browse code

api/server: format code with gofumpt

Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2022/01/20 21:47:00
Showing 10 changed files
... ...
@@ -76,7 +76,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
76 76
 		return "", nil
77 77
 	}
78 78
 
79
-	var imageID = build.ImageID
79
+	imageID := build.ImageID
80 80
 	if options.Squash {
81 81
 		if imageID, err = squashBuild(build, b.imageComponent); err != nil {
82 82
 			return "", err
... ...
@@ -15,7 +15,6 @@ type Backend interface {
15 15
 
16 16
 	// Prune build cache
17 17
 	PruneCache(context.Context, types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
18
-
19 18
 	Cancel(context.Context, string) error
20 19
 }
21 20
 
... ...
@@ -107,7 +107,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
107 107
 	}
108 108
 
109 109
 	if ulimitsJSON := r.FormValue("ulimits"); ulimitsJSON != "" {
110
-		var buildUlimits = []*units.Ulimit{}
110
+		buildUlimits := []*units.Ulimit{}
111 111
 		if err := json.Unmarshal([]byte(ulimitsJSON), &buildUlimits); err != nil {
112 112
 			return nil, invalidParam{errors.Wrap(err, "error reading ulimit settings")}
113 113
 		}
... ...
@@ -127,7 +127,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
127 127
 	// so that it can print a warning about "foo" being unused if there is
128 128
 	// no "ARG foo" in the Dockerfile.
129 129
 	if buildArgsJSON := r.FormValue("buildargs"); buildArgsJSON != "" {
130
-		var buildArgs = map[string]*string{}
130
+		buildArgs := map[string]*string{}
131 131
 		if err := json.Unmarshal([]byte(buildArgsJSON), &buildArgs); err != nil {
132 132
 			return nil, invalidParam{errors.Wrap(err, "error reading build args")}
133 133
 		}
... ...
@@ -135,7 +135,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
135 135
 	}
136 136
 
137 137
 	if labelsJSON := r.FormValue("labels"); labelsJSON != "" {
138
-		var labels = map[string]string{}
138
+		labels := map[string]string{}
139 139
 		if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil {
140 140
 			return nil, invalidParam{errors.Wrap(err, "error reading labels")}
141 141
 		}
... ...
@@ -143,7 +143,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
143 143
 	}
144 144
 
145 145
 	if cacheFromJSON := r.FormValue("cachefrom"); cacheFromJSON != "" {
146
-		var cacheFrom = []string{}
146
+		cacheFrom := []string{}
147 147
 		if err := json.Unmarshal([]byte(cacheFromJSON), &cacheFrom); err != nil {
148 148
 			return nil, invalidParam{errors.Wrap(err, "error reading cache-from")}
149 149
 		}
... ...
@@ -35,7 +35,6 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
35 35
 	checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
36 36
 		CheckpointDir: r.Form.Get("dir"),
37 37
 	})
38
-
39 38
 	if err != nil {
40 39
 		return err
41 40
 	}
... ...
@@ -52,7 +51,6 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http
52 52
 		CheckpointDir: r.Form.Get("dir"),
53 53
 		CheckpointID:  vars["checkpoint"],
54 54
 	})
55
-
56 55
 	if err != nil {
57 56
 		return err
58 57
 	}
... ...
@@ -53,7 +53,6 @@ type monitorBackend interface {
53 53
 	ContainerLogs(ctx context.Context, name string, config *types.ContainerLogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
54 54
 	ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
55 55
 	ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
56
-
57 56
 	Containers(ctx context.Context, config *types.ContainerListOptions) ([]*types.Container, error)
58 57
 }
59 58
 
... ...
@@ -449,7 +449,7 @@ func (ir *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWrite
449 449
 	// AuthConfig to increase compatibility with the existing API.
450 450
 	authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))
451 451
 
452
-	var headers = http.Header{}
452
+	headers := http.Header{}
453 453
 	for k, v := range r.Header {
454 454
 		k = http.CanonicalHeaderKey(k)
455 455
 		if strings.HasPrefix(k, "X-Meta-") {
... ...
@@ -186,7 +186,8 @@ func (pr *pluginRouter) createPlugin(ctx context.Context, w http.ResponseWriter,
186 186
 	}
187 187
 
188 188
 	options := &types.PluginCreateOptions{
189
-		RepoName: r.FormValue("name")}
189
+		RepoName: r.FormValue("name"),
190
+	}
190 191
 
191 192
 	if err := pr.backend.CreateFromContext(ctx, r.Body, options); err != nil {
192 193
 		return err
... ...
@@ -17,29 +17,23 @@ type Backend interface {
17 17
 	Update(uint64, types.Spec, types.UpdateFlags) error
18 18
 	GetUnlockKey() (string, error)
19 19
 	UnlockSwarm(req types.UnlockRequest) error
20
-
21 20
 	GetServices(basictypes.ServiceListOptions) ([]types.Service, error)
22 21
 	GetService(idOrName string, insertDefaults bool) (types.Service, error)
23 22
 	CreateService(types.ServiceSpec, string, bool) (*basictypes.ServiceCreateResponse, error)
24 23
 	UpdateService(string, uint64, types.ServiceSpec, basictypes.ServiceUpdateOptions, bool) (*basictypes.ServiceUpdateResponse, error)
25 24
 	RemoveService(string) error
26
-
27 25
 	ServiceLogs(context.Context, *backend.LogSelector, *basictypes.ContainerLogsOptions) (<-chan *backend.LogMessage, error)
28
-
29 26
 	GetNodes(basictypes.NodeListOptions) ([]types.Node, error)
30 27
 	GetNode(string) (types.Node, error)
31 28
 	UpdateNode(string, uint64, types.NodeSpec) error
32 29
 	RemoveNode(string, bool) error
33
-
34 30
 	GetTasks(basictypes.TaskListOptions) ([]types.Task, error)
35 31
 	GetTask(string) (types.Task, error)
36
-
37 32
 	GetSecrets(opts basictypes.SecretListOptions) ([]types.Secret, error)
38 33
 	CreateSecret(s types.SecretSpec) (string, error)
39 34
 	RemoveSecret(idOrName string) error
40 35
 	GetSecret(id string) (types.Secret, error)
41 36
 	UpdateSecret(idOrName string, version uint64, spec types.SecretSpec) error
42
-
43 37
 	GetConfigs(opts basictypes.ConfigListOptions) ([]types.Config, error)
44 38
 	CreateConfig(s types.ConfigSpec) (string, error)
45 39
 	RemoveConfig(id string) error
... ...
@@ -9,9 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestAdjustForAPIVersion(t *testing.T) {
12
-	var (
13
-		expectedSysctls = map[string]string{"foo": "bar"}
14
-	)
12
+	expectedSysctls := map[string]string{"foo": "bar"}
15 13
 	// testing the negative -- does this leave everything else alone? -- is
16 14
 	// prohibitively time-consuming to write, because it would need an object
17 15
 	// with literally every field filled in.
... ...
@@ -78,7 +78,6 @@ func TestGetVolumeByNameFoundRegular(t *testing.T) {
78 78
 	v := &volumeRouter{
79 79
 		backend: &fakeVolumeBackend{
80 80
 			volumes: map[string]*volume.Volume{
81
-
82 81
 				"volume1": {
83 82
 					Name: "volume1",
84 83
 				},
... ...
@@ -108,6 +107,7 @@ func TestGetVolumeByNameFoundSwarm(t *testing.T) {
108 108
 	_, err := callGetVolume(v, "volume1")
109 109
 	assert.NilError(t, err)
110 110
 }
111
+
111 112
 func TestListVolumes(t *testing.T) {
112 113
 	v := &volumeRouter{
113 114
 		backend: &fakeVolumeBackend{