feat(platform-api): enforce request timeout
This commit is contained in:
@@ -35,5 +35,12 @@ func NewServer(cfg config.Config) http.Handler {
|
||||
}
|
||||
}
|
||||
api := platform.NewHandler(platform.NewService(store))
|
||||
return static.Handler(cfg.StaticDir, api)
|
||||
return withRequestTimeout(static.Handler(cfg.StaticDir, api), cfg.RequestTimeout)
|
||||
}
|
||||
|
||||
func withRequestTimeout(next http.Handler, timeout time.Duration) http.Handler {
|
||||
if timeout <= 0 {
|
||||
return next
|
||||
}
|
||||
return http.TimeoutHandler(next, timeout, `{"error":{"code":"REQUEST_TIMEOUT","message":"请求处理超时"},"traceId":"timeout","timestamp":0}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user