web

package
v0.0.0-...-e100621 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const KeyValues ctxKey = 1

KeyValues ...

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Request, val interface{}) error

Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value.

If the provided value is a struct then it is checked for validation tags.

func IsShutdown

func IsShutdown(err error) bool

func NewRequestError

func NewRequestError(err error, status int) error

NewRequestError ...

func NewShutdownError

func NewShutdownError(message string) error

NewShutdownError ...

func Param

func Param(r *http.Request, key string) string

Param returns the web call parameters from the request.

func Params

func Params(r *http.Request) map[string]string

Params returns the web call parameters from the request.

func Respond

func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, statusCode int) error

Respond converts a Go value to JSON and sends it to the client.

func RespondError

func RespondError(ctx context.Context, w http.ResponseWriter, err error) error

Types

type App

type App struct {
	*httptreemux.ContextMux
	// contains filtered or unexported fields
}

App ...

func NewApp

func NewApp(shutdown chan os.Signal, mw ...Middleware) *App

NewApp ...

func (*App) Handle

func (a *App) Handle(method string, path string, handler Handler, mw ...Middleware)

func (*App) SignalShutdown

func (a *App) SignalShutdown()

SignalShutdown ...

type Error

type Error struct {
	Err    error
	Status int
	Fields []FieldError
}

Error ...

func (*Error) Error

func (err *Error) Error() string

Error ...

type ErrorResponse

type ErrorResponse struct {
	Error  string       `json:"error"`
	Fields []FieldError `json:"fields,omitempty"`
}

ErrorResponse ...

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

FieldError ...

type Handler

type Handler func(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Handler ...

type Middleware

type Middleware func(Handler) Handler

Middleware ...

type PaginatedLimitOffsetResponse

type PaginatedLimitOffsetResponse struct {
	Limit   int `json:"limit"`
	Offset  int `json:"offset"`
	Records int `json:"records"`
	Total   int `json:"total"`
}

PaginatedLimitOffsetResponse ...

type Values

type Values struct {
	TraceID    string
	Now        time.Time
	StatusCode int
}

Values ...

Jump to

Keyboard shortcuts

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