Documentation ¶
Index ¶
- func Authorize(serviceKey string) (mw func(basehttp.Handler) basehttp.Handler)
- func GetResponseWriter(w interface{}) basehttp.ResponseWriter
- func Respond(w nh.ResponseWriter, r *nh.Request, statusCode int, response interface{})
- func RespondError(w nh.ResponseWriter, r *nh.Request, statusCode int, detail ...interface{})
- func RespondOk(w nh.ResponseWriter, r *nh.Request, response interface{})
- func SetHTMLTemplatePaths(applicationHTML, textHTML string)
- func StartServer(srv *base_http.Server)
- type RespondErrorDetail
- type ResponseError
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetResponseWriter ¶
func GetResponseWriter(w interface{}) basehttp.ResponseWriter
func Respond ¶
func Respond(w nh.ResponseWriter, r *nh.Request, statusCode int, response interface{})
Respond is used to return data to the client with a custom http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).
func RespondError ¶
func RespondError(w nh.ResponseWriter, r *nh.Request, statusCode int, detail ...interface{})
RespondError is used to return errors to the client The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths). Be careful in here not to recurse (by calling RespondError() again) when there is an error. For the detail parameter, only error, string and RespondErrorDetail types are useful.
func RespondOk ¶
func RespondOk(w nh.ResponseWriter, r *nh.Request, response interface{})
RespondOk is used to return data to the client with a 200 http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).
func SetHTMLTemplatePaths ¶
func SetHTMLTemplatePaths(applicationHTML, textHTML string)
SetHTMLTemplatePaths allows the application to specify the paths to HTML tempate files that will be used for responses with HTML content-types. If a template path is empty, it will not be used and the default content-type (application/json) will be used instead. Template paths are empty by default.
func StartServer ¶
Types ¶
type RespondErrorDetail ¶
type RespondErrorDetail string
RespondErrorDetail allows a RespondError detail parameter to end up in the Details array
type ResponseError ¶
type ResponseError struct { StatusCode int `json:"status_code"` Message string `json:"message"` Documentation string `json:"documentation"` Details []string `json:"details,omitempty"` }
ResponseError structure holds standard fields for errors. Public so that when two of our own applications communicate; one can parse the error received from the other.