fix: address golangci-lint warnings#158
Conversation
8523016 to
ba94778
Compare
I think this reduces clarity when there are multiple embedded structs.
dbd2027 to
57a65cf
Compare
Replace tools.go with go mod tool directives. go get -tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint go get -tool github.com/elastic/go-licenser go mod tidy
Rename GcsOptions to GCSOptions.
Fixed an issue in TCP and TLS outputs where the write buffer was being modified, which is unsafe. A new buffer is now used.
Resolved a potential context leak in the GCS output by ensuring the cancel function is always called.
57a65cf to
42c0f59
Compare
💚 Build Succeeded
History
|
| // KafkaOptions holds configuration for the Kafka output. | ||
| type KafkaOptions struct { | ||
| Topic string // Topic name. Will create it if not exists. | ||
| Topic string // Topic is the Kafka topic name. It will be created if it does not exist. |
There was a problem hiding this comment.
"Topic is the Kafka topic name. The topic will be created if it does not exist."
("It" is Topic string on first reading)
Similar below.
| // Initialize creates and configures a new Output using the provided Options and | ||
| // logger, then attempts to establish a connection with retries. It returns the | ||
| // connected Output or an error if the connection could not be established within | ||
| // the allowed retries or if the provided context is canceled. The logger is used | ||
| // for informational and debug messages during initialization and connection | ||
| // attempts. |
There was a problem hiding this comment.
This doesn't look right (comment is in gutter).
| } | ||
|
|
||
| r.cmd.RunE = func(_ *cobra.Command, args []string) error { | ||
| r.cmd.RunE = func(_ *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
Just FYI, this could be r.cmd.RunE = func(*cobra.Command, []string) error {. No need for change.
| // the allowed retries or if the provided context is canceled. The logger is used | ||
| // for informational and debug messages during initialization and connection | ||
| // attempts. | ||
| func Initialize(ctx context.Context, opts *Options, logger *zap.SugaredLogger) (Output, error) { |
| // Add a newline for framing. | ||
| buf := make([]byte, len(b)+1) | ||
| copy(buf, b) | ||
| buf[len(b)] = '\n' | ||
| return o.conn.Write(buf) |
There was a problem hiding this comment.
In both cases this could be return o.conn.Write(append(b[:len(b):len(b)], '\n')) with safety.
| if (opts.TLSCertificate != "" || opts.TLSKey != "") && | ||
| (opts.TLSCertificate == "" || opts.TLSKey == "") { |
There was a problem hiding this comment.
if (opts.TLSCertificate == "") != (opts.TLSKey == "") {
or better
certIsZero := opts.TLSCertificate == ""
keyIsZero := opts.TLSKey == ""
if certIsZero != keyIsZero {
| if addr != "" { | ||
| h, err = url.Parse(addr) | ||
| if err != nil { | ||
| cancel() |
There was a problem hiding this comment.
I think rather than doing this, NewClient should accept a context.Context and the caller should have the responsibility to handle this.
| if _, err = io.Copy(&buf, resp.Body); err != nil { | ||
| return 0, fmt.Errorf("failed to read response body: %w", err) | ||
| } | ||
| defer resp.Body.Close() |
This commit addresses a large number of golangci-lint warnings across the codebase.
The fixes span multiple categories of linters.
io.Copyandflag.Value.Set.gofumpt.io/ioutilwithioandospackages.zap.OnFatalwithzap.WithFatalHook._).context.Contextas the first argument.internal/output/tlsandinternal/output/udppackages to match their dir names.The only remaining linter warning is for the TODO in the udp output.