fix(lint): resolve 6 golangci-lint issues blocking CI

- safe/safe.go: pass context.Background() to slog.LogAttrs (SA1012)
- capture_fingerprint/main.go: wrap ln/raw Close() defers to swallow err
- capture_fingerprint/peek_conn.go, serve_h2.go: ignore bytes.Buffer.Write
  return (cannot fail)
- verify_fingerprint/main.go: wrap resp.Body.Close() defer

These were pre-existing issues on release/custom-0.1.114 also failing
on v0.1.114.1. Fixing now so the current CI run turns green.
This commit is contained in:
erio
2026-04-18 21:55:29 +08:00
parent cfd9566905
commit 5794dc96ef
5 changed files with 7 additions and 6 deletions
+2 -1
View File
@@ -7,6 +7,7 @@
package safe
import (
"context"
"log/slog"
"runtime/debug"
)
@@ -61,5 +62,5 @@ func logPanic(event string, attrs []slog.Attr, panicValue any) {
slog.Any("panic", panicValue),
slog.String("stack", string(debug.Stack())),
)
slog.LogAttrs(nil, slog.LevelError, event+panicSuffix, logAttrs...)
slog.LogAttrs(context.Background(), slog.LevelError, event+panicSuffix, logAttrs...)
}
+2 -2
View File
@@ -49,7 +49,7 @@ func main() {
if err != nil {
log.Fatalf("listen %s: %v", *addr, err)
}
defer ln.Close()
defer func() { _ = ln.Close() }()
logStartupBanner(*addr)
acceptLoop(ln, tlsCfg, *outFile)
@@ -80,7 +80,7 @@ func acceptLoop(ln net.Listener, tlsCfg *ctls.Config, outFile string) {
}
func handleConn(raw net.Conn, tlsCfg *ctls.Config, outFile string) {
defer raw.Close()
defer func() { _ = raw.Close() }()
_ = raw.SetDeadline(time.Now().Add(30 * time.Second))
capture := &Capture{
@@ -27,7 +27,7 @@ func (p *peekConn) peek(n int) ([]byte, error) {
if _, err := io.ReadFull(p.Conn, chunk); err != nil {
return nil, err
}
p.buf.Write(chunk)
_, _ = p.buf.Write(chunk)
return chunk, nil
}
@@ -186,7 +186,7 @@ func (s *h2Session) handleData(f *http2.DataFrame) {
if len(data) > need {
data = data[:need]
}
buf.Write(data)
_, _ = buf.Write(data)
}
if f.StreamEnded() {
// Attach body preview back to the matching request.
+1 -1
View File
@@ -73,7 +73,7 @@ func main() {
fmt.Printf("check capture server log for ClientHello details\n")
return
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(resp.Body)
fmt.Printf("status=%d body=%s\n", resp.StatusCode, body)
}