26 lines
590 B
Go
26 lines
590 B
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package middleware
|
|
|
|
import "net/http"
|
|
|
|
const maxUploadSizeBytes int64 = 20 << 20
|
|
|
|
type FileSizeLimitMiddleware struct {
|
|
}
|
|
|
|
func NewFileSizeLimitMiddleware() *FileSizeLimitMiddleware {
|
|
return &FileSizeLimitMiddleware{}
|
|
}
|
|
|
|
func (m *FileSizeLimitMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == http.MethodPost && r.URL != nil && r.URL.Path == "/api/v1/upload" {
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSizeBytes)
|
|
}
|
|
|
|
next(w, r)
|
|
}
|
|
}
|