Documentation
¶
Overview ¶
Package httpserver provides common HTTP server functionality.
Index ¶
- Constants
- func AcceptsMediaType(w http.ResponseWriter, r *http.Request, strict bool, mts ...string) (string, bool)
- func EnableCors(w http.ResponseWriter)
- func HandleError(w http.ResponseWriter, err error, reqType string)
- func MethodOK(w http.ResponseWriter, r *http.Request, method string) bool
- func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)
Constants ¶
View Source
const ( MediaTypeNDJson = "application/x-ndjson" MediaTypeJson = "application/json" MediaTypeAny = "*/*" )
Variables ¶
This section is empty.
Functions ¶
func AcceptsMediaType ¶ added in v0.13.0
func AcceptsMediaType(w http.ResponseWriter, r *http.Request, strict bool, mts ...string) (string, bool)
AcceptsMediaType checks whether the request Accept header matches one of the given media types and returns the first match. When strict is false and Accept is empty, it accepts. On mismatch or invalid Accept, it writes StatusNotAcceptable and returns false.
func EnableCors ¶ added in v0.13.0
func EnableCors(w http.ResponseWriter)
EnableCors sets Access-Control-Allow-Origin to allow any origin.
func HandleError ¶
func HandleError(w http.ResponseWriter, err error, reqType string)
func WriteJsonResponse ¶
func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.