Skip to content

Commit ee349f9

Browse files
authored
CI: Lint against 1.19 (#1141)
We prefer to lint against the latest release. In Go 1.19, gofmt reformats godoc to match the [new format]. This change includes all the formatting changes that resulted from this. [new format]: https://go.dev/doc/comment
1 parent 7ee98d2 commit ee349f9

File tree

15 files changed

+141
-128
lines changed

15 files changed

+141
-128
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
go: ["1.17.x", "1.18.x", "1.19.x"]
1717
include:
18-
- go: 1.18.x
18+
- go: 1.19.x
1919
latest: true
2020

2121
steps:

array_go118.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ import "go.uber.org/zap/zapcore"
3636
// Given an object that implements MarshalLogObject on the value receiver, you
3737
// can log a slice of those objects with Objects like so:
3838
//
39-
// type Author struct{ ... }
40-
// func (a Author) MarshalLogObject(enc zapcore.ObjectEncoder) error
39+
// type Author struct{ ... }
40+
// func (a Author) MarshalLogObject(enc zapcore.ObjectEncoder) error
4141
//
42-
// var authors []Author = ...
43-
// logger.Info("loading article", zap.Objects("authors", authors))
42+
// var authors []Author = ...
43+
// logger.Info("loading article", zap.Objects("authors", authors))
4444
//
4545
// Similarly, given a type that implements MarshalLogObject on its pointer
4646
// receiver, you can log a slice of pointers to that object with Objects like
4747
// so:
4848
//
49-
// type Request struct{ ... }
50-
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
49+
// type Request struct{ ... }
50+
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
5151
//
52-
// var requests []*Request = ...
53-
// logger.Info("sending requests", zap.Objects("requests", requests))
52+
// var requests []*Request = ...
53+
// logger.Info("sending requests", zap.Objects("requests", requests))
5454
//
5555
// If instead, you have a slice of values of such an object, use the
5656
// ObjectValues constructor.
5757
//
58-
// var requests []Request = ...
59-
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
58+
// var requests []Request = ...
59+
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
6060
func Objects[T zapcore.ObjectMarshaler](key string, values []T) Field {
6161
return Array(key, objects[T](values))
6262
}
@@ -90,17 +90,17 @@ type objectMarshalerPtr[T any] interface {
9090
// Given an object that implements MarshalLogObject on the pointer receiver,
9191
// you can log a slice of those objects with ObjectValues like so:
9292
//
93-
// type Request struct{ ... }
94-
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
93+
// type Request struct{ ... }
94+
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
9595
//
96-
// var requests []Request = ...
97-
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
96+
// var requests []Request = ...
97+
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
9898
//
9999
// If instead, you have a slice of pointers of such an object, use the Objects
100100
// field constructor.
101101
//
102-
// var requests []*Request = ...
103-
// logger.Info("sending requests", zap.Objects("requests", requests))
102+
// var requests []*Request = ...
103+
// logger.Info("sending requests", zap.Objects("requests", requests))
104104
func ObjectValues[T any, P objectMarshalerPtr[T]](key string, values []T) Field {
105105
return Array(key, objectValues[T, P](values))
106106
}

doc.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// they need to count every allocation and when they'd prefer a more familiar,
3333
// loosely typed API.
3434
//
35-
// Choosing a Logger
35+
// # Choosing a Logger
3636
//
3737
// In contexts where performance is nice, but not critical, use the
3838
// SugaredLogger. It's 4-10x faster than other structured logging packages and
@@ -41,14 +41,15 @@
4141
// variadic number of key-value pairs. (For more advanced use cases, they also
4242
// accept strongly typed fields - see the SugaredLogger.With documentation for
4343
// details.)
44-
// sugar := zap.NewExample().Sugar()
45-
// defer sugar.Sync()
46-
// sugar.Infow("failed to fetch URL",
47-
// "url", "http://example.com",
48-
// "attempt", 3,
49-
// "backoff", time.Second,
50-
// )
51-
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
44+
//
45+
// sugar := zap.NewExample().Sugar()
46+
// defer sugar.Sync()
47+
// sugar.Infow("failed to fetch URL",
48+
// "url", "http://example.com",
49+
// "attempt", 3,
50+
// "backoff", time.Second,
51+
// )
52+
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
5253
//
5354
// By default, loggers are unbuffered. However, since zap's low-level APIs
5455
// allow buffering, calling Sync before letting your process exit is a good
@@ -57,32 +58,35 @@
5758
// In the rare contexts where every microsecond and every allocation matter,
5859
// use the Logger. It's even faster than the SugaredLogger and allocates far
5960
// less, but it only supports strongly-typed, structured logging.
60-
// logger := zap.NewExample()
61-
// defer logger.Sync()
62-
// logger.Info("failed to fetch URL",
63-
// zap.String("url", "http://example.com"),
64-
// zap.Int("attempt", 3),
65-
// zap.Duration("backoff", time.Second),
66-
// )
61+
//
62+
// logger := zap.NewExample()
63+
// defer logger.Sync()
64+
// logger.Info("failed to fetch URL",
65+
// zap.String("url", "http://example.com"),
66+
// zap.Int("attempt", 3),
67+
// zap.Duration("backoff", time.Second),
68+
// )
6769
//
6870
// Choosing between the Logger and SugaredLogger doesn't need to be an
6971
// application-wide decision: converting between the two is simple and
7072
// inexpensive.
71-
// logger := zap.NewExample()
72-
// defer logger.Sync()
73-
// sugar := logger.Sugar()
74-
// plain := sugar.Desugar()
7573
//
76-
// Configuring Zap
74+
// logger := zap.NewExample()
75+
// defer logger.Sync()
76+
// sugar := logger.Sugar()
77+
// plain := sugar.Desugar()
78+
//
79+
// # Configuring Zap
7780
//
7881
// The simplest way to build a Logger is to use zap's opinionated presets:
7982
// NewExample, NewProduction, and NewDevelopment. These presets build a logger
8083
// with a single function call:
81-
// logger, err := zap.NewProduction()
82-
// if err != nil {
83-
// log.Fatalf("can't initialize zap logger: %v", err)
84-
// }
85-
// defer logger.Sync()
84+
//
85+
// logger, err := zap.NewProduction()
86+
// if err != nil {
87+
// log.Fatalf("can't initialize zap logger: %v", err)
88+
// }
89+
// defer logger.Sync()
8690
//
8791
// Presets are fine for small projects, but larger projects and organizations
8892
// naturally require a bit more customization. For most users, zap's Config
@@ -94,7 +98,7 @@
9498
// go.uber.org/zap/zapcore. See the package-level AdvancedConfiguration
9599
// example for sample code.
96100
//
97-
// Extending Zap
101+
// # Extending Zap
98102
//
99103
// The zap package itself is a relatively thin wrapper around the interfaces
100104
// in go.uber.org/zap/zapcore. Extending zap to support a new encoding (e.g.,
@@ -106,7 +110,7 @@
106110
// Similarly, package authors can use the high-performance Encoder and Core
107111
// implementations in the zapcore package to build their own loggers.
108112
//
109-
// Frequently Asked Questions
113+
// # Frequently Asked Questions
110114
//
111115
// An FAQ covering everything from installation errors to design decisions is
112116
// available at https://github.com/uber-go/zap/blob/master/FAQ.md.

http_handler.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,41 @@ import (
3333
// ServeHTTP is a simple JSON endpoint that can report on or change the current
3434
// logging level.
3535
//
36-
// GET
36+
// # GET
3737
//
3838
// The GET request returns a JSON description of the current logging level like:
39-
// {"level":"info"}
4039
//
41-
// PUT
40+
// {"level":"info"}
41+
//
42+
// # PUT
4243
//
4344
// The PUT request changes the logging level. It is perfectly safe to change the
4445
// logging level while a program is running. Two content types are supported:
4546
//
46-
// Content-Type: application/x-www-form-urlencoded
47+
// Content-Type: application/x-www-form-urlencoded
4748
//
4849
// With this content type, the level can be provided through the request body or
4950
// a query parameter. The log level is URL encoded like:
5051
//
51-
// level=debug
52+
// level=debug
5253
//
5354
// The request body takes precedence over the query parameter, if both are
5455
// specified.
5556
//
5657
// This content type is the default for a curl PUT request. Following are two
5758
// example curl requests that both set the logging level to debug.
5859
//
59-
// curl -X PUT localhost:8080/log/level?level=debug
60-
// curl -X PUT localhost:8080/log/level -d level=debug
60+
// curl -X PUT localhost:8080/log/level?level=debug
61+
// curl -X PUT localhost:8080/log/level -d level=debug
6162
//
6263
// For any other content type, the payload is expected to be JSON encoded and
6364
// look like:
6465
//
65-
// {"level":"info"}
66+
// {"level":"info"}
6667
//
6768
// An example curl request could look like this:
6869
//
69-
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
70-
//
70+
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
7171
func (lvl AtomicLevel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7272
type errorResponse struct {
7373
Error string `json:"error"`

logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func NewDevelopment(options ...Option) (*Logger, error) {
111111
// and panics if the error is non-nil. It is intended for use in variable
112112
// initialization such as:
113113
//
114-
// var logger = zap.Must(zap.NewProduction())
114+
// var logger = zap.Must(zap.NewProduction())
115115
func Must(logger *Logger, err error) *Logger {
116116
if err != nil {
117117
panic(err)

options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func OnFatal(action zapcore.CheckWriteAction) Option {
145145
// goroutine after writing a fatal log message, but it will not exit the
146146
// program.
147147
//
148-
// zap.New(core, zap.WithFatalHook(zapcore.WriteThenGoexit))
148+
// zap.New(core, zap.WithFatalHook(zapcore.WriteThenGoexit))
149149
//
150150
// It is important that the provided CheckWriteHook stops the control flow at
151151
// the current statement to meet expectations of callers of the logger.

sugar.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ const (
4040
// Unlike the Logger, the SugaredLogger doesn't insist on structured logging.
4141
// For each log level, it exposes four methods:
4242
//
43-
// - methods named after the log level for log.Print-style logging
44-
// - methods ending in "w" for loosely-typed structured logging
45-
// - methods ending in "f" for log.Printf-style logging
46-
// - methods ending in "ln" for log.Println-style logging
43+
// - methods named after the log level for log.Print-style logging
44+
// - methods ending in "w" for loosely-typed structured logging
45+
// - methods ending in "f" for log.Printf-style logging
46+
// - methods ending in "ln" for log.Println-style logging
4747
//
4848
// For example, the methods for InfoLevel are:
4949
//
50-
// Info(...any) Print-style logging
51-
// Infow(...any) Structured logging (read as "info with")
52-
// Infof(string, ...any) Printf-style logging
53-
// Infoln(...any) Println-style logging
50+
// Info(...any) Print-style logging
51+
// Infow(...any) Structured logging (read as "info with")
52+
// Infof(string, ...any) Printf-style logging
53+
// Infoln(...any) Println-style logging
5454
type SugaredLogger struct {
5555
base *Logger
5656
}
@@ -86,21 +86,24 @@ func (s *SugaredLogger) WithOptions(opts ...Option) *SugaredLogger {
8686
// and the second as the field value.
8787
//
8888
// For example,
89-
// sugaredLogger.With(
90-
// "hello", "world",
91-
// "failure", errors.New("oh no"),
92-
// Stack(),
93-
// "count", 42,
94-
// "user", User{Name: "alice"},
95-
// )
89+
//
90+
// sugaredLogger.With(
91+
// "hello", "world",
92+
// "failure", errors.New("oh no"),
93+
// Stack(),
94+
// "count", 42,
95+
// "user", User{Name: "alice"},
96+
// )
97+
//
9698
// is the equivalent of
97-
// unsugared.With(
98-
// String("hello", "world"),
99-
// String("failure", "oh no"),
100-
// Stack(),
101-
// Int("count", 42),
102-
// Object("user", User{Name: "alice"}),
103-
// )
99+
//
100+
// unsugared.With(
101+
// String("hello", "world"),
102+
// String("failure", "oh no"),
103+
// Stack(),
104+
// Int("count", 42),
105+
// Object("user", User{Name: "alice"}),
106+
// )
104107
//
105108
// Note that the keys in key-value pairs should be strings. In development,
106109
// passing a non-string key panics. In production, the logger is more
@@ -187,7 +190,8 @@ func (s *SugaredLogger) Fatalf(template string, args ...interface{}) {
187190
// pairs are treated as they are in With.
188191
//
189192
// When debug-level logging is disabled, this is much faster than
190-
// s.With(keysAndValues).Debug(msg)
193+
//
194+
// s.With(keysAndValues).Debug(msg)
191195
func (s *SugaredLogger) Debugw(msg string, keysAndValues ...interface{}) {
192196
s.log(DebugLevel, msg, nil, keysAndValues)
193197
}

zapcore/buffered_write_syncer.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ const (
4949
// BufferedWriteSyncer, and defer a Stop() call for when you no longer need the
5050
// object.
5151
//
52-
// func main() {
53-
// ws := ... // your log destination
54-
// bws := &zapcore.BufferedWriteSyncer{WS: ws}
55-
// defer bws.Stop()
52+
// func main() {
53+
// ws := ... // your log destination
54+
// bws := &zapcore.BufferedWriteSyncer{WS: ws}
55+
// defer bws.Stop()
5656
//
57-
// // ...
58-
// core := zapcore.NewCore(enc, bws, lvl)
59-
// logger := zap.New(core)
57+
// // ...
58+
// core := zapcore.NewCore(enc, bws, lvl)
59+
// logger := zap.New(core)
6060
//
61-
// // ...
62-
// }
61+
// // ...
62+
// }
6363
//
6464
// By default, a BufferedWriteSyncer will buffer up to 256 kilobytes of logs,
6565
// waiting at most 30 seconds between flushes.
@@ -68,12 +68,12 @@ const (
6868
// For example, the following buffers up to 512 kB of logs before flushing them
6969
// to Stderr, with a maximum of one minute between each flush.
7070
//
71-
// ws := &BufferedWriteSyncer{
72-
// WS: os.Stderr,
73-
// Size: 512 * 1024, // 512 kB
74-
// FlushInterval: time.Minute,
75-
// }
76-
// defer ws.Stop()
71+
// ws := &BufferedWriteSyncer{
72+
// WS: os.Stderr,
73+
// Size: 512 * 1024, // 512 kB
74+
// FlushInterval: time.Minute,
75+
// }
76+
// defer ws.Stop()
7777
type BufferedWriteSyncer struct {
7878
// WS is the WriteSyncer around which BufferedWriteSyncer will buffer
7979
// writes.

zapcore/encoder.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,13 @@ func (e *TimeEncoder) UnmarshalText(text []byte) error {
188188

189189
// UnmarshalYAML unmarshals YAML to a TimeEncoder.
190190
// If value is an object with a "layout" field, it will be unmarshaled to TimeEncoder with given layout.
191-
// timeEncoder:
192-
// layout: 06/01/02 03:04pm
191+
//
192+
// timeEncoder:
193+
// layout: 06/01/02 03:04pm
194+
//
193195
// If value is string, it uses UnmarshalText.
194-
// timeEncoder: iso8601
196+
//
197+
// timeEncoder: iso8601
195198
func (e *TimeEncoder) UnmarshalYAML(unmarshal func(interface{}) error) error {
196199
var o struct {
197200
Layout string `json:"layout" yaml:"layout"`

zapcore/entry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ type Entry struct {
156156
//
157157
// Register one on a CheckedEntry with the After method.
158158
//
159-
// if ce := logger.Check(...); ce != nil {
160-
// ce = ce.After(hook)
161-
// ce.Write(...)
162-
// }
159+
// if ce := logger.Check(...); ce != nil {
160+
// ce = ce.After(hook)
161+
// ce.Write(...)
162+
// }
163163
//
164164
// You can configure the hook for Fatal log statements at the logger level with
165165
// the zap.WithFatalHook option.

0 commit comments

Comments
 (0)