Documentation
¶
Index ¶
- Variables
- func ParseCommentXml(v any) (rs string)
- 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) IncludeChildAPI(child *ChildAPI)
- 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) SetStructTagVariableMapping(m map[string]string)
- func (a *API) Static(path, root string)
- type APIGroup
- type ApiKey
- type ChildAPI
- 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 HTTPBearerJWT
- type JWT
- func (j *JWT) Encrypt(bearerJWT HTTPBearerJWT) (string, error)
- func (j *JWT) GetAudience() (jwt.ClaimStrings, error)
- func (j *JWT) GetExpirationTime() (*jwt.NumericDate, error)
- func (j *JWT) GetIssuedAt() (*jwt.NumericDate, error)
- func (j *JWT) GetIssuer() (string, error)
- func (j *JWT) GetNotBefore() (*jwt.NumericDate, error)
- func (j *JWT) GetSubject() (string, error)
- func (j *JWT) MarshalJSON() ([]byte, error)
- type Lang
- type LogLevel
- type Logger
- type MediaType
- type Middleware
- type Response
- type ResponseWriter
- type Router
- type SecurityDescription
- type SigningMethod
- type SigningMethodECDSA
- type SigningMethodEd25519
- type SigningMethodHMAC
- type SigningMethodRSA
Constants ¶
This section is empty.
Variables ¶
var ( // hmac SigningMethodHS256 *SigningMethodHMAC = jwt.SigningMethodHS256 SigningMethodHS384 *SigningMethodHMAC = jwt.SigningMethodHS384 SigningMethodHS512 *SigningMethodHMAC = jwt.SigningMethodHS512 // rsa SigningMethodRS256 *SigningMethodRSA = jwt.SigningMethodRS256 SigningMethodRS384 *SigningMethodRSA = jwt.SigningMethodRS384 SigningMethodRS512 *SigningMethodRSA = jwt.SigningMethodRS512 // ecdsa SigningMethodES256 *SigningMethodECDSA = jwt.SigningMethodES256 SigningMethodES384 *SigningMethodECDSA = jwt.SigningMethodES384 SigningMethodES512 *SigningMethodECDSA = jwt.SigningMethodES512 // ed25519 SigningMethodEdDSA *SigningMethodEd25519 = jwt.SigningMethodEdDSA )
Functions ¶
func ParseCommentXml ¶ added in v0.1.9
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) IncludeChildAPI ¶ added in v0.1.2
IncludeChildAPI It is an introduction routing children
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
func (*API) SetStructTagVariableMapping ¶ added in v0.1.5
SetStructTagVariableMapping It is set struct tag variable mapping Only supports the replacement of tags 'summary' and 'desc' example:
mapping: username: test password: 123456 tag value: username is {{username}} and password is {{password}} result value: username is test and password is 123456
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 ChildAPI ¶ added in v0.1.2
type ChildAPI struct { OpenAPIInfo *openapi.Info OpenAPIServers []*openapi.Server OpenAPITags []*openapi.Tag // contains filtered or unexported fields }
func NewChildAPI ¶ added in v0.1.2
NewChildAPI It is a newly created ChildAPI function
func (*ChildAPI) AddMiddleware ¶ added in v0.1.2
func (c *ChildAPI) AddMiddleware(middlewares ...Middleware)
AddMiddleware It is a function for adding middleware
func (*ChildAPI) IncludeGroup ¶ added in v0.1.2
IncludeGroup It is an introduction routing group
func (*ChildAPI) IncludeRouter ¶ added in v0.1.2
func (c *ChildAPI) 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 HTTPBearerJWT ¶ added in v0.1.2
type HTTPBearerJWT interface { // EncryptKey the encrypted key EncryptKey() (any, error) // DecryptKey the Decryption key DecryptKey() (any, error) // SigningMethod encryption and decryption methods SigningMethod() SigningMethod // HTTPBearerJWT jwt logical HTTPBearerJWT(jwt *JWT) }
HTTPBearerJWT verification interface
type JWT ¶ added in v0.1.2
type JWT struct { // the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1 Issuer string `json:"iss"` // the `sub` (Subject) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 Subject string `json:"sub"` // the `aud` (Audience) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3 Audience []string `json:"aud"` // the `exp` (Expiration Time) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 ExpiresAt time.Time `json:"exp"` // the `nbf` (Not Before) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5 NotBefore time.Time `json:"nbf"` // the `iat` (Issued At) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6 IssuedAt time.Time `json:"iat"` // the `jti` (JWT ID) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7 ID string `json:"jti"` Extensions map[string]any `json:"ext"` }
func (*JWT) Encrypt ¶ added in v0.1.2
func (j *JWT) Encrypt(bearerJWT HTTPBearerJWT) (string, error)
Encrypt Get Jwt encrypted string
func (*JWT) GetAudience ¶ added in v0.1.2
func (*JWT) GetExpirationTime ¶ added in v0.1.2
func (*JWT) GetIssuedAt ¶ added in v0.1.2
func (*JWT) GetNotBefore ¶ added in v0.1.2
func (*JWT) GetSubject ¶ added in v0.1.2
func (*JWT) MarshalJSON ¶ added in v0.1.2
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 JwtTranslate(msg string) 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 ','
type SecurityDescription ¶ added in v0.1.8
type SecurityDescription interface {
Desc() string
}
type SigningMethod ¶ added in v0.1.2
type SigningMethod = jwt.SigningMethod
type SigningMethodECDSA ¶ added in v0.1.2
type SigningMethodECDSA = jwt.SigningMethodECDSA
type SigningMethodEd25519 ¶ added in v0.1.2
type SigningMethodEd25519 = jwt.SigningMethodEd25519
type SigningMethodHMAC ¶ added in v0.1.2
type SigningMethodHMAC = jwt.SigningMethodHMAC
type SigningMethodRSA ¶ added in v0.1.2
type SigningMethodRSA = jwt.SigningMethodRSA