web

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParamNotFoundError = errors.New("param not found")
View Source
var UnknownError = NewApiStatus("system", "0")

Functions

func AccessLogMiddleware

func AccessLogMiddleware(next http.Handler) http.Handler

func ErrorHandlerMiddleware

func ErrorHandlerMiddleware(next http.Handler) http.Handler

func HandleBadRequest

func HandleBadRequest(err error)

func HandleHttpError

func HandleHttpError(err error)

func HandleHttpErrorWithStatusCode

func HandleHttpErrorWithStatusCode(stateCode int, err error, message string)

func HandleMethodNotAllow

func HandleMethodNotAllow(r *http.Request)

func HandleNoPermission

func HandleNoPermission(err error, message string)

func HandleNotFound

func HandleNotFound(err error, message string)

func HandleServerError

func HandleServerError(err error)

func HandleUnauthorized

func HandleUnauthorized(err error, message string)

func RegisterCRUDApi

func RegisterCRUDApi(route *Route, pathPrefix string, api CRUDApi)

func ResponseJson

func ResponseJson(response interface{}, statusCode int, w http.ResponseWriter)

func RestControllerHandler

func RestControllerHandler(handle RestFunc) http.Handler

Types

type ApiStatus

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

func NewApiStatus

func NewApiStatus(code string, module string) ApiStatus

type CRUDApi

type CRUDApi interface {
	Get(r *http.Request) (interface{}, error)
	List(r *http.Request) (interface{}, error)
	Create(r *http.Request) (interface{}, error)
	Update(r *http.Request) (interface{}, error)
	Delete(r *http.Request) (interface{}, error)
}

type HttpError

type HttpError struct {
	StatusCode int
	Message    string
}

func (*HttpError) Error

func (e *HttpError) Error() string

type MethodRoute

type MethodRoute map[string]http.Handler

func (*MethodRoute) DELETE

func (route *MethodRoute) DELETE(handler http.Handler) *MethodRoute

func (*MethodRoute) GET

func (route *MethodRoute) GET(handler http.Handler) *MethodRoute

func (*MethodRoute) Handle

func (route *MethodRoute) Handle(method string, handler http.Handler)

func (*MethodRoute) HandleFunc

func (route *MethodRoute) HandleFunc(method string, handler func(w http.ResponseWriter, r *http.Request))

func (*MethodRoute) POST

func (route *MethodRoute) POST(handler http.Handler) *MethodRoute

func (*MethodRoute) PUT

func (route *MethodRoute) PUT(handler http.Handler) *MethodRoute

func (*MethodRoute) ServeHTTP

func (route *MethodRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)

type QueryParam

type QueryParam url.Values

func (*QueryParam) Get

func (q *QueryParam) Get(key string) string

func (*QueryParam) GetBool

func (q *QueryParam) GetBool(key string) (bool, error)

func (*QueryParam) GetByte

func (q *QueryParam) GetByte(key string) (byte, error)

func (*QueryParam) GetFloat

func (q *QueryParam) GetFloat(key string) (float64, error)

func (*QueryParam) GetInt

func (q *QueryParam) GetInt(key string) (int64, error)

func (*QueryParam) GetString

func (q *QueryParam) GetString(key string) (string, error)

func (*QueryParam) GetTime

func (q *QueryParam) GetTime(key string) (*time.Time, error)

type QueryParamError

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

func (*QueryParamError) Error

func (q *QueryParamError) Error() string

func (*QueryParamError) Unwrap

func (q *QueryParamError) Unwrap() error

type RestError

type RestError struct {
	Status ApiStatus
	Msg    string
	// contains filtered or unexported fields
}

func NewRestError

func NewRestError(module string, code string, msg string, err error) *RestError

func (*RestError) Error

func (r *RestError) Error() string

func (*RestError) Unwrap

func (r *RestError) Unwrap() error

type RestFunc

type RestFunc func(r *http.Request) (interface{}, error)

type RestMethodRoute

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

func (*RestMethodRoute) DELETE

func (route *RestMethodRoute) DELETE(f RestFunc) *RestMethodRoute

func (*RestMethodRoute) GET

func (route *RestMethodRoute) GET(f RestFunc) *RestMethodRoute

func (*RestMethodRoute) Handle

func (route *RestMethodRoute) Handle(method string, f RestFunc)

func (*RestMethodRoute) POST

func (route *RestMethodRoute) POST(f RestFunc) *RestMethodRoute

func (*RestMethodRoute) PUT

func (route *RestMethodRoute) PUT(f RestFunc) *RestMethodRoute

func (*RestMethodRoute) ServeHTTP

func (route *RestMethodRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RestResponse

type RestResponse struct {
	Data   interface{} `json:"data"`
	Status string      `json:"status"`
	Msg    string      `json:"msg"`
}

type Route

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

func NewRoute

func NewRoute() *Route

func (*Route) Handle

func (route *Route) Handle(pattern string, handler http.Handler)

func (*Route) HandleFunc

func (route *Route) HandleFunc(pattern string, handler func(w http.ResponseWriter, r *http.Request))

func (*Route) MethodRoute

func (route *Route) MethodRoute(pattern string) *MethodRoute

func (*Route) RestMethodRoute

func (route *Route) RestMethodRoute(pattern string) *RestMethodRoute

func (*Route) ServeHTTP

func (route *Route) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Route) SubRoute

func (route *Route) SubRoute(pattern string) *Route

Directories

Path Synopsis
v2

Jump to

Keyboard shortcuts

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