Documentation
¶
Index ¶
- Variables
- func Json(w http.ResponseWriter, jsonResponse *JSONResponse) error
- func JsonDecode(r *http.Request, data interface{}) error
- func JsonEncode(w http.ResponseWriter, data interface{}, status ...ResponseStatus) error
- func JsonError(w http.ResponseWriter, message string, statusCode int, err error) error
- func Render(w http.ResponseWriter, templateName string, data any) error
- func String(w http.ResponseWriter, templateString string, data any) error
- type JSONError
- type JSONResponse
- type ResponseStatus
Constants ¶
This section is empty.
Variables ¶
View Source
var TEMPLATE_MANAGER *templates.Manager
Functions ¶
func Json ¶
func Json(w http.ResponseWriter, jsonResponse *JSONResponse) error
Encode json to a request.
func JsonDecode ¶
Decoode json from a request, into any.
func JsonEncode ¶
func JsonEncode(w http.ResponseWriter, data interface{}, status ...ResponseStatus) error
Render json to a request. Response will be in the form of:
{
"status": "ok",
"data": {
"key": "value"
}
}
Types ¶
type JSONError ¶
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 ¶
Create a new JSONError
type JSONResponse ¶
type JSONResponse struct {
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.