Documentation
¶
Index ¶
- func AccessDenied(writer http.ResponseWriter)
- func BadRequest(writer http.ResponseWriter, response interface{})
- func Error(writer http.ResponseWriter, response interface{})
- func Forbidden(writer http.ResponseWriter, response interface{})
- func JSONBadRequest(writer http.ResponseWriter, message string)
- func JSONError(writer http.ResponseWriter, message string)
- func JSONForbidden(writer http.ResponseWriter, message string)
- func JSONNotFound(writer http.ResponseWriter, message string)
- func JSONSuccess(writer http.ResponseWriter, message string)
- func LoadHTML(pageName string) ([]byte, error)
- func NotFound(writer http.ResponseWriter, response interface{})
- func ParseJSONBody(request *http.Request, receiver interface{}) error
- func RenderHTML(writer http.ResponseWriter, pageName string) error
- func RenderTemplate(writer http.ResponseWriter, pageName string, data interface{}) error
- func RequestIsJSONContentType(request *http.Request) bool
- func SessionExpired(writer http.ResponseWriter)
- func SplitListOfIntsInURL(request *http.Request, key string, delimiter string) []int
- func Success(writer http.ResponseWriter, response interface{})
- func WriteHTML(writer http.ResponseWriter, html string, code int)
- func WriteJSON(writer http.ResponseWriter, object interface{}, code int)
- func WriteText(writer http.ResponseWriter, text string, code int)
- type BasicJSONResponse
- func (response BasicJSONResponse) BadRequest(writer http.ResponseWriter)
- func (response BasicJSONResponse) Error(writer http.ResponseWriter)
- func (response BasicJSONResponse) Forbidden(writer http.ResponseWriter)
- func (response BasicJSONResponse) NotFound(writer http.ResponseWriter)
- func (response BasicJSONResponse) Success(writer http.ResponseWriter)
- type Layout
- type SessionExpiredResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessDenied ¶
func AccessDenied(writer http.ResponseWriter)
AccessDenied is a convenience method. This will set the HTTP status code to 403 and send back a BasicJSONResponse with a message of Access Denied
func BadRequest ¶
func BadRequest(writer http.ResponseWriter, response interface{})
BadRequest is a convenience method. This will set the HTTP status code to 400. This is useful for telling a caller that the request is malformed.
func Error ¶
func Error(writer http.ResponseWriter, response interface{})
Error is a convenience method. This will set the HTTP status code to 500. This is useful for indicating some type of error ocurred during processing.
func Forbidden ¶
func Forbidden(writer http.ResponseWriter, response interface{})
Forbidden is a convenience method. This will set the HTTP status code to 403. This is useful in telling a caller that some type of authentication failed.
func JSONBadRequest ¶
func JSONBadRequest(writer http.ResponseWriter, message string)
JSONBadRequest is a shortcut to send a bad request with a basic JSON object
func JSONError ¶
func JSONError(writer http.ResponseWriter, message string)
JSONError is a shortcut to send an error with a basic JSON object
func JSONForbidden ¶
func JSONForbidden(writer http.ResponseWriter, message string)
JSONForbidden is a shortcut to send a forbidden response with a basic JSON object
func JSONNotFound ¶
func JSONNotFound(writer http.ResponseWriter, message string)
JSONNotFound is a shortcut to send a not found message with a basic JSON object
func JSONSuccess ¶
func JSONSuccess(writer http.ResponseWriter, message string)
JSONSuccess is a shortcut to send a 200 with a basic JSON object
func LoadHTML ¶
LoadHTML loads a file with the specified name and returns a byte array of its contents. This will automatically append the HTML extension to the end of the page name
func NotFound ¶
func NotFound(writer http.ResponseWriter, response interface{})
NotFound is a convenience method. This will set the HTTP status code to 404. This is useful in telling a caller that the resources they are trying to get is not found.
func ParseJSONBody ¶
ParseJSONBody is useful when a POST or PUT request has a Content-Type of application/json and the body has JSON data. Pass the address of a receiver variable and this function will fill in the values from the request JSON into any matching struct fields, or will hydrate them into a map if possible.
func RenderHTML ¶
func RenderHTML(writer http.ResponseWriter, pageName string) error
RenderHTML takes the name of a page, loads it, and writes it to the provided ResponseWriter.
func RenderTemplate ¶
func RenderTemplate(writer http.ResponseWriter, pageName string, data interface{}) error
RenderTemplate takes a page name, loads it, executes it as a template against the provided data, then writes it to the provided ResponseWriter
func RequestIsJSONContentType ¶
REquestIsJSONContentType returns true/false if the request contains a Content-Type header, and if that header is set to "application/json".
func SessionExpired ¶
func SessionExpired(writer http.ResponseWriter)
SessionExpired is a convenience method for telling clients that a session has expired. This sends a SessionExpiredResponse structure and a status of 401 Unauthorized.
func SplitListOfIntsInURL ¶
SplitListOfIntsInURL takes a delimited list value in a URL key and splits it into a slice of integers
func Success ¶
func Success(writer http.ResponseWriter, response interface{})
Success is a convenience method. This will set the HTTP status code to 200.
func WriteHTML ¶
func WriteHTML(writer http.ResponseWriter, html string, code int)
WriteHTML writes HTML out to a ResponseWriter
func WriteJSON ¶
func WriteJSON(writer http.ResponseWriter, object interface{}, code int)
WriteJSON serializes an object to JSON and writes it to the specified writer stream with an HTTP code. The object is of type interface{} so can technically be anything. A struct or map would be the usual type of item to serialize.
Types ¶
type BasicJSONResponse ¶
A BasicJSONResponse allows you to return a message and a success indicator
func ErrorJSONResponse ¶
func ErrorJSONResponse(message string) BasicJSONResponse
func NewBasicJSONResponse ¶
func NewBasicJSONResponse(success bool, message string) BasicJSONResponse
NewBasicJSONResponse creates a new structure.
func (BasicJSONResponse) BadRequest ¶
func (response BasicJSONResponse) BadRequest(writer http.ResponseWriter)
BadRequest sends this basic JSON response as a 400
func (BasicJSONResponse) Error ¶
func (response BasicJSONResponse) Error(writer http.ResponseWriter)
Error sends this basic JSON response as a 500
func (BasicJSONResponse) Forbidden ¶
func (response BasicJSONResponse) Forbidden(writer http.ResponseWriter)
Forbidden sends this basic JSON response as a 403
func (BasicJSONResponse) NotFound ¶
func (response BasicJSONResponse) NotFound(writer http.ResponseWriter)
NotFound sends this basic JSON response as a 404
func (BasicJSONResponse) Success ¶
func (response BasicJSONResponse) Success(writer http.ResponseWriter)
Success sends this basic JSON response as a 200
type Layout ¶
type Layout struct { BaseDirectory string TemplateFileNames []string TemplateBodies map[string]string }
Layout represents a directory of template files and pre-loaded bodies
func (Layout) RenderView ¶
func (this Layout) RenderView(writer http.ResponseWriter, pageName string, data interface{}) error
type SessionExpiredResponse ¶
type SessionExpiredResponse struct { Success bool `json:"success"` SessionExpired bool `json:"sessionExpired"` }
func NewSessionExpiredResponse ¶
func NewSessionExpiredResponse() SessionExpiredResponse
Creates a new SessionExpiredResponse structure.