Documentation
¶
Index ¶
- Constants
- func Authentication(authenticator Authenticator) func(next http.Handler) http.Handler
- func Authorization(authorizator Authorizator) func(next http.Handler) http.Handler
- func IdentityFromRequestContext(r *http.Request) any
- func NewNotFoundError() error
- func NewRouter(cfg RouterConfig) (*chi.Mux, error)
- func NewSwaggerUI(cfg *SwaggerUIConfig) (http.Handler, error)
- func RequestLogger(logger zerolog.Logger) func(http.Handler) http.Handler
- type AuthHandler
- type Authenticator
- type Authorizator
- type BaseHandler
- func (o BaseHandler) BindJSON(r *http.Request, v any) error
- func (o BaseHandler) BindJSONValidate(r *http.Request, v any) error
- func (o BaseHandler) BindQueryParams(r *http.Request, v any) error
- func (o BaseHandler) GetReqID(r *http.Request) string
- func (o BaseHandler) Json(w http.ResponseWriter, statusCode int, value any)
- func (o BaseHandler) Log(r *http.Request, format string, v ...any)
- func (o BaseHandler) URLParamInt(r *http.Request, key string) (int, error)
- func (o BaseHandler) URLParamString(r *http.Request, key string) string
- func (o BaseHandler) Validate(s any, fields ...string) error
- type DefaultHandler
- type ErrHTTP
- type IAuthService
- type IBaseHandler
- type IResourceService
- type ResourceHandler
- func (h ResourceHandler[Q, P, R]) Delete(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Get(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Patch(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Post(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Put(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Search(w http.ResponseWriter, r *http.Request)
- func (h ResourceHandler[Q, P, R]) Select(w http.ResponseWriter, r *http.Request)
- type RouterConfig
- type SwaggerUIConfig
Constants ¶
View Source
const Authenticated ctxKey = ctxKey(0)
Variables ¶
This section is empty.
Functions ¶
func Authentication ¶
func Authentication(authenticator Authenticator) func(next http.Handler) http.Handler
func Authorization ¶
func Authorization(authorizator Authorizator) func(next http.Handler) http.Handler
func NewNotFoundError ¶
func NewNotFoundError() error
func NewRouter ¶
func NewRouter(cfg RouterConfig) (*chi.Mux, error)
func NewSwaggerUI ¶
func NewSwaggerUI(cfg *SwaggerUIConfig) (http.Handler, error)
Types ¶
type AuthHandler ¶
type AuthHandler[Q, R any] struct { BaseHandler Srv IAuthService[Q, R] }
func (AuthHandler[Q, R]) Login ¶
func (h AuthHandler[Q, R]) Login(w http.ResponseWriter, r *http.Request)
Login
type Authorizator ¶
type BaseHandler ¶
BaseHandler ...
func (BaseHandler) BindJSON ¶
func (o BaseHandler) BindJSON(r *http.Request, v any) error
BindJSON ...
func (BaseHandler) BindJSONValidate ¶
func (o BaseHandler) BindJSONValidate(r *http.Request, v any) error
BindJSONValidate ...
func (BaseHandler) BindQueryParams ¶
func (o BaseHandler) BindQueryParams(r *http.Request, v any) error
BindQueryParams ...
func (BaseHandler) Json ¶
func (o BaseHandler) Json(w http.ResponseWriter, statusCode int, value any)
Json ...
func (BaseHandler) URLParamInt ¶
URLParamInt ...
func (BaseHandler) URLParamString ¶
func (o BaseHandler) URLParamString(r *http.Request, key string) string
URLParamString ...
type DefaultHandler ¶
type DefaultHandler struct {
BaseHandler
}
func (DefaultHandler) Health ¶
func (d DefaultHandler) Health(w http.ResponseWriter, r *http.Request)
func (DefaultHandler) MethodNotAllowed ¶
func (d DefaultHandler) MethodNotAllowed(w http.ResponseWriter, r *http.Request)
func (DefaultHandler) NotFound ¶
func (d DefaultHandler) NotFound(w http.ResponseWriter, r *http.Request)
type ErrHTTP ¶
type ErrHTTP struct { StatusCode int `json:"-"` Message string `json:"message,omitempty"` Errors []string `json:"errors,omitempty"` }
func NewBadRequestError ¶
func NewErrHTTPFromError ¶
func NewInternalServerError ¶
func NewValidationError ¶
type IAuthService ¶
type IBaseHandler ¶
type IBaseHandler interface { Validate(s any, fields ...string) error Log(r *http.Request, format string, v ...any) GetReqID(r *http.Request) string URLParamString(r *http.Request, key string) string URLParamInt(r *http.Request, key string) (int, error) BindJSON(r *http.Request, v any) error BindJSONValidate(r *http.Request, v any) error BindQueryParams(r *http.Request, v any) error Json(w http.ResponseWriter, statusCode int, value any) }
type IResourceService ¶
type IResourceService[Q, P, R any] interface { CreateResource(ctx context.Context, p Q) (R, error) GetResourceByID(ctx context.Context, id string) (R, error) DeleteResourceByID(ctx context.Context, id string) error SelectResources(ctx context.Context, p P) ([]R, error) SearchResources(ctx context.Context, p P) ([]R, error) }
type ResourceHandler ¶
type ResourceHandler[Q, P, R any] struct { BaseHandler Srv IResourceService[Q, P, R] }
func (ResourceHandler[Q, P, R]) Delete ¶
func (h ResourceHandler[Q, P, R]) Delete(w http.ResponseWriter, r *http.Request)
Delete
func (ResourceHandler[Q, P, R]) Get ¶
func (h ResourceHandler[Q, P, R]) Get(w http.ResponseWriter, r *http.Request)
Get GET
func (ResourceHandler[Q, P, R]) Patch ¶
func (h ResourceHandler[Q, P, R]) Patch(w http.ResponseWriter, r *http.Request)
Patch
func (ResourceHandler[Q, P, R]) Post ¶
func (h ResourceHandler[Q, P, R]) Post(w http.ResponseWriter, r *http.Request)
Post
func (ResourceHandler[Q, P, R]) Put ¶
func (h ResourceHandler[Q, P, R]) Put(w http.ResponseWriter, r *http.Request)
Put
func (ResourceHandler[Q, P, R]) Search ¶
func (h ResourceHandler[Q, P, R]) Search(w http.ResponseWriter, r *http.Request)
Search
func (ResourceHandler[Q, P, R]) Select ¶
func (h ResourceHandler[Q, P, R]) Select(w http.ResponseWriter, r *http.Request)
Select
type RouterConfig ¶
type RouterConfig struct { // The middlewares to use // set this not an empty []func(http.Handler) http.Hander{} to not // use any middleware. Otherwise it uses the defaults // (see setupDefaults) Middlewares []func(http.Handler) http.Handler // NotFoundHandler NotFoundHandler func(w http.ResponseWriter, r *http.Request) // MethodNotAllowedHandler MethodNotAllowedHandler func(w http.ResponseWriter, r *http.Request) // Log Log zerolog.Logger // SwaggerUI SwaggerUI *SwaggerUIConfig }
Click to show internal directories.
Click to hide internal directories.