Skip to content

Commit

Permalink
fix golangci-lint findings
Browse files Browse the repository at this point in the history
  • Loading branch information
petracihalova committed Dec 5, 2024
1 parent 50ef8f1 commit 93e1a60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 5 additions & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func InitLogger() *zap.Logger {

logger, _ := loggerConfig.Build(options...)

defer logger.Sync()
defer func() {
if err := logger.Sync(); err != nil {
fmt.Printf("Failed to sync logger: %v", err)
}
}()
Log = logger
}

Expand Down
9 changes: 0 additions & 9 deletions requests/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ import (
"fmt"
"net/http"

l "github.com/redhatinsights/uhc-auth-proxy/logger"
"github.com/redhatinsights/uhc-auth-proxy/requests/client"
"github.com/spf13/viper"
"go.uber.org/zap"
)

var log *zap.Logger

func init() {
l.InitLogger()
log = l.Log.Named("cluster")
}

// GetIdentity is a facade over all the steps required to get an Identity
func GetIdentity(wrapper client.Wrapper, reg Registration) (*Identity, error) {

Expand Down
10 changes: 8 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ func RootHandler(wrapper client.Wrapper) func(w http.ResponseWriter, r *http.Req

w.Header().Add("Content-Type", "application/json")
respond(200)
w.Write(out)
_, err = w.Write(out)
if err != nil {
logr.Error("failed to write response", zap.Error(err))
}
}
}

Expand All @@ -186,7 +189,10 @@ func getErrorStatusCode(err error) int {

// StatusHandler handles a basic /status endpoint for information/ready checks
func StatusHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]string{"status": "available"})
err := json.NewEncoder(w).Encode(map[string]string{"status": "available"})
if err != nil {
log.Error(fmt.Sprintf("Failed to encode response: %v", err))
}
}

// Start starts the server
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func call(wrapper client.Wrapper, userAgent string, auth string) (*httptest.Resp
Expect(err).To(BeNil())
rr.Result().Body.Close()
var ident cluster.Identity
json.Unmarshal(out, &ident)
_ = json.Unmarshal(out, &ident)
return rr, &ident
}

Expand Down

0 comments on commit 93e1a60

Please sign in to comment.