response

package
v3.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2023 License: GPL-2.0 Imports: 8 Imported by: 3

Documentation

Index

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

func JsonDecode(r *request.Request, data interface{}) error

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 JsonError added in v3.2.9

func JsonError(r *request.Request, msg string, statusCode int, err error) error

func Render

func Render(r *request.Request, templateName string) error

Template configuration must be set before calling this function!

See the templates package for more information.

func String

func String(r *request.Request, templateString string) error

Render a string as a template

func Template added in v3.2.8

func Template(r *request.Request, t *template.Template, name string) error

Render a template with the given name

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

func NewJsonError(message string, statusCode int, err error) *JSONError

Create a new JSONError

func (*JSONError) Error added in v3.2.9

func (e *JSONError) Error() string

func (*JSONError) Unwrap added in v3.2.9

func (e *JSONError) Unwrap() error

func (*JSONError) Write added in v3.2.9

func (e *JSONError) Write(r *request.Request) error

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL