lint: fix errcheck in api/api.go debug log writes
Add lint.Fprintf and lint.Write helpers for safe writer operations. Use lint.Fprintf for unchecked fmt.Fprintf calls in webhookFieldseeker.
This commit is contained in:
parent
970cd568dc
commit
c83606908f
2 changed files with 21 additions and 3 deletions
|
|
@ -294,7 +294,7 @@ func webhookFieldseeker(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
for name, values := range r.Header {
|
||||
for _, value := range values {
|
||||
fmt.Fprintf(file, "%s: %s\n", name, value)
|
||||
lint.Fprintf(file, "%s: %s\n", name, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,11 +323,11 @@ func webhookFieldseeker(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if len(body) == 0 {
|
||||
fmt.Fprintf(file, "(empty body)")
|
||||
lint.Fprintf(file, "(empty body)")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(file, "\n=== End of request ===\n\n")
|
||||
lint.Fprintf(file, "\n=== End of request ===\n\n")
|
||||
|
||||
// Extract the crc_token value for the signature portion
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package lint
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
|
@ -33,3 +35,19 @@ func LogOnErrRollback(f ErrorableCtx, ctx context.Context, msg string) {
|
|||
log.Error().Err(e).Msg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Fprintf writes a formatted string to w, logging any error.
|
||||
func Fprintf(w io.Writer, format string, args ...any) {
|
||||
_, err := fmt.Fprintf(w, format, args...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("fprintf failed")
|
||||
}
|
||||
}
|
||||
|
||||
// Write writes p to w, logging any error.
|
||||
func Write(w io.Writer, p []byte) {
|
||||
_, err := w.Write(p)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("write failed")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue