limit upload size, update build info
This commit is contained in:
parent
ec9b29f680
commit
1b84a99001
|
@ -2,7 +2,10 @@
|
|||
|
||||
> Boilerplate for how I like to write a backend web service
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
export GOFLAGS="-mod=vendor"
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
go generate -mod=vendor ./...
|
||||
|
|
13
main.go
13
main.go
|
@ -92,6 +92,8 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
var defaultMaxBytes int64 = 1 << 20
|
||||
|
||||
func serve() {
|
||||
r := chi.NewRouter()
|
||||
|
||||
|
@ -105,6 +107,10 @@ func serve() {
|
|||
r.Use(middleware.Logger)
|
||||
r.Use(middleware.Recoverer)
|
||||
|
||||
r.Route("/api", func(r chi.Router) {
|
||||
r.Use(limitResponseSize)
|
||||
})
|
||||
|
||||
var staticHandler http.HandlerFunc
|
||||
pub := http.FileServer(assets.Assets)
|
||||
|
||||
|
@ -142,3 +148,10 @@ func serve() {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func limitResponseSize(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, defaultMaxBytes)
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue