Documentation ¶
Index ¶
- Variables
- func BadRequest(req *http.Request, message string) error
- func Forbidden(req *http.Request) error
- func Internal(req *http.Request) error
- func JSON(rw http.ResponseWriter, status int, v interface{}) error
- func NewQuietError(req *http.Request, code int32, e error) error
- func NewQuietWrap(req *http.Request, code int32, detail string) error
- func NewRedirectingError(req *http.Request, code int32, e error) error
- func NewRequestError(req *http.Request, code int32, detail string) error
- func NotFound(req *http.Request, message string) error
- func Proto(rw http.ResponseWriter, status int, pb proto.Message) error
- func ProtoOK(rw http.ResponseWriter, pb proto.Message) error
- type Config
- type Error
- type Handle
- type HandleError
- type Module
- func (m *Module) DELETE(path string, h Handle)
- func (m *Module) EmptyJSON(rw http.ResponseWriter, status int) error
- func (m *Module) Error(rw http.ResponseWriter, status int32, errors ...*api.Error) error
- func (m *Module) GET(path string, h Handle)
- func (m *Module) GetErrorCode(err error) int
- func (m *Module) Handle(method, path string, h http.HandlerFunc)
- func (m *Module) HandleError(rw http.ResponseWriter, req *http.Request, err error) int
- func (m *Module) Init(c *service.Config)
- func (m *Module) PATCH(path string, h Handle)
- func (m *Module) POST(path string, h Handle)
- func (m *Module) PUT(path string, h Handle)
- func (m *Module) Shutdown(ctx context.Context)
- func (m *Module) Subrouter(path string) *httprouter.Router
- func (m *Module) WrappedHandle(method, path string, h Handle)
- type Params
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func JSON ¶
func JSON(rw http.ResponseWriter, status int, v interface{}) error
JSON renders a response with given status and JSON serialized data
func NewQuietError ¶
NewQuietError logs the error but does not show it to the user
func NewQuietWrap ¶
NewQuietWrap creates a quiet *wrapped* error that does not return a body
func NewRedirectingError ¶
NewRedirectingError creates an Error with source set to the request url and the redirect flag set to true, which will
func NewRequestError ¶
NewRequestError creates an Error with source set to the request url
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps an api.Error return object
func (*Error) GetRequest ¶
type Handle ¶
type Handle func(rw http.ResponseWriter, req *http.Request, par httprouter.Params) error
type HandleError ¶
type HandleError func(rw http.ResponseWriter, req *http.Request, err error)
type Module ¶
type Module struct { Logger *logger.Module Config *config.Module Root *http.ServeMux HTTPRouter *httprouter.Router ErrorHandler HandleError Middleware *middleware.MiddlewareServer ErrorPage func(rw http.ResponseWriter, req *http.Request, status int) // contains filtered or unexported fields }
Module router implements basic routing with helpers for protobuf-rootd responses.
func (*Module) EmptyJSON ¶
func (m *Module) EmptyJSON(rw http.ResponseWriter, status int) error
EmptyJSON renders a 200 response with JSON body `{}`
func (*Module) GetErrorCode ¶
func (*Module) Handle ¶
func (m *Module) Handle(method, path string, h http.HandlerFunc)
Handle is a shortcut for m.HTTPRouter.Handle
func (*Module) HandleError ¶
HandleError is the default API error handler
func (*Module) Subrouter ¶
func (m *Module) Subrouter(path string) *httprouter.Router
Subrouter creates a new router rooted at path
func (*Module) WrappedHandle ¶
WrappedHandle is a shortcut for m.HTTPRouter.Handle
type Params ¶
type Params = httprouter.Params