router

package
v0.0.0-...-1a3755f Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleSQLError

func HandleSQLError(err error) error

func Recoverer

func Recoverer(w http.ResponseWriter, r *http.Request) (context.Context, error)

====================================== Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recoverer prints a request ID if one is provided. ======================================

func SendJSON

func SendJSON(w http.ResponseWriter, status int, obj interface{}) error

Types

type HTTPError

type HTTPError struct {
	Object          string      `json:"object"`
	Code            int         `json:"code"`
	Message         string      `json:"msg"`
	Json            interface{} `json:"json"`
	InternalError   error       `json:"-"`
	InternalMessage string      `json:"-"`
	ErrorID         string      `json:"error_id,omitempty"`
}

HTTPError is an error with a message and an HTTP status code.

func BadRequestError

func BadRequestError(fmtString string, args ...interface{}) *HTTPError

====================================== Return bad request error ======================================

func InternalServerError

func InternalServerError(fmtString string, args ...interface{}) *HTTPError

====================================== Return internal server error ======================================

func NotFoundError

func NotFoundError(fmtString string, args ...interface{}) *HTTPError

====================================== Return not found error ======================================

func UnauthorizedError

func UnauthorizedError(fmtString string, args ...interface{}) *HTTPError

====================================== Return unauthorized error ======================================

func UnavailableServiceError

func UnavailableServiceError(fmtString string, args ...interface{}) *HTTPError

====================================== Return unavailable service error ======================================

func (*HTTPError) Cause

func (e *HTTPError) Cause() error

====================================== Cause returns the root cause error ======================================

func (*HTTPError) Error

func (e *HTTPError) Error() string

====================================== Return error as string ======================================

func (*HTTPError) WithInternalError

func (e *HTTPError) WithInternalError(err error) *HTTPError

====================================== WithInternalError adds internal error information to the error ======================================

func (*HTTPError) WithInternalMessage

func (e *HTTPError) WithInternalMessage(fmtString string, args ...interface{}) *HTTPError

====================================== WithInternalMessage adds internal message information to the error ======================================

func (*HTTPError) WithJsonError

func (e *HTTPError) WithJsonError(json interface{}) *HTTPError

====================================== WithJsonError ======================================

type Router

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

====================================== Router wrapper ======================================

func NewRouter

func NewRouter() *Router

====================================== Create new Router ======================================

func (*Router) Delete

func (r *Router) Delete(pattern string, fn apiHandler)

func (*Router) Get

func (r *Router) Get(pattern string, fn apiHandler)

func (*Router) Post

func (r *Router) Post(pattern string, fn apiHandler)

func (*Router) Put

func (r *Router) Put(pattern string, fn apiHandler)

func (*Router) Route

func (r *Router) Route(pattern string, fn func(*Router))

====================================== Default methods ======================================

func (*Router) ServeHTTP

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

====================================== Serve ======================================

func (*Router) Use

func (r *Router) Use(fn middlewareHandler)

func (*Router) UseBypass

func (r *Router) UseBypass(fn func(next http.Handler) http.Handler)

func (*Router) With

func (r *Router) With(fn middlewareHandler) *Router

====================================== Use custom middleware ======================================

func (*Router) WithBypass

func (r *Router) WithBypass(fn func(next http.Handler) http.Handler) *Router

Jump to

Keyboard shortcuts

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