middlewares

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

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 Accounts

type Accounts map[string]string

type BasicAuthMiddleware

type BasicAuthMiddleware struct {
	*fw.MiddlewareCtl
	// contains filtered or unexported fields
}

func (*BasicAuthMiddleware) CloneAsCtl

func (b *BasicAuthMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*BasicAuthMiddleware) CloneAsMethod

func (b *BasicAuthMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*BasicAuthMiddleware) HandlerController

func (b *BasicAuthMiddleware) HandlerController(base string) []*fw.RouteItem

func (*BasicAuthMiddleware) HandlerMethod

func (b *BasicAuthMiddleware) HandlerMethod(h fw.HandlerFunc) fw.HandlerFunc

type CSRFMiddleware

type CSRFMiddleware struct {
}

type CacheControlMiddleware

type CacheControlMiddleware struct{}

type Client

type Client struct {
	ID string
	// contains filtered or unexported fields
}

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

func (c *Config) AddAllowHeaders(headers ...string)

AddAllowHeaders is allowed to add custom headers

func (*Config) AddAllowMethods

func (c *Config) AddAllowMethods(methods ...string)

AddAllowMethods is allowed to add custom methods

func (*Config) AddExposeHeaders

func (c *Config) AddExposeHeaders(headers ...string)

AddExposeHeaders is allowed to add custom expose headers

func (Config) Validate

func (c Config) Validate() error

Validate is check configuration of user defined.

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) CloneAsCtl

func (c *CorsMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*CorsMiddleware) CloneAsMethod

func (c *CorsMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*CorsMiddleware) HandlerController

func (c *CorsMiddleware) HandlerController(base string) []*fw.RouteItem

func (*CorsMiddleware) HandlerMethod

func (c *CorsMiddleware) HandlerMethod(next fw.HandlerFunc) fw.HandlerFunc

type Data

type Data[T int | string] struct {
	Code    T
	Message string
	Data    interface{}
}

type GZipMiddleware

type GZipMiddleware struct {
}

type HealthCheckMiddleware

type HealthCheckMiddleware struct {
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func (*Hub) Broadcast

func (h *Hub) Broadcast(message []byte)

func (*Hub) SendByClient

func (h *Hub) SendByClient(id string, message []byte)

type JwtMiddleware

type JwtMiddleware struct{}

type LimitMiddleware

type LimitMiddleware struct{}

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) CloneAsCtl

func (w *LogMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*LogMiddleware) CloneAsMethod

func (w *LogMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*LogMiddleware) HandlerController

func (w *LogMiddleware) HandlerController(s string) []*fw.RouteItem

func (*LogMiddleware) HandlerMethod

func (w *LogMiddleware) HandlerMethod(next fw.HandlerFunc) 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 (p *LogParams) ClientIPWithColor() string

func (*LogParams) LatencyWithColor

func (p *LogParams) LatencyWithColor() string

func (*LogParams) MethodWithColor

func (p *LogParams) MethodWithColor() string

func (*LogParams) StatusCodeWithColor

func (p *LogParams) StatusCodeWithColor() string

func (*LogParams) TimeStampWithColor

func (p *LogParams) TimeStampWithColor() string

type LoggerMiddleware

type LoggerMiddleware struct {
	*fw.MiddlewareGlobal
	Logger *logrus.Logger `inject:""`
}

func (*LoggerMiddleware) CloneAsCtl

func (w *LoggerMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*LoggerMiddleware) CloneAsMethod

func (w *LoggerMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*LoggerMiddleware) HandlerController

func (w *LoggerMiddleware) HandlerController(s string) []*fw.RouteItem

func (*LoggerMiddleware) HandlerMethod

func (w *LoggerMiddleware) HandlerMethod(next fw.HandlerFunc) fw.HandlerFunc

type PprofMiddleware

type PprofMiddleware struct {
}

type PrometheusMiddleware

type PrometheusMiddleware struct {
}

type RecoveryMiddleware

type RecoveryMiddleware struct {
	*fw.MiddlewareGlobal

	Logger *logrus.Logger `inject:""`
	// contains filtered or unexported fields
}

RecoveryMiddleware globally recover from panic

func (*RecoveryMiddleware) CloneAsCtl

func (s *RecoveryMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*RecoveryMiddleware) CloneAsMethod

func (s *RecoveryMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*RecoveryMiddleware) HandlerController

func (s *RecoveryMiddleware) HandlerController(base string) []*fw.RouteItem

func (*RecoveryMiddleware) HandlerMethod

func (s *RecoveryMiddleware) HandlerMethod(h fw.HandlerFunc) 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) CloneAsCtl

func (*ResponseRewriterMiddleware) CloneAsMethod

func (s *ResponseRewriterMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*ResponseRewriterMiddleware) HandlerController

func (s *ResponseRewriterMiddleware) HandlerController(base string) []*fw.RouteItem

func (*ResponseRewriterMiddleware) HandlerMethod

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) CloneAsCtl

func (s *ServerDownMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*ServerDownMiddleware) CloneAsMethod

func (s *ServerDownMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*ServerDownMiddleware) HandlerController

func (s *ServerDownMiddleware) HandlerController(s2 string) []*fw.RouteItem

func (*ServerDownMiddleware) HandlerMethod

func (s *ServerDownMiddleware) HandlerMethod(h fw.HandlerFunc) fw.HandlerFunc

type WebLogMiddleware

type WebLogMiddleware struct {
}

WebLogMiddleware provides a web page for tail logs

type WebsocketHubMiddleware

type WebsocketHubMiddleware struct {
	*fw.MiddlewareCtl
	// contains filtered or unexported fields
}

WebsocketHubMiddleware used for chat

func (*WebsocketHubMiddleware) CloneAsCtl

func (w *WebsocketHubMiddleware) CloneAsCtl() fw.IMiddlewareCtl

func (*WebsocketHubMiddleware) CloneAsMethod

func (w *WebsocketHubMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*WebsocketHubMiddleware) HandlerController

func (w *WebsocketHubMiddleware) HandlerController(h string) []*fw.RouteItem

func (*WebsocketHubMiddleware) HandlerMethod

func (w *WebsocketHubMiddleware) HandlerMethod(next fw.HandlerFunc) fw.HandlerFunc

type WebsocketMiddleware

type WebsocketMiddleware struct {
	*fw.MiddlewareMethod
	// contains filtered or unexported fields
}

WebsocketMiddleware used for simple websocket communication with server

func (*WebsocketMiddleware) CloneAsMethod

func (w *WebsocketMiddleware) CloneAsMethod() fw.IMiddlewareMethod

func (*WebsocketMiddleware) HandlerMethod

func (w *WebsocketMiddleware) HandlerMethod(next fw.HandlerFunc) fw.HandlerFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL