jsonapi

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 17 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFoundJSONHandler = withJSONResponse(func(r *http.Request) (int, interface{}) {
	return http.StatusNotFound, nil
})

NotFoundJSONHandler returns a JSON HTTP 404 Not Found response

Functions

func GetSession

func GetSession(r *http.Request) session.Session

GetSession returns the Session for the given request

func LogActionID

func LogActionID(r *http.Request, id string)

LogActionID sets the ActionID for the given request

func ParseJSONBody

func ParseJSONBody(r *http.Request, vals ...interface{}) error

ParseJSONBody decodes the http.Request body into one or more values

Types

type APIRouter

type APIRouter struct {
	// contains filtered or unexported fields
}

APIRouter is an API Router

func New

func New(output io.Writer, auth auth.Auth, store session.Store, hook AuthHookFunc) *APIRouter

New returns a new APIRouter

func (*APIRouter) Handle

func (r *APIRouter) Handle(method, path string, handler ReturnHandlerFunc, auth bool)

Handle registers a ReturnHandlerFunc with the given parameters

func (*APIRouter) HandleTX

func (r *APIRouter) HandleTX(method, path string, db *sql.DB, handler TXReturnHandlerFunc, auth bool)

HandleTX registers a TXReturnHandlerFunc with the given parameters

func (*APIRouter) ServeHTTP

func (r *APIRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface

type AuthHookFunc

type AuthHookFunc func(session.Session) (status bool, attrs interface{}, err error)

AuthHookFunc is used to further check authorization of a Session and return extra attributes

type ReturnHandlerFunc

type ReturnHandlerFunc func(*http.Request) (int, interface{})

ReturnHandlerFunc returns an HTTP status code and body for the given request

func WithTX

func WithTX(db *sql.DB, next TXReturnHandlerFunc) ReturnHandlerFunc

WithTX returns a ReturnHandlerFunc for the given database and TXReturnHandlerFunc

type TXReturnHandlerFunc

type TXReturnHandlerFunc func(*http.Request, *sql.Tx) (int, interface{})

TXReturnHandlerFunc returns an HTTP status code and body for the given request and database handle

Jump to

Keyboard shortcuts

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