Skip to content

Commit

Permalink
Fix gosec issues
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-jiva committed Jan 3, 2025
1 parent 4eec2de commit 52e99aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 11 additions & 9 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ func respondWithError(w http.ResponseWriter, code int, msg string) {
}

func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
w.Header().Set("Content-Type", "application/json")
dat, err := json.Marshal(payload)
if err != nil {
log.Printf("Error marshalling JSON: %s", err)
w.WriteHeader(500)
return
}
w.WriteHeader(code)
w.Write(dat)
w.Header().Set("Content-Type", "application/json")
dat, err := json.Marshal(payload)
if err != nil {
log.Printf("Error marshalling JSON: %s", err)
w.WriteHeader(500)
return
}
w.WriteHeader(code)
if _, err := w.Write(dat); err != nil {
log.Printf("Error writing response: %s", err)
}
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -91,6 +92,7 @@ func main() {
srv := &http.Server{
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: 5 * time.Second,
}

log.Printf("Serving on port: %s\n", port)
Expand Down

0 comments on commit 52e99aa

Please sign in to comment.