Skip to content

Commit e50540b

Browse files
Fixed 2 bugs
1 parent 71c43d3 commit e50540b

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

json.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
3030
return
3131
}
3232
w.WriteHeader(code)
33-
w.Write(dat)
33+
resp, writeErr := w.Write(dat)
34+
if writeErr != nil {
35+
log.Printf("Error writing data: %s", err)
36+
}
3437
}

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net/http"
99
"os"
10+
"time"
1011

1112
"github.com/go-chi/chi"
1213
"github.com/go-chi/cors"
@@ -90,6 +91,8 @@ func main() {
9091
router.Mount("/v1", v1Router)
9192
srv := &http.Server{
9293
Addr: ":" + port,
94+
ReadTimeout: 5 * time.Second,
95+
WriteTimeout: 10 * time.Second,
9396
Handler: router,
9497
}
9598

0 commit comments

Comments
 (0)