Documentation
¶
Index ¶
- Variables
- func Json(r *request.Request, jsonResponse *JSONResponse) error
- func JsonDecode(r *request.Request, data interface{}) error
- func JsonEncode(r *request.Request, data interface{}, status ...ResponseStatus) error
- func JsonError(r *request.Request, msg string, statusCode int, err error) error
- func Render(r *request.Request, templateName string) error
- func String(r *request.Request, templateString string) error
- func Template(r *request.Request, t *template.Template, name string) error
- type JSONError
- type JSONResponse
- type ResponseStatus
Constants ¶
This section is empty.
Variables ¶
View Source
var DEFAULT_DATA_FUNC func(r *request.Request)
View Source
var TEMPLATE_MANAGER *templates.Manager
Functions ¶
func Json ¶ added in v3.2.8
func Json(r *request.Request, jsonResponse *JSONResponse) error
Encode json to a request.
func JsonDecode ¶ added in v3.2.8
Decoode json from a request, into any.
func JsonEncode ¶ added in v3.2.8
func JsonEncode(r *request.Request, data interface{}, status ...ResponseStatus) error
Render json to a request. Response will be in the form of:
{
"status": "ok",
"data": {
"key": "value"
}
}
func Render ¶
Template configuration must be set before calling this function!
See the templates package for more information.
Types ¶
type JSONError ¶ added in v3.2.9
type JSONError struct {
Message string `json:"message"`
StatusCode int `json:"status_code"` // HTTP status code
// The error that caused this error
Err error `json:"-"`
}
Render a JSONError to a request.
func NewJsonError ¶ added in v3.2.9
Create a new JSONError
type JSONResponse ¶
type JSONResponse struct {
Next string `json:"next,omitempty"`
Detail string `json:"detail,omitempty"`
Status ResponseStatus `json:"status"`
Data interface{} `json:"data"`
}
type ResponseStatus ¶
type ResponseStatus string
const ( ResponseStatusOK ResponseStatus = "ok" ResponseStatusError ResponseStatus = "error" ResponseStatusRedirect ResponseStatus = "redirect" )
Click to show internal directories.
Click to hide internal directories.