Skip to content

Commit e0281dc

Browse files
committed
format code with gofumpt
gofumpt (https://github.com/mvdan/gofumpt) provides a supserset of `gofmt` / `go fmt`, and addresses various formatting issues that linters may be checking for. We can consider enabling the `gofumpt` linter to verify the formatting in CI, although not every developer may have it installed, so for now this runs it once to get formatting in shape. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7f9f86c commit e0281dc

File tree

107 files changed

+404
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+404
-483
lines changed

cmd/digest/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func main() {
6262
if flag.NArg() > 0 {
6363
for _, path := range flag.Args() {
6464
fp, err := os.Open(path)
65-
6665
if err != nil {
6766
log.Printf("%s: %v", path, err)
6867
fail = true

cmd/registry-api-descriptor-template/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// For example, to generate a new API specification, one would execute the
55
// following command from the repo root:
66
//
7-
// $ registry-api-descriptor-template docs/spec/api.md.tmpl > docs/spec/api.md
7+
// $ registry-api-descriptor-template docs/spec/api.md.tmpl > docs/spec/api.md
88
//
99
// The templates are passed in the api/v2.APIDescriptor object. Please see the
1010
// package documentation for fields available on that object. The template
@@ -27,7 +27,6 @@ import (
2727
var spaceRegex = regexp.MustCompile(`\n\s*`)
2828

2929
func main() {
30-
3130
if len(os.Args) != 2 {
3231
log.Fatalln("please specify a template to execute.")
3332
}
@@ -127,5 +126,4 @@ end:
127126
}
128127

129128
return output
130-
131129
}

configuration/configuration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ type Events struct {
589589
IncludeReferences bool `yaml:"includereferences"` // include reference data in manifest events
590590
}
591591

592-
//Ignore configures mediaTypes and actions of the event, that it won't be propagated
592+
// Ignore configures mediaTypes and actions of the event, that it won't be propagated
593593
type Ignore struct {
594594
MediaTypes []string `yaml:"mediatypes"` // target media types to ignore
595595
Actions []string `yaml:"actions"` // ignore action types

configuration/configuration_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ func (suite *ConfigSuite) TestParseInvalidLoglevel(c *C) {
360360

361361
_, err = Parse(bytes.NewReader([]byte(configYamlV0_1)))
362362
c.Assert(err, NotNil)
363-
364363
}
365364

366365
// TestParseWithDifferentEnvReporting validates that environment variables

configuration/fuzz.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build gofuzz
12
// +build gofuzz
23

34
package configuration

context/doc.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,82 @@
44
//
55
// The easiest way to get started is to get the background context:
66
//
7-
// ctx := context.Background()
7+
// ctx := context.Background()
88
//
99
// The returned context should be passed around your application and be the
1010
// root of all other context instances. If the application has a version, this
1111
// line should be called before anything else:
1212
//
13-
// ctx := context.WithVersion(context.Background(), version)
13+
// ctx := context.WithVersion(context.Background(), version)
1414
//
1515
// The above will store the version in the context and will be available to
1616
// the logger.
1717
//
18-
// Logging
18+
// # Logging
1919
//
2020
// The most useful aspect of this package is GetLogger. This function takes
2121
// any context.Context interface and returns the current logger from the
2222
// context. Canonical usage looks like this:
2323
//
24-
// GetLogger(ctx).Infof("something interesting happened")
24+
// GetLogger(ctx).Infof("something interesting happened")
2525
//
2626
// GetLogger also takes optional key arguments. The keys will be looked up in
2727
// the context and reported with the logger. The following example would
2828
// return a logger that prints the version with each log message:
2929
//
30-
// ctx := context.Context(context.Background(), "version", version)
31-
// GetLogger(ctx, "version").Infof("this log message has a version field")
30+
// ctx := context.Context(context.Background(), "version", version)
31+
// GetLogger(ctx, "version").Infof("this log message has a version field")
3232
//
3333
// The above would print out a log message like this:
3434
//
35-
// INFO[0000] this log message has a version field version=v2.0.0-alpha.2.m
35+
// INFO[0000] this log message has a version field version=v2.0.0-alpha.2.m
3636
//
3737
// When used with WithLogger, we gain the ability to decorate the context with
3838
// loggers that have information from disparate parts of the call stack.
3939
// Following from the version example, we can build a new context with the
4040
// configured logger such that we always print the version field:
4141
//
42-
// ctx = WithLogger(ctx, GetLogger(ctx, "version"))
42+
// ctx = WithLogger(ctx, GetLogger(ctx, "version"))
4343
//
4444
// Since the logger has been pushed to the context, we can now get the version
4545
// field for free with our log messages. Future calls to GetLogger on the new
4646
// context will have the version field:
4747
//
48-
// GetLogger(ctx).Infof("this log message has a version field")
48+
// GetLogger(ctx).Infof("this log message has a version field")
4949
//
5050
// This becomes more powerful when we start stacking loggers. Let's say we
5151
// have the version logger from above but also want a request id. Using the
5252
// context above, in our request scoped function, we place another logger in
5353
// the context:
5454
//
55-
// ctx = context.WithValue(ctx, "http.request.id", "unique id") // called when building request context
56-
// ctx = WithLogger(ctx, GetLogger(ctx, "http.request.id"))
55+
// ctx = context.WithValue(ctx, "http.request.id", "unique id") // called when building request context
56+
// ctx = WithLogger(ctx, GetLogger(ctx, "http.request.id"))
5757
//
5858
// When GetLogger is called on the new context, "http.request.id" will be
5959
// included as a logger field, along with the original "version" field:
6060
//
61-
// INFO[0000] this log message has a version field http.request.id=unique id version=v2.0.0-alpha.2.m
61+
// INFO[0000] this log message has a version field http.request.id=unique id version=v2.0.0-alpha.2.m
6262
//
6363
// Note that this only affects the new context, the previous context, with the
6464
// version field, can be used independently. Put another way, the new logger,
6565
// added to the request context, is unique to that context and can have
6666
// request scoped variables.
6767
//
68-
// HTTP Requests
68+
// # HTTP Requests
6969
//
7070
// This package also contains several methods for working with http requests.
7171
// The concepts are very similar to those described above. We simply place the
7272
// request in the context using WithRequest. This makes the request variables
7373
// available. GetRequestLogger can then be called to get request specific
7474
// variables in a log line:
7575
//
76-
// ctx = WithRequest(ctx, req)
77-
// GetRequestLogger(ctx).Infof("request variables")
76+
// ctx = WithRequest(ctx, req)
77+
// GetRequestLogger(ctx).Infof("request variables")
7878
//
7979
// Like above, if we want to include the request data in all log messages in
8080
// the context, we push the logger to a new context and use that one:
8181
//
82-
// ctx = WithLogger(ctx, GetRequestLogger(ctx))
82+
// ctx = WithLogger(ctx, GetRequestLogger(ctx))
8383
//
8484
// The concept is fairly powerful and ensures that calls throughout the stack
8585
// can be traced in log messages. Using the fields like "http.request.id", one

context/trace.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ import (
2424
//
2525
// Here is an example of the usage:
2626
//
27-
// func timedOperation(ctx Context) {
28-
// ctx, done := WithTrace(ctx)
29-
// defer done("this will be the log message")
30-
// // ... function body ...
31-
// }
27+
// func timedOperation(ctx Context) {
28+
// ctx, done := WithTrace(ctx)
29+
// defer done("this will be the log message")
30+
// // ... function body ...
31+
// }
3232
//
3333
// If the function ran for roughly 1s, such a usage would emit a log message
3434
// as follows:
3535
//
36-
// INFO[0001] this will be the log message trace.duration=1.004575763s trace.func=github.com/distribution/distribution/context.traceOperation trace.id=<id> ...
36+
// INFO[0001] this will be the log message trace.duration=1.004575763s trace.func=github.com/distribution/distribution/context.traceOperation trace.id=<id> ...
3737
//
3838
// Notice that the function name is automatically resolved, along with the
3939
// package and a trace id is emitted that can be linked with parent ids.

contrib/token-server/main.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import (
2020
"github.com/sirupsen/logrus"
2121
)
2222

23-
var (
24-
enforceRepoClass bool
25-
)
23+
var enforceRepoClass bool
2624

2725
func main() {
2826
var (
@@ -110,7 +108,6 @@ func main() {
110108
if err != nil {
111109
logrus.Infof("Error serving: %v", err)
112110
}
113-
114111
}
115112

116113
// handlerWithContext wraps the given context-aware handler by setting up the

contrib/token-server/token_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"crypto/rsa"
66
"encoding/base64"
77
"errors"
8+
"strings"
89
"testing"
910
"time"
1011

11-
"strings"
12-
1312
"github.com/distribution/distribution/v3/registry/auth"
1413
"github.com/docker/libtrust"
1514
)
@@ -49,7 +48,6 @@ func TestCreateJWTSuccessWithEmptyACL(t *testing.T) {
4948
if !strings.Contains(json, "test") {
5049
t.Fatal("Valid token was not generated.")
5150
}
52-
5351
}
5452

5553
func decodeJWT(rawToken string) (string, error) {
@@ -74,7 +72,7 @@ func joseBase64Decode(s string) (string, error) {
7472
}
7573
data, err := base64.StdEncoding.DecodeString(s)
7674
if err != nil {
77-
return "", err //errors.New("Error in Decoding base64 String")
75+
return "", err // errors.New("Error in Decoding base64 String")
7876
}
7977
return string(data), nil
8078
}

digestset/set_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func TestAll(t *testing.T) {
187187
t.Fatalf("Missing element at position %d: %s", i, dgst)
188188
}
189189
}
190-
191190
}
192191

193192
func assertEqualShort(t *testing.T, actual, expected string) {
@@ -363,9 +362,11 @@ func BenchmarkLookup1000(b *testing.B) {
363362
func BenchmarkShortCode10(b *testing.B) {
364363
benchShortCodeNTable(b, 10, 12)
365364
}
365+
366366
func BenchmarkShortCode100(b *testing.B) {
367367
benchShortCodeNTable(b, 100, 12)
368368
}
369+
369370
func BenchmarkShortCode1000(b *testing.B) {
370371
benchShortCodeNTable(b, 1000, 12)
371372
}

health/api/api.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77
"github.com/distribution/distribution/v3/health"
88
)
99

10-
var (
11-
updater = health.NewStatusUpdater()
12-
)
10+
var updater = health.NewStatusUpdater()
1311

1412
// DownHandler registers a manual_http_status that always returns an Error
1513
func DownHandler(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)