rest

package
v0.0.0-...-8644ba8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorized unauthorized error
	ErrUnauthorized = errors.New(http.StatusText(http.StatusForbidden))
	// ErrNotFound not found error
	ErrNotFound = errors.New(http.StatusText(http.StatusNotFound))
	// ErrInvalid invalid error
	ErrInvalid = errors.New("invalid")
	// ErrDuplicate duplicate error
	ErrDuplicate = errors.New("duplicate")
	// ErrMethodNotAllowed HTTP method not allowed
	ErrMethodNotAllowed = errors.New(http.StatusText(http.StatusMethodNotAllowed))
)

Functions

func BodyParameter

func BodyParameter(s spec.Schema) spec.Parameter

BodyParameter body parameter with Required true

func CreateResponses

func CreateResponses() *spec.Responses

CreateResponses responses for create operation

func DeleteResponses

func DeleteResponses() *spec.Responses

DeleteResponses responses for delete operation

func Errored

func Errored(w http.ResponseWriter, err error) bool

Errored writes errors to the HTTP response writer

func HandlerFunc

func HandlerFunc(paths spec.Paths) http.HandlerFunc

HandlerFunc writes the spec as json

func PasswordHandlerFunc

func PasswordHandlerFunc(accountReader security.AccountReader, f http.HandlerFunc) http.HandlerFunc

PasswordHandlerFunc request.Form must be initialized before

func PathHandlerFunc

func PathHandlerFunc(path string, f http.HandlerFunc) http.HandlerFunc

PathHandlerFunc supports single path parameter only /path/{parameter} calls http.HandleFunc with DefaultServeMux path reference https://www.reddit.com/r/golang/comments/3z10p1/create_dynamic_paths_in_httphandle_with_only/cyicw0t

func ReadResponses

func ReadResponses() *spec.Responses

ReadResponses responses for read operation

func Redact

func Redact(pb proto.Message)

Redact clears every sensitive field in pb.

func UpdateResponses

func UpdateResponses() *spec.Responses

UpdateResponses responses for update operation

func Validate

func Validate(r *http.Request, o *spec.Operation, pb proto.Message) error

Validate body parameter

func ValidateParameter

func ValidateParameter(r http.Request, p spec.Parameter) (string, error)

ValidateParameter path and query parameters

func ValidateParameterQueryAction

func ValidateParameterQueryAction(r http.Request, ps ...spec.Parameter) string

ValidateParameterQueryAction query parameter for actions, no value, not required

func WriteProto

func WriteProto(w http.ResponseWriter, pb proto.Message)

WriteProto jsonpb marshal a proto

func WriteProtoCreated

func WriteProtoCreated(w http.ResponseWriter, pb proto.Message, location string)

WriteProtoCreated sets 201 and Location header

func WriteProtos

func WriteProtos(w http.ResponseWriter, pbs []proto.Message)

WriteProtos marshal many protos

Types

type HeaderHandler

type HeaderHandler struct {
	ServeMux *http.ServeMux
	Origin   string
}

HeaderHandler adds HTTP headers

func (HeaderHandler) ServeHTTP

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

type ValidationError

type ValidationError struct {
	Property string `json:"property,omitempty"`
	Rule     string `json:"rule,omitempty"`
}

ValidationError with JSON tags

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors returned to the user

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Jump to

Keyboard shortcuts

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