lint: fix errcheck for fmt.Fprintf/Fprint across multiple files
Add lint.Fprint helper for unchecked fmt.Fprint calls. Use lint.Fprintf/Fprint in api/event.go, api/image.go, rmo/root.go. Add explicit error check for fmt.Fprintf in middleware/terminal.go cW.
This commit is contained in:
parent
934fb03ca2
commit
c7a7e8431c
5 changed files with 20 additions and 8 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/version"
|
||||
|
|
@ -135,7 +136,7 @@ func streamEvents(w http.ResponseWriter, r *http.Request, u platform.User) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "data: %s\n\n", body)
|
||||
lint.Fprintf(w, "data: %s\n\n", body)
|
||||
w.(http.Flusher).Flush()
|
||||
|
||||
// Keep the connection open with a ticker sending periodic events
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
||||
"github.com/aarondl/opt/omit"
|
||||
|
|
@ -80,5 +80,5 @@ func apiImageContentPost(w http.ResponseWriter, r *http.Request, u platform.User
|
|||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
log.Printf("Saved image file %s\n", imageUUID)
|
||||
fmt.Fprintf(w, "PNG uploaded successfully")
|
||||
lint.Fprintf(w, "PNG uploaded successfully")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,3 +51,11 @@ func Write(w io.Writer, p []byte) {
|
|||
log.Error().Err(err).Msg("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
// Fprint writes a string to w, logging any error.
|
||||
func Fprint(w io.Writer, a ...any) {
|
||||
_, err := fmt.Fprint(w, a...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("fprint failed")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,9 +59,12 @@ func cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{})
|
|||
return fmt.Errorf("write color: %w", err)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(w, s, args...)
|
||||
_, err := fmt.Fprintf(w, s, args...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fprintf: %w", err)
|
||||
}
|
||||
if IsTTY && useColor {
|
||||
_, err := w.Write(reset)
|
||||
_, err = w.Write(reset)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write color: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package rmo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
|
@ -76,8 +76,8 @@ func getRootDistrict(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getRobots(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "User-agent: *\n")
|
||||
fmt.Fprint(w, "Allow: /\n")
|
||||
lint.Fprint(w, "User-agent: *\n")
|
||||
lint.Fprint(w, "Allow: /\n")
|
||||
}
|
||||
func getTerms(w http.ResponseWriter, r *http.Request) {
|
||||
html.RenderOrError(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue