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>
14 lines
464 B
Go
14 lines
464 B
Go
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)
|
|
})
|
|
}
|