Documentation ¶
Index ¶
- func BadRequest(writer http.ResponseWriter, message string)
- func Error(writer http.ResponseWriter, message string)
- func Forbidden(writer http.ResponseWriter, message string)
- func LoadHtml(pageName string) ([]byte, error)
- func NotFound(writer http.ResponseWriter, message string)
- 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, message string)
- 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
- type Layout
- type SessionExpiredResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(writer http.ResponseWriter, message string)
Convenience method sending out a BasicJsonResponse in JSON format with a success of FALSE. 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, message string)
Convenience method sending out a BasicJsonResponse in JSON format with a success of FALSE. 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, message string)
Convenience method sending our a BasicJsonResponse in JSON format with a success of FALSE. This will set the HTTP status code to 403. This is useful in telling a caller that some type of authentication failed.
func NotFound ¶
func NotFound(writer http.ResponseWriter, message string)
Convenience method sending out a BasicJsonResponse in JSON format with a success of FALSE. 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 ¶
This function 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
func RenderTemplate ¶
func RenderTemplate(writer http.ResponseWriter, pageName string, data interface{}) error
func 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)
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, message string)
Convenience method sending out a BasicJsonResponse in JSON format with a success of TRUE. This will set the HTTP status code to 200.
func WriteJson ¶
func WriteJson(writer http.ResponseWriter, object interface{}, code int)
This function 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 ¶
func NewBasicJsonResponse ¶
func NewBasicJsonResponse(success bool, message string) BasicJsonResponse
Creates a new BasicJsonResponse structure.
type Layout ¶
type Layout struct { BaseDirectory string TemplateFileNames []string TemplateBodies map[string]string }
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.