Skip to content

Commit

Permalink
Merge pull request moby#43169 from thaJeztah/use_gofumpt
Browse files Browse the repository at this point in the history
Format code with gofumpt
  • Loading branch information
neersighted committed Jun 29, 2023
2 parents fc7a3be + a764cd5 commit 46cf8ce
Show file tree
Hide file tree
Showing 350 changed files with 1,473 additions and 1,363 deletions.
2 changes: 1 addition & 1 deletion api/server/backend/build/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string
return "", nil
}

var imageID = build.ImageID
imageID := build.ImageID
if options.Squash {
if imageID, err = squashBuild(build, b.imageComponent); err != nil {
return "", err
Expand Down
1 change: 0 additions & 1 deletion api/server/router/build/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Backend interface {

// Prune build cache
PruneCache(context.Context, types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)

Cancel(context.Context, string) error
}

Expand Down
8 changes: 4 additions & 4 deletions api/server/router/build/build_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
}

if ulimitsJSON := r.FormValue("ulimits"); ulimitsJSON != "" {
var buildUlimits = []*units.Ulimit{}
buildUlimits := []*units.Ulimit{}
if err := json.Unmarshal([]byte(ulimitsJSON), &buildUlimits); err != nil {
return nil, invalidParam{errors.Wrap(err, "error reading ulimit settings")}
}
Expand All @@ -127,23 +127,23 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
// so that it can print a warning about "foo" being unused if there is
// no "ARG foo" in the Dockerfile.
if buildArgsJSON := r.FormValue("buildargs"); buildArgsJSON != "" {
var buildArgs = map[string]*string{}
buildArgs := map[string]*string{}
if err := json.Unmarshal([]byte(buildArgsJSON), &buildArgs); err != nil {
return nil, invalidParam{errors.Wrap(err, "error reading build args")}
}
options.BuildArgs = buildArgs
}

if labelsJSON := r.FormValue("labels"); labelsJSON != "" {
var labels = map[string]string{}
labels := map[string]string{}
if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil {
return nil, invalidParam{errors.Wrap(err, "error reading labels")}
}
options.Labels = labels
}

if cacheFromJSON := r.FormValue("cachefrom"); cacheFromJSON != "" {
var cacheFrom = []string{}
cacheFrom := []string{}
if err := json.Unmarshal([]byte(cacheFromJSON), &cacheFrom); err != nil {
return nil, invalidParam{errors.Wrap(err, "error reading cache-from")}
}
Expand Down
2 changes: 0 additions & 2 deletions api/server/router/checkpoint/checkpoint_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
CheckpointDir: r.Form.Get("dir"),
})

if err != nil {
return err
}
Expand All @@ -52,7 +51,6 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http
CheckpointDir: r.Form.Get("dir"),
CheckpointID: vars["checkpoint"],
})

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion api/server/router/container/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type monitorBackend interface {
ContainerLogs(ctx context.Context, name string, config *types.ContainerLogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)

Containers(ctx context.Context, config *types.ContainerListOptions) ([]*types.Container, error)
}

Expand Down
2 changes: 1 addition & 1 deletion api/server/router/image/image_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (ir *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWrite
// AuthConfig to increase compatibility with the existing API.
authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))

var headers = http.Header{}
headers := http.Header{}
for k, v := range r.Header {
k = http.CanonicalHeaderKey(k)
if strings.HasPrefix(k, "X-Meta-") {
Expand Down
3 changes: 2 additions & 1 deletion api/server/router/plugin/plugin_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func (pr *pluginRouter) createPlugin(ctx context.Context, w http.ResponseWriter,
}

options := &types.PluginCreateOptions{
RepoName: r.FormValue("name")}
RepoName: r.FormValue("name"),
}

if err := pr.backend.CreateFromContext(ctx, r.Body, options); err != nil {
return err
Expand Down
6 changes: 0 additions & 6 deletions api/server/router/swarm/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,23 @@ type Backend interface {
Update(uint64, types.Spec, types.UpdateFlags) error
GetUnlockKey() (string, error)
UnlockSwarm(req types.UnlockRequest) error

GetServices(basictypes.ServiceListOptions) ([]types.Service, error)
GetService(idOrName string, insertDefaults bool) (types.Service, error)
CreateService(types.ServiceSpec, string, bool) (*basictypes.ServiceCreateResponse, error)
UpdateService(string, uint64, types.ServiceSpec, basictypes.ServiceUpdateOptions, bool) (*basictypes.ServiceUpdateResponse, error)
RemoveService(string) error

ServiceLogs(context.Context, *backend.LogSelector, *basictypes.ContainerLogsOptions) (<-chan *backend.LogMessage, error)

GetNodes(basictypes.NodeListOptions) ([]types.Node, error)
GetNode(string) (types.Node, error)
UpdateNode(string, uint64, types.NodeSpec) error
RemoveNode(string, bool) error

GetTasks(basictypes.TaskListOptions) ([]types.Task, error)
GetTask(string) (types.Task, error)

GetSecrets(opts basictypes.SecretListOptions) ([]types.Secret, error)
CreateSecret(s types.SecretSpec) (string, error)
RemoveSecret(idOrName string) error
GetSecret(id string) (types.Secret, error)
UpdateSecret(idOrName string, version uint64, spec types.SecretSpec) error

GetConfigs(opts basictypes.ConfigListOptions) ([]types.Config, error)
CreateConfig(s types.ConfigSpec) (string, error)
RemoveConfig(id string) error
Expand Down
4 changes: 1 addition & 3 deletions api/server/router/swarm/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
)

func TestAdjustForAPIVersion(t *testing.T) {
var (
expectedSysctls = map[string]string{"foo": "bar"}
)
expectedSysctls := map[string]string{"foo": "bar"}
// testing the negative -- does this leave everything else alone? -- is
// prohibitively time-consuming to write, because it would need an object
// with literally every field filled in.
Expand Down
2 changes: 1 addition & 1 deletion api/server/router/volume/volume_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestGetVolumeByNameFoundRegular(t *testing.T) {
v := &volumeRouter{
backend: &fakeVolumeBackend{
volumes: map[string]*volume.Volume{

"volume1": {
Name: "volume1",
},
Expand Down Expand Up @@ -108,6 +107,7 @@ func TestGetVolumeByNameFoundSwarm(t *testing.T) {
_, err := callGetVolume(v, "volume1")
assert.NilError(t, err)
}

func TestListVolumes(t *testing.T) {
v := &volumeRouter{
backend: &fakeVolumeBackend{
Expand Down
1 change: 0 additions & 1 deletion api/types/container/hostconfig_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func TestUTSMode(t *testing.T) {
assert.Check(t, is.Equal(mode.IsHost(), expected.host))
assert.Check(t, is.Equal(mode.Valid(), expected.valid))
})

}
}

Expand Down
101 changes: 65 additions & 36 deletions api/types/filters/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ func TestArgsMatchKVList(t *testing.T) {

matches := map[*Args]string{
{}: "field",
{map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1": true}},
{
map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1": true},
},
}: "labels",
{map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1=value1": true}},
{
map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1=value1": true},
},
}: "labels",
}

Expand All @@ -181,16 +185,22 @@ func TestArgsMatchKVList(t *testing.T) {
}

differs := map[*Args]string{
{map[string]map[string]bool{
"created": {"today": true}},
{
map[string]map[string]bool{
"created": {"today": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"today": true},
"labels": {"key4": true}},
{
map[string]map[string]bool{
"created": {"today": true},
"labels": {"key4": true},
},
}: "labels",
{map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1=value3": true}},
{
map[string]map[string]bool{
"created": {"today": true},
"labels": {"key1=value3": true},
},
}: "labels",
}

Expand All @@ -206,20 +216,30 @@ func TestArgsMatch(t *testing.T) {

matches := map[*Args]string{
{}: "field",
{map[string]map[string]bool{
"created": {"today": true}},
{
map[string]map[string]bool{
"created": {"today": true},
},
}: "today",
{map[string]map[string]bool{
"created": {"to*": true}},
{
map[string]map[string]bool{
"created": {"to*": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"to(.*)": true}},
{
map[string]map[string]bool{
"created": {"to(.*)": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"tod": true}},
{
map[string]map[string]bool{
"created": {"tod": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"anything": true, "to*": true}},
{
map[string]map[string]bool{
"created": {"anything": true, "to*": true},
},
}: "created",
}

Expand All @@ -229,21 +249,31 @@ func TestArgsMatch(t *testing.T) {
}

differs := map[*Args]string{
{map[string]map[string]bool{
"created": {"tomorrow": true}},
{
map[string]map[string]bool{
"created": {"tomorrow": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"to(day": true}},
{
map[string]map[string]bool{
"created": {"to(day": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"tom(.*)": true}},
{
map[string]map[string]bool{
"created": {"tom(.*)": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"tom": true}},
{
map[string]map[string]bool{
"created": {"tom": true},
},
}: "created",
{map[string]map[string]bool{
"created": {"today1": true},
"labels": {"today": true}},
{
map[string]map[string]bool{
"created": {"today1": true},
"labels": {"today": true},
},
}: "created",
}

Expand Down Expand Up @@ -532,5 +562,4 @@ func TestGetBoolOrDefault(t *testing.T) {
assert.Check(t, is.Equal(tC.expectedValue, value))
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func parseCreatedLayerInfo(img image) ([]string, []string, error) {
return dates, createdBy, nil
}

type emptyProvider struct {
}
type emptyProvider struct{}

func (p *emptyProvider) ReaderAt(ctx context.Context, dec ocispec.Descriptor) (content.ReaderAt, error) {
return nil, errors.Errorf("ReaderAt not implemented for empty provider")
Expand Down
14 changes: 8 additions & 6 deletions builder/builder-next/adapters/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
bolt "go.etcd.io/bbolt"
)

var keyParent = []byte("parent")
var keyCommitted = []byte("committed")
var keyIsCommitted = []byte("iscommitted")
var keyChainID = []byte("chainid")
var keySize = []byte("size")
var (
keyParent = []byte("parent")
keyCommitted = []byte("committed")
keyIsCommitted = []byte("iscommitted")
keyChainID = []byte("chainid")
keySize = []byte("size")
)

// Opt defines options for creating the snapshotter
type Opt struct {
Expand Down Expand Up @@ -57,7 +59,7 @@ type snapshotter struct {
// NewSnapshotter creates a new snapshotter
func NewSnapshotter(opt Opt, prevLM leases.Manager) (snapshot.Snapshotter, leases.Manager, error) {
dbPath := filepath.Join(opt.Root, "snapshots.db")
db, err := bolt.Open(dbPath, 0600, nil)
db, err := bolt.Open(dbPath, 0o600, nil)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to open database file %s", dbPath)
}
Expand Down
5 changes: 4 additions & 1 deletion builder/builder-next/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
return nil, errors.Errorf("multiple outputs not supported")
}

var rc = opt.Source
rc := opt.Source
if buildID := opt.Options.BuildID; buildID != "" {
b.mu.Lock()

Expand Down Expand Up @@ -466,6 +466,7 @@ func (sp *streamProxy) SetTrailer(_ grpcmetadata.MD) {
func (sp *streamProxy) Context() context.Context {
return sp.ctx
}

func (sp *streamProxy) RecvMsg(m interface{}) error {
return io.EOF
}
Expand All @@ -478,6 +479,7 @@ type statusProxy struct {
func (sp *statusProxy) Send(resp *controlapi.StatusResponse) error {
return sp.SendMsg(resp)
}

func (sp *statusProxy) SendMsg(m interface{}) error {
if sr, ok := m.(*controlapi.StatusResponse); ok {
sp.ch <- sr
Expand All @@ -493,6 +495,7 @@ type pruneProxy struct {
func (sp *pruneProxy) Send(resp *controlapi.UsageRecord) error {
return sp.SendMsg(resp)
}

func (sp *pruneProxy) SendMsg(m interface{}) error {
if sr, ok := m.(*controlapi.UsageRecord); ok {
sp.ch <- sr
Expand Down
2 changes: 1 addition & 1 deletion builder/builder-next/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt
return nil, err
}

db, err := bolt.Open(filepath.Join(root, "containerdmeta.db"), 0644, nil)
db, err := bolt.Open(filepath.Join(root, "containerdmeta.db"), 0o644, nil)
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
3 changes: 1 addition & 2 deletions builder/builder-next/executor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool
return &winExecutor{}, nil
}

type winExecutor struct {
}
type winExecutor struct{}

func (w *winExecutor) Run(ctx context.Context, id string, root executor.Mount, mounts []executor.Mount, process executor.ProcessInfo, started chan<- struct{}) (err error) {
return errors.New("buildkit executor not implemented for windows")
Expand Down
Loading

0 comments on commit 46cf8ce

Please sign in to comment.