response

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 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 Decode

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

Decoode json from a request, into any.

func Encode

func Encode(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 JSON

func JSON(r *request.Request, jsonResponse *JSONResponse) error

Encode json to a request.

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 RenderTemplate

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

Render a template with the given name

func String

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

Render a string as a template

Types

type JSONResponse

type JSONResponse struct {
	Next   string         `json:"next,omitempty"`
	Detail string         `json:"detail,omitempty"`
	Status ResponseStatus `json:"status"`
	Data   interface{}    `json:"data"`
}

Default json response which gets returned when using (j).Encode().

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