Documentation
¶
Index ¶
- Constants
- Variables
- func CheckForJSON(r *http.Request) error
- func NewErr(code int, err error, megs ...string) *prouterError
- func ReadJSON(r *http.Request, out interface{}) error
- func SetMapCodeToStatusFunc(fn func(code int) (statusCode int))
- func SetMode(value int64)
- func SetResponseTmpl(tmpl ResponseTmpl)
- func WriteJSON(w http.ResponseWriter, code int, v interface{}) error
- type Context
- func (c *Context) Ctx() context.Context
- func (c *Context) ExecuteTemplateFS(fs embed.FS, resource string, data any) (Response, error)
- func (c *Context) Redirect(code int, location string) (Response, error)
- func (c *Context) Session() *Session
- func (c *Context) Value(key any) any
- func (c *Context) Var(key string) string
- func (c *Context) WithValue(key, val any)
- type ContextKeyType
- type ErrComponent
- type Error
- type HandleFunc
- type LogMiddleware
- type LogOption
- type Middleware
- type OptRoute
- type Prouter
- type RecoveryMiddleware
- type Response
- type ResponseErrType
- type ResponseTmpl
- type ResponseWriter
- type Ret
- type Route
- type RouteOption
- type Router
- type RouterGroup
- func (rg *RouterGroup) Any(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) DELETE(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) GET(path string, handler HandleFunc, opt ...RouteOption)
- func (rg *RouterGroup) Group(prefix string, middlewares ...HandleFunc) *RouterGroup
- func (rg *RouterGroup) HEAD(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) HandleRoute(method, path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) HandleRouter(routers ...Router)
- func (rg *RouterGroup) OPTIONS(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) PATCH(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) POST(path string, handler HandleFunc, opt ...RouteOption)
- func (rg *RouterGroup) PUT(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) Static(path, root string, opts ...RouteOption)
- func (rg *RouterGroup) StaticFS(relativePath string, fs http.FileSystem, opts ...RouteOption)
- func (rg *RouterGroup) StaticFsEmbed(path, fileRelativePath string, fsEmbed embed.FS, opts ...RouteOption)
- func (rg *RouterGroup) TRACE(path string, handler HandleFunc, opts ...RouteOption)
- func (rg *RouterGroup) Use(middlewares ...HandleFunc)
- func (rg *RouterGroup) UseMiddleware(m ...Middleware)
- type RouterOption
- type Session
- type SessionMiddleware
Constants ¶
View Source
const ( DebugMode = iota ReleaseMode )
Variables ¶
View Source
var ( SessionNotInitialized = fmt.Errorf("Session not initialized") SessionKeyNotExists = fmt.Errorf("Session key not exist") )
Functions ¶
func CheckForJSON ¶
CheckForJSON makes sure that the request's Content-Type is application/json.
func SetMapCodeToStatusFunc ¶ added in v1.1.5
func SetResponseTmpl ¶ added in v1.0.4
func SetResponseTmpl(tmpl ResponseTmpl)
Types ¶
type Context ¶ added in v1.0.9
type Context struct { context.Context Request *http.Request Writer *ResponseWriter Path string ClientIp string Method string // contains filtered or unexported fields }
func (*Context) ExecuteTemplateFS ¶ added in v1.0.10
type ContextKeyType ¶ added in v1.0.9
type ContextKeyType int
const ( ContextRequestKey ContextKeyType = iota ContextKey )
type ErrComponent ¶ added in v1.1.5
type ErrComponent string
const ( ErrProuter ErrComponent = "prouter" ErrRecovery ErrComponent = "recovery" ErrService ErrComponent = "service" ErrRepo ErrComponent = "repository" ErrLib ErrComponent = "library" )
type Error ¶ added in v1.1.5
type Error interface { error Code() int Message() string Cause() error String() string Component() ErrComponent SetComponent(c ErrComponent) Error ResponseErrType() ResponseErrType SetResponseType(r ResponseErrType) Error }
func ResourceAlreadyExists ¶ added in v1.1.5
func ResourceNotFound ¶ added in v1.1.5
type HandleFunc ¶
func BodyParser ¶ added in v1.1.7
func BodyParser[RequestT any, ResponseT any](fn func(*Context, *RequestT) (*ResponseT, error)) HandleFunc
func (HandleFunc) Handle ¶ added in v1.0.6
func (f HandleFunc) Handle(ctx *Context) (Response, error)
func (HandleFunc) Name ¶ added in v1.0.6
func (f HandleFunc) Name() string
func (HandleFunc) WrapHandler ¶
func (f HandleFunc) WrapHandler(handler handlerFunc) handlerFunc
type LogMiddleware ¶
type LogMiddleware struct {
// contains filtered or unexported fields
}
func NewLogMiddleware ¶
func NewLogMiddleware(opts ...LogOption) *LogMiddleware
func (*LogMiddleware) WrapHandler ¶
func (lm *LogMiddleware) WrapHandler(handler handlerFunc) handlerFunc
type Middleware ¶
type Middleware interface {
WrapHandler(handler handlerFunc) handlerFunc
}
type Prouter ¶
type Prouter struct { RouterGroup // contains filtered or unexported fields }
func New ¶
func New(opts ...RouterOption) *Prouter
func NewProuter ¶
func NewProuter(opts ...RouterOption) *Prouter
func (*Prouter) ServeHandler ¶
type RecoveryMiddleware ¶ added in v1.0.4
type RecoveryMiddleware struct{}
func NewRecoveryMiddleware ¶ added in v1.0.4
func NewRecoveryMiddleware() *RecoveryMiddleware
func (*RecoveryMiddleware) WrapHandler ¶ added in v1.0.4
func (m *RecoveryMiddleware) WrapHandler(handler handlerFunc) handlerFunc
type Response ¶
type Response interface { SetCode(int) Response SetData(any) Response SetMessage(string) Response GetCode() int GetMessage() string GetData() any }
func ErrorResponse ¶
func SuccessResponse ¶
type ResponseErrType ¶ added in v1.1.5
type ResponseErrType string
const ( BadRequest ResponseErrType = "BadRequest" InternalServerError ResponseErrType = "InternalServerError" Forbidden ResponseErrType = "Forbidden" NotFound ResponseErrType = "NotFound" AlreadyExists ResponseErrType = "AlreadyExists" )
type ResponseTmpl ¶ added in v1.0.4
type ResponseTmpl interface { Response }
func NewResponseTmpl ¶ added in v1.0.4
func NewResponseTmpl() ResponseTmpl
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func WrapResponseWriter ¶
func WrapResponseWriter(w http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) StatusCode ¶
func (w *ResponseWriter) StatusCode() int
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(code int)
type Ret ¶
type Ret struct { Code int `json:"code"` Data any `json:"data,omitempty"` Message string `json:"message,omitempty"` }
func (*Ret) GetMessage ¶
func (*Ret) SetMessage ¶ added in v1.0.4
type Route ¶
func NewRoute ¶
func NewRoute(method, path string, handler HandleFunc, opts ...RouteOption) Route
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
func (*RouterGroup) Any ¶
func (rg *RouterGroup) Any(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) DELETE ¶
func (rg *RouterGroup) DELETE(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) GET ¶
func (rg *RouterGroup) GET(path string, handler HandleFunc, opt ...RouteOption)
func (*RouterGroup) Group ¶
func (rg *RouterGroup) Group(prefix string, middlewares ...HandleFunc) *RouterGroup
func (*RouterGroup) HEAD ¶
func (rg *RouterGroup) HEAD(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) HandleRoute ¶
func (rg *RouterGroup) HandleRoute(method, path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) HandleRouter ¶ added in v1.1.10
func (rg *RouterGroup) HandleRouter(routers ...Router)
func (*RouterGroup) OPTIONS ¶
func (rg *RouterGroup) OPTIONS(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) PATCH ¶
func (rg *RouterGroup) PATCH(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) POST ¶
func (rg *RouterGroup) POST(path string, handler HandleFunc, opt ...RouteOption)
func (*RouterGroup) PUT ¶
func (rg *RouterGroup) PUT(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) Static ¶
func (rg *RouterGroup) Static(path, root string, opts ...RouteOption)
func (*RouterGroup) StaticFS ¶
func (rg *RouterGroup) StaticFS(relativePath string, fs http.FileSystem, opts ...RouteOption)
func (*RouterGroup) StaticFsEmbed ¶ added in v1.0.11
func (rg *RouterGroup) StaticFsEmbed(path, fileRelativePath string, fsEmbed embed.FS, opts ...RouteOption)
func (*RouterGroup) TRACE ¶
func (rg *RouterGroup) TRACE(path string, handler HandleFunc, opts ...RouteOption)
func (*RouterGroup) Use ¶ added in v1.1.3
func (rg *RouterGroup) Use(middlewares ...HandleFunc)
func (*RouterGroup) UseMiddleware ¶
func (rg *RouterGroup) UseMiddleware(m ...Middleware)
type RouterOption ¶
type RouterOption func(v *Prouter)
func WithHost ¶
func WithHost(host string) RouterOption
func WithMethodNotAllowedHandler ¶
func WithMethodNotAllowedHandler(handler http.Handler) RouterOption
func WithNotFoundHandler ¶
func WithNotFoundHandler(handler http.Handler) RouterOption
func WithScheme ¶
func WithScheme(scheme string) RouterOption
type Session ¶ added in v1.1.2
type Session struct {
// contains filtered or unexported fields
}
func SessionGet ¶ added in v1.1.2
type SessionMiddleware ¶ added in v1.0.10
type SessionMiddleware struct {
// contains filtered or unexported fields
}
func NewSessionMiddleware ¶ added in v1.0.10
func NewSessionMiddleware(key string, stores ...sessions.Store) *SessionMiddleware
func (*SessionMiddleware) WrapHandler ¶ added in v1.0.10
func (m *SessionMiddleware) WrapHandler(handler handlerFunc) handlerFunc
Source Files
¶
Click to show internal directories.
Click to hide internal directories.