api

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 9 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildJSONResponse = func(response ResponseInfo) ([]byte, error) {
	return json.MarshalIndent(&response, "", "  ")
}

BuildJSONResponse allows implementers to control the json response form from the api

View Source
var IgnoredFormFields []string

IgnoredFormFields are ignored by FormValues() when checking for extraneous fields

View Source
var Log = func(*http.Request, *Response, error) {}

Log allows logging of events and errors

View Source
var ResponseHeaders map[string]string

ResponseHeaders are returned with each response

View Source
var TraceEnabled = false

TraceEnabled Attaches a trace field to the JSON response when enabled.

Functions

func FormValues

func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldRules) error

Types

type Handler

type Handler func(r *http.Request) Response

Handler handles API requests

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Response

type Response struct {
	Status      int
	Data        interface{}
	RedirectURL string
	Error       error
}

Response is returned by API handlers

type ResponseInfo added in v2.4.2

type ResponseInfo struct {
	Success bool        `json:"success"`
	Error   *string     `json:"error"`
	Data    interface{} `json:"data"`
	Trace   []string    `json:"_trace,omitempty"`
}

http://choly.ca/post/go-json-marshalling/

type StatusError

type StatusError struct {
	Status int
	Err    error
}

StatusError represents an error with an associated HTTP status code.

func (StatusError) Error

func (se StatusError) Error() string

Jump to

Keyboard shortcuts

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