Documentation ¶
Overview ¶
Package httputil contains a collection of HTTP request and response utility functions.
Index ¶
- Constants
- func AddBasicAuth(apiKey, apiSecret string, r *http.Request)
- func HeaderOrDefault(r *http.Request, key string, defaultValue string) string
- func Link(url, template string, segments ...interface{}) string
- func PathParam(r *http.Request, name string) string
- func QueryIntOrDefault(q url.Values, key string, def int) int
- func QueryUintOrDefault(q url.Values, key string, def uint) uint
- func SendJSON(ctx context.Context, w http.ResponseWriter, statusCode int, data interface{})
- func SendStatus(ctx context.Context, w http.ResponseWriter, statusCode int)
- func SendText(ctx context.Context, w http.ResponseWriter, statusCode int, data string)
- type Status
Constants ¶
View Source
const ( // MimeApplicationJSON contains the mime type string for JSON content. MimeApplicationJSON = "application/json; charset=utf-8" // MimeTextPlain contains the mime type string for text content. MimeTextPlain = "text/plain; charset=utf-8" )
View Source
const ( StatusSuccess = "success" StatusFail = "fail" StatusError = "error" )
JSend status codes.
Variables ¶
This section is empty.
Functions ¶
func AddBasicAuth ¶
AddBasicAuth decorates the provided http.Request with Basic Authorization.
func HeaderOrDefault ¶
HeaderOrDefault returns the value of an HTTP header or a default value.
func Link ¶ added in v1.2.0
Link generates a public Link using the service url. It replaces all segments into the template. The template then gets joined at the end of the service url.
func QueryIntOrDefault ¶ added in v1.3.0
QueryIntOrDefault set default value for a particular int key.
func QueryUintOrDefault ¶ added in v1.3.0
QueryUintOrDefault set default value for a particular uint key.
func SendJSON ¶
func SendJSON(ctx context.Context, w http.ResponseWriter, statusCode int, data interface{})
SendJSON sends a JSON object to the response.
func SendStatus ¶
func SendStatus(ctx context.Context, w http.ResponseWriter, statusCode int)
SendStatus sends write a HTTP status code to the response.
Types ¶
Click to show internal directories.
Click to hide internal directories.