feat(mw): add content-type and response middleware
Add Content-Type enforcement middleware and generic JSON response helpers to standardize API responses. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package mw
|
||||
|
||||
import "net/http"
|
||||
|
||||
// JsonContentType sets Content-Type: application/json on all API responses.
|
||||
// Individual handlers that need to override (e.g. binary/image responses)
|
||||
// should set their own Content-Type header after this middleware runs.
|
||||
func JsonContentType(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user