Documentation ¶
Index ¶
- func SetLogLevel(level LogLevel)
- type API
- func (a *API) AddMiddleware(middlewares ...Middleware)
- func (a *API) DebugPprof()
- func (a *API) HTTPExceptionHandler(f func(httpCode int, detail string) Response)
- func (a *API) Handler() http.Handler
- func (a *API) IncludeGroup(group *APIGroup)
- func (a *API) IncludeRouter(router any, prefix string, isDocs bool, middlewares ...Middleware)
- func (a *API) Logger() Logger
- func (a *API) Run(addr ...string) (err error)
- func (a *API) RunTLS(addr, certFile, keyFile string) (err error)
- func (a *API) SetLang(lang Lang)
- func (a *API) SetLogger(log Logger)
- func (a *API) SetResponseMediaType(mediaTypes ...MediaType)
- func (a *API) Static(path, root string)
- type APIGroup
- type ApiKey
- type Context
- func (c *Context) ClientIP() string
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) FullPath() string
- func (c *Context) Get(key string) (value any, ok bool)
- func (c *Context) Logger() Logger
- func (c *Context) Next()
- func (c *Context) RemoteIP() string
- func (c *Context) Set(key string, value any)
- func (c *Context) Value(key any) any
- type HTTPBasic
- type HTTPBearer
- type Lang
- type LogLevel
- type Logger
- type MediaType
- type Middleware
- type Response
- type ResponseWriter
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetLogLevel ¶ added in v0.0.2
func SetLogLevel(level LogLevel)
Types ¶
type API ¶
type API struct { OpenAPIInfo *openapi.Info OpenAPIServers []*openapi.Server OpenAPITags []*openapi.Tag Swagger swagger.Config // contains filtered or unexported fields }
func (*API) AddMiddleware ¶
func (a *API) AddMiddleware(middlewares ...Middleware)
AddMiddleware It is a function for adding middleware
func (*API) DebugPprof ¶ added in v0.0.4
func (a *API) DebugPprof()
DebugPprof Open the system's built-in pprof
func (*API) HTTPExceptionHandler ¶
HTTPExceptionHandler It is an exception handling registration for HTTP
func (*API) IncludeGroup ¶ added in v0.0.6
IncludeGroup It is an introduction routing group
func (*API) IncludeRouter ¶
func (a *API) IncludeRouter(router any, prefix string, isDocs bool, middlewares ...Middleware)
IncludeRouter It is a function that introduces routing structures
func (*API) Run ¶
Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.
func (*API) RunTLS ¶ added in v0.0.9
RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests. It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router) Note: this method will block the calling goroutine indefinitely unless an error happens.
func (*API) SetResponseMediaType ¶
SetResponseMediaType It is a function that sets the return value type
type APIGroup ¶ added in v0.0.6
type APIGroup struct {
// contains filtered or unexported fields
}
func (*APIGroup) AddMiddleware ¶ added in v0.0.6
func (g *APIGroup) AddMiddleware(middlewares ...Middleware)
AddMiddleware It is a function for adding middleware
func (*APIGroup) IncludeGroup ¶ added in v0.0.6
IncludeGroup It is an introduction routing group
func (*APIGroup) IncludeRouter ¶ added in v0.0.6
func (g *APIGroup) IncludeRouter(router any, prefix string, isDocs bool, middlewares ...Middleware)
IncludeRouter It is a function that introduces routing structures
type Context ¶
type Context struct { Request *http.Request Writer http.ResponseWriter Values map[string]any // contains filtered or unexported fields }
func (*Context) ClientIP ¶ added in v0.0.12
ClientIP implements one best effort algorithm to return the real client IP. It is it will then try to parse the headers defined in http.Header (defaulting to [X-Forwarded-For, X-Real-Ip]). else the remote IP (coming from Request.RemoteAddr) is returned.
func (*Context) FullPath ¶ added in v0.0.11
FullPath returns a matched route full path. For not found routes returns an empty string.
func (*Context) Next ¶
func (c *Context) Next()
Next It is used in middleware, before Next is before interface request, and after Next is after interface request
func (*Context) RemoteIP ¶ added in v0.0.12
RemoteIP parses the IP from Request.RemoteAddr, normalizes and returns the IP (without the port).
type HTTPBasic ¶
type HTTPBasic interface {
HTTPBasic(username, password string)
}
HTTPBasic verification interface
type HTTPBearer ¶
type HTTPBearer interface {
HTTPBearer(token string)
}
HTTPBearer verification interface
type Lang ¶
type Lang interface { Required(field string) string Lt(field string, val float64) string Lte(field string, val float64) string Gt(field string, val float64) string Gte(field string, val float64) string MultipleOf(field string, val float64) string Max(field string, val uint64) string Min(field string, val uint64) string Unique(field string) string Regexp(field string, val string) string Enum(field string, val []any) string }
type MediaType ¶
type MediaType string
const JSON MediaType = "application/json"
const XML MediaType = "application/xml"
type Middleware ¶
type Middleware func(ctx *Context)
type Response ¶
type Response interface { GetBody() any GetContentType() string SetContentType(contentType string) Write(w http.ResponseWriter) }
type ResponseWriter ¶ added in v0.0.2
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func (*ResponseWriter) Flush ¶ added in v0.0.3
func (r *ResponseWriter) Flush()
Flush implements the http.Flusher interface.
func (*ResponseWriter) Header ¶ added in v0.0.2
func (r *ResponseWriter) Header() http.Header
func (*ResponseWriter) Hijack ¶ added in v0.0.3
func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements the http.Hijacker interface.
func (*ResponseWriter) Status ¶ added in v0.0.2
func (r *ResponseWriter) Status() int
func (*ResponseWriter) Write ¶ added in v0.0.2
func (r *ResponseWriter) Write(b []byte) (int, error)
func (*ResponseWriter) WriteHeader ¶ added in v0.0.2
func (r *ResponseWriter) WriteHeader(statusCode int)
type Router ¶
type Router struct{}
Router is used to set access routes and routing methods
Tag Description: path: Access Routing method: Access method. Multiple contents separated by ',' summary: A short summary of the API. desc: A description of the API. CommonMark syntax MAY be used for rich text representation. tags: Multiple contents separated by ','