Documentation
¶
Index ¶
- Constants
- Variables
- func NewBasicAuthMiddleware() fw.IMiddlewareCtl
- func NewLogMiddleware(logger *logrus.Logger) fw.IMiddlewareCtl
- func NewLoggerMiddleware(logger *logrus.Logger) fw.IMiddlewareGlobal
- func NewRecoveryMiddleware(o *RecoveryOptions, logger *logrus.Logger) fw.IMiddlewareGlobal
- func NewResponseRewriteMiddleware() fw.IMiddlewareGlobal
- func NewServerDownMiddleware(key string) fw.IMiddlewareGlobal
- func NewWebsocketHubMiddleware() fw.IMiddlewareCtl
- func NewWebsocketMiddleware() fw.IMiddlewareMethod
- type Accounts
- type BasicAuthMiddleware
- type Client
- type Config
- type CorsMiddleware
- type Data
- type Hub
- type LogMiddleware
- type LogParams
- type LoggerMiddleware
- type RecoveryMiddleware
- type RecoveryOptions
- type ResponseRewriterMiddleware
- type ServerDownMiddleware
- type WebsocketHubMiddleware
- type WebsocketMiddleware
Constants ¶
View Source
const ( AuthUserKey = "user" AuthProxyUserKey = "proxy_user" )
Variables ¶
View Source
var ( DefaultSchemas = []string{ "http://", "https://", } ExtensionSchemas = []string{ "chrome-extension://", "safari-extension://", "moz-extension://", "ms-browser-extension://", } FileSchemas = []string{ "file://", } WebSocketSchemas = []string{ "ws://", "wss://", } )
Functions ¶
func NewBasicAuthMiddleware ¶
func NewBasicAuthMiddleware() fw.IMiddlewareCtl
func NewLogMiddleware ¶
func NewLogMiddleware(logger *logrus.Logger) fw.IMiddlewareCtl
func NewLoggerMiddleware ¶
func NewLoggerMiddleware(logger *logrus.Logger) fw.IMiddlewareGlobal
func NewRecoveryMiddleware ¶
func NewRecoveryMiddleware(o *RecoveryOptions, logger *logrus.Logger) fw.IMiddlewareGlobal
func NewResponseRewriteMiddleware ¶
func NewResponseRewriteMiddleware() fw.IMiddlewareGlobal
func NewServerDownMiddleware ¶
func NewServerDownMiddleware(key string) fw.IMiddlewareGlobal
func NewWebsocketHubMiddleware ¶
func NewWebsocketHubMiddleware() fw.IMiddlewareCtl
func NewWebsocketMiddleware ¶
func NewWebsocketMiddleware() fw.IMiddlewareMethod
Types ¶
type BasicAuthMiddleware ¶
type BasicAuthMiddleware struct {
*fw.MiddlewareCtl
// contains filtered or unexported fields
}
func (*BasicAuthMiddleware) Execute ¶ added in v0.3.0
func (b *BasicAuthMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
type Config ¶
type Config struct {
AllowAllOrigins bool
// AllowOrigins is a list of origins a cross-domain request can be executed from.
// If the special "*" value is present in the list, all origins will be allowed.
// Default value is []
AllowOrigins []string
// AllowOriginFunc is a custom function to validate the origin. It takes the origin
// as an argument and returns true if allowed or false otherwise. If this option is
// set, the content of AllowOrigins is ignored.
AllowOriginFunc func(origin string) bool
// Same as AllowOriginFunc except also receives the full request context.
// This function should use the context as a read only source and not
// have any side effects on the request, such as aborting or injecting
// values on the request.
AllowOriginWithContextFunc func(c *fw.Context, origin string) bool
// AllowMethods is a list of methods the client is allowed to use with
// cross-domain requests. Default value is simple methods (GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS)
AllowMethods []string
// AllowPrivateNetwork indicates whether the response should include allow private network header
AllowPrivateNetwork bool
// AllowHeaders is list of non simple headers the client is allowed to use with
// cross-domain requests.
AllowHeaders []string
// AllowCredentials indicates whether the request can include user credentials like
// cookies, HTTP authentication or client side SSL certificates.
AllowCredentials bool
// ExposeHeaders indicates which headers are safe to expose to the API of a CORS
// API specification
ExposeHeaders []string
// MaxAge indicates how long (with second-precision) the results of a preflight request
// can be cached
MaxAge time.Duration
// Allows to add origins like http://some-domain/*, https://api.* or http://some.*.subdomain.com
AllowWildcard bool
// Allows usage of popular browser extensions schemas
AllowBrowserExtensions bool
// Allows to add custom schema like tauri://
CustomSchemas []string
// Allows usage of WebSocket protocol
AllowWebSockets bool
// Allows usage of file:// schema (dangerous!) use it only when you 100% sure it's needed
AllowFiles bool
// Allows to pass custom OPTIONS response status code for old browsers / clients
OptionsResponseStatusCode int
}
Config represents all available options for the middleware.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a generic default configuration mapped to localhost.
func (*Config) AddAllowHeaders ¶
AddAllowHeaders is allowed to add custom headers
func (*Config) AddAllowMethods ¶
AddAllowMethods is allowed to add custom methods
func (*Config) AddExposeHeaders ¶
AddExposeHeaders is allowed to add custom expose headers
type CorsMiddleware ¶
type CorsMiddleware struct {
*fw.MiddlewareGlobal
// contains filtered or unexported fields
}
func NewCorsMiddleware ¶
func NewCorsMiddleware(config Config) *CorsMiddleware
func NewDefaultCorsMiddleware ¶
func NewDefaultCorsMiddleware() *CorsMiddleware
func (*CorsMiddleware) Execute ¶ added in v0.3.0
func (c *CorsMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
func (*CorsMiddleware) Router ¶ added in v0.3.0
func (c *CorsMiddleware) Router(ctx *fw.MiddlewareContext) []*fw.RouteItem
type LogMiddleware ¶
type LogMiddleware struct {
*fw.MiddlewareCtl
Logger *logrus.Logger `inject:""`
// contains filtered or unexported fields
}
LogMiddleware for logging request info. can be used on Controller or Method
func (*LogMiddleware) Execute ¶ added in v0.3.0
func (w *LogMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
type LogParams ¶
type LogParams struct {
// TimeStamp shows the time after the server returns a response.
TimeStamp time.Time
// StatusCode is HTTP response code.
StatusCode int
// Latency is how much time the server cost to process a certain request.
Latency time.Duration
// ClientIP equals Context's ClientIP method.
ClientIP string
// Method is the HTTP method given to the request.
Method string
// Path is a path the client requests.
Path string
// ErrorMessage is set if error has occurred in processing the request.
ErrorMessage string
// BodySize is the size of the Response Body
BodySize int
// Keys are the keys set on the request's context.
Keys map[string]any
}
func (*LogParams) ClientIPWithColor ¶
func (*LogParams) LatencyWithColor ¶
func (*LogParams) MethodWithColor ¶
func (*LogParams) StatusCodeWithColor ¶
func (*LogParams) TimeStampWithColor ¶
type LoggerMiddleware ¶
type LoggerMiddleware struct {
*fw.MiddlewareGlobal
Logger *logrus.Logger `inject:""`
}
func (*LoggerMiddleware) Execute ¶ added in v0.3.0
func (w *LoggerMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
type RecoveryMiddleware ¶
type RecoveryMiddleware struct {
*fw.MiddlewareGlobal
Logger *logrus.Logger `inject:""`
// contains filtered or unexported fields
}
RecoveryMiddleware globally recover from panic
func (*RecoveryMiddleware) Execute ¶ added in v0.3.0
func (s *RecoveryMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
type RecoveryOptions ¶
type RecoveryOptions struct {
// if true, panic info and request info will show as web page
// else output json to response
// won't output stack trace to response unless the environment FW_DEBUG=true
NiceWeb bool
// whether output to console
// won't output stack trace to console unless the environment FW_DEBUG=true
Console bool
}
type ResponseRewriterMiddleware ¶
type ResponseRewriterMiddleware struct {
*fw.MiddlewareGlobal
}
func (*ResponseRewriterMiddleware) Execute ¶ added in v0.3.0
func (s *ResponseRewriterMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
type ServerDownMiddleware ¶
type ServerDownMiddleware struct {
*fw.MiddlewareGlobal
// contains filtered or unexported fields
}
ServerDownMiddleware is a middleware which provides an api to mark server down.
func (*ServerDownMiddleware) Execute ¶ added in v0.3.0
func (s *ServerDownMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
func (*ServerDownMiddleware) Router ¶ added in v0.3.0
func (s *ServerDownMiddleware) Router(ctx *fw.MiddlewareContext) []*fw.RouteItem
type WebsocketHubMiddleware ¶
type WebsocketHubMiddleware struct {
*fw.MiddlewareCtl
// contains filtered or unexported fields
}
WebsocketHubMiddleware used for chat
func (*WebsocketHubMiddleware) Execute ¶ added in v0.3.0
func (w *WebsocketHubMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
func (*WebsocketHubMiddleware) Router ¶ added in v0.3.0
func (w *WebsocketHubMiddleware) Router(ctx *fw.MiddlewareContext) []*fw.RouteItem
type WebsocketMiddleware ¶
type WebsocketMiddleware struct {
*fw.MiddlewareMethod
// contains filtered or unexported fields
}
WebsocketMiddleware used for simple websocket communication with server
func (*WebsocketMiddleware) Execute ¶ added in v0.3.0
func (w *WebsocketMiddleware) Execute(ctx *fw.MiddlewareContext) fw.HandlerFunc
Click to show internal directories.
Click to hide internal directories.