Documentation
¶
Index ¶
- Constants
- Variables
- func ActionRoutes(config *ActionRoutesConfig) echo.MiddlewareFunc
- func AddLogSeparator(config *LoggerConfig, ip string, logChannel alog.ChannelLabel)
- func CacheControlMiddleware(cfg CacheControlConfig) echo.MiddlewareFunc
- func FlushIPStats(config *RIPXCounterConfig)
- func InitLogSeparator(config *LoggerConfig, ipLogMap IPLogChannelMap)
- func Logger() echo.MiddlewareFunc
- func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc
- func LoggerWithIPLogChannelMap(ipLogMap IPLogChannelMap) echo.MiddlewareFunc
- func NewActionRoutes(akUrls asessions.ActionKeyUrls, provisioner IActionRoutesProvisioner) echo.MiddlewareFunc
- func NewAuthenticatePermConfig(perms asessions.PermSet, provisioner IAuthenticateProvisioner) echo.MiddlewareFunc
- func RIPXCounterMiddleware(config *RIPXCounterConfig) echo.MiddlewareFunc
- func RemoveLogSeparator(config *LoggerConfig, ip string)
- func SCSLoadAndSave(sessionManager *scs.SessionManager, isOnRequireSession bool) echo.MiddlewareFunc
- func SCSLoadAndSaveWithConfig(config SessionConfig) echo.MiddlewareFunc
- type ActionRoutesConfig
- type AuthenticatePermConfig
- type CORSConfig
- type CacheControlConfig
- type IActionRoutesProvisioner
- type IAuthenticateProvisioner
- type IPExclusion
- type IPLogChannelMap
- type LoggerConfig
- type RIPXCounterConfig
- type RIPXCounterOpts
- type SerializableCORSConfig
- type SessionConfig
- type TimeRange
Constants ¶
const LOGGER_RIPXC alog.ChannelLabel = "ripxc"
Variables ¶
var DefaultLoggerConfig = LoggerConfig{ Skipper: middleware.DefaultSkipper, LogChannel: alog.LOGGER_HTTP, LogSeparator: &sync.Map{}, }
DefaultLoggerConfig is the default Logger middleware config.
var DefaultRIPXCounterConfig = RIPXCounterConfig{ Skipper: middleware.DefaultSkipper, LogChannel: LOGGER_RIPXC, IsOnExclusions: true, IsOnGeneralCounts: true, }
var DefaultSessionConfig = SessionConfig{ Skipper: middleware.DefaultSkipper, }
DefaultSessionConfig provides default settings for session management.
Functions ¶
func ActionRoutes ¶
func ActionRoutes(config *ActionRoutesConfig) echo.MiddlewareFunc
ActionRoutes returns a middleware function that handles action routing based on user session status.
func AddLogSeparator ¶
func AddLogSeparator(config *LoggerConfig, ip string, logChannel alog.ChannelLabel)
AddLogSeparator dynamically updates the LogSeparator.
func CacheControlMiddleware ¶ added in v0.9.5
func CacheControlMiddleware(cfg CacheControlConfig) echo.MiddlewareFunc
CacheControlMiddleware returns Echo middleware with precomputed headers. The default applies global middleware to disable client-side caching for all routes. This sets headers like Cache-Control, Pragma, and Expires to prevent the browser from caching pages.
✅ Use cases: - Security-sensitive apps (e.g. banking, finance) where cached pages must not be revisited - After logout to prevent the user from going back to a sensitive page via the back button - Dynamic UIs (e.g. dashboards) where stale data must never be shown - Multi-user environments where data should not persist across sessions
func FlushIPStats ¶ added in v0.9.5
func FlushIPStats(config *RIPXCounterConfig)
func InitLogSeparator ¶
func InitLogSeparator(config *LoggerConfig, ipLogMap IPLogChannelMap)
InitLogSeparator initializes LogSeparator with a given IPLogChannelMap.
func Logger ¶
func Logger() echo.MiddlewareFunc
Logger returns a middleware that logs HTTP requests using zerolog.
func LoggerWithConfig ¶
func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc
LoggerWithConfig returns a Logger middleware with config.
func LoggerWithIPLogChannelMap ¶
func LoggerWithIPLogChannelMap(ipLogMap IPLogChannelMap) echo.MiddlewareFunc
LoggerWithIPLogChannelMap returns a middleware that logs HTTP requests using zerolog.
func NewActionRoutes ¶
func NewActionRoutes(akUrls asessions.ActionKeyUrls, provisioner IActionRoutesProvisioner) echo.MiddlewareFunc
NewActionRoutes creates a new ActionRoutes middleware with the provided configuration.
func NewAuthenticatePermConfig ¶
func NewAuthenticatePermConfig(perms asessions.PermSet, provisioner IAuthenticateProvisioner) echo.MiddlewareFunc
NewAuthenticatePermConfig creates a new instance of AuthenticatePermConfig with default values.
func RIPXCounterMiddleware ¶ added in v0.9.5
func RIPXCounterMiddleware(config *RIPXCounterConfig) echo.MiddlewareFunc
func RemoveLogSeparator ¶
func RemoveLogSeparator(config *LoggerConfig, ip string)
RemoveLogSeparator dynamically removes an IP from LogSeparator.
func SCSLoadAndSave ¶
func SCSLoadAndSave(sessionManager *scs.SessionManager, isOnRequireSession bool) echo.MiddlewareFunc
SCSLoadAndSave initializes session management middleware with default configuration.
func SCSLoadAndSaveWithConfig ¶
func SCSLoadAndSaveWithConfig(config SessionConfig) echo.MiddlewareFunc
SCSLoadAndSaveWithConfig returns a middleware function that loads and saves session data.
Types ¶
type ActionRoutesConfig ¶
type ActionRoutesConfig struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// ActionKeyUrls holds the mapping from action keys to URLs.
ActionKeyUrls asessions.ActionKeyUrls
// Provisioner is the interface implementation for route provisioning.
Provisioner IActionRoutesProvisioner
}
ActionRoutesConfig holds the configuration for action routes middleware.
type AuthenticatePermConfig ¶
type AuthenticatePermConfig struct {
Skipper middleware.Skipper // Function to skip middleware.
Perms asessions.PermSet // Set of permissions required for access.
Provisioner IAuthenticateProvisioner // Interface for provisioning URLs and logging.
UrlNoLogin string // URL to redirect to when no login is detected.
UrlInvalidPerms string // URL to redirect to when permissions are invalid.
}
AuthenticatePermConfig holds the configuration for permission-based authentication middleware.
type CORSConfig ¶ added in v0.9.11
type CORSConfig struct {
// Embedded CORSConfig for direct configuration.
middleware.CORSConfig `json:"cors,omitempty"`
// Per-origin overrides (key: origin URL, value: custom CORSConfig).
PerOriginConfigs map[string]middleware.CORSConfig `json:"perOriginConfigs,omitempty"`
IsPermissive bool `json:"isPermissive"`
// contains filtered or unexported fields
}
CORSConfig holds CORS-related global config.
func NewCORSConfig ¶ added in v0.9.11
func NewCORSConfig(initialConfig *middleware.CORSConfig) (*CORSConfig, error)
NewCORSConfig creates and initializes a CORSConfig instance with optional initial config.
func (*CORSConfig) GetCustomMiddleware ¶ added in v0.9.11
func (gc *CORSConfig) GetCustomMiddleware() echo.MiddlewareFunc
GetCustomMiddleware returns a dynamic CORS middleware func for per-origin logic.
func (*CORSConfig) GetIsEnabled ¶ added in v0.9.11
func (gc *CORSConfig) GetIsEnabled() bool
GetIsEnabled returns true if the CORS config is meaningfully set.
func (*CORSConfig) MarshalJSON ¶ added in v0.9.11
func (g *CORSConfig) MarshalJSON() ([]byte, error)
MarshalJSON customizes JSON encoding for CORSConfig, omitting non-serializable fields.
func (*CORSConfig) UnmarshalJSON ¶ added in v0.9.11
func (g *CORSConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON customizes JSON decoding for CORSConfig.
type CacheControlConfig ¶ added in v0.9.5
type CacheControlConfig struct {
NoStore bool
NoCache bool
MustRevalidate bool
PragmaNoCache bool
Expires string
MaxAge int // in seconds
ETagSupport bool // If true, sets a static weak ETag header
// contains filtered or unexported fields
}
CacheControlConfig defines configurable cache headers.
func DefaultCacheControlConfig ¶ added in v0.9.5
func DefaultCacheControlConfig() CacheControlConfig
DefaultCacheControlConfig returns strict no-cache config.
func (CacheControlConfig) GetHeaders ¶ added in v0.9.5
func (cfg CacheControlConfig) GetHeaders() map[string]string
GetHeaders returns precomputed headers.
func (*CacheControlConfig) SetHeaders ¶ added in v0.9.5
func (cfg *CacheControlConfig) SetHeaders(extra ...map[string]string)
SetHeaders precomputes the headers and optionally merges additional ones. If extra has keys that match existing ones, extra overrides them.
type IActionRoutesProvisioner ¶
type IActionRoutesProvisioner interface {
MatchesWhitelistActionPath(targetPath string) bool
LogError(c echo.Context, err error)
GetUrlNotFoundActions() string
IsMaintenanceMode() bool
GetUrlMaintenance() string
}
IActionRoutesProvisioner defines the interface for route provisioners.
type IAuthenticateProvisioner ¶
type IAuthenticateProvisioner interface {
GetUrlNoLogin() string
GetUrlInvalidPerms() string
LogAuthError(c echo.Context, err error)
}
IAuthenticateProvisioner defines the interface for authentication provisioning.
type IPExclusion ¶ added in v0.9.5
type IPExclusion struct {
IP string
AlwaysExclude bool
TimeRanges []TimeRange
// contains filtered or unexported fields
}
func (*IPExclusion) GetCounter ¶ added in v0.9.5
func (ex *IPExclusion) GetCounter() int
func (*IPExclusion) IncrementCounter ¶ added in v0.9.5
func (ex *IPExclusion) IncrementCounter()
func (*IPExclusion) ResetWindow ¶ added in v0.9.5
func (ex *IPExclusion) ResetWindow()
type IPLogChannelMap ¶
type IPLogChannelMap map[string]alog.ChannelLabel
type LoggerConfig ¶
type LoggerConfig struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// Zerolog logger instance to be used for structured logging.
LogChannel alog.ChannelLabel
// Thread-safe dynamic log separation.
LogSeparator *sync.Map
// CustomTagFunc is a function to handle `${custom}` tag.
CustomTagFunc func(c echo.Context, event *zerolog.Event)
}
LoggerConfig defines the config for Logger middleware.
type RIPXCounterConfig ¶ added in v0.9.5
type RIPXCounterConfig struct {
Skipper middleware.Skipper
IsOnExclusions bool
Exclusions map[string]*IPExclusion
IsOnGeneralCounts bool
GeneralCounts map[string]int
Mutex sync.Mutex
LogChannel alog.ChannelLabel
FlushInterval int // in seconds
}
func (*RIPXCounterConfig) FlushDuration ¶ added in v0.9.5
func (cfg *RIPXCounterConfig) FlushDuration() time.Duration
type RIPXCounterOpts ¶ added in v0.9.5
type RIPXCounterOpts struct {
Enabled bool `json:"enabled"` // Enable/disable RIPX middleware
FlushInterval int `json:"flushInterval"` // Interval (in seconds) to flush counters
EnableExclusions bool `json:"enableExclusions"` // Enable time-based exclusions
EnableGeneralCounts bool `json:"enableGeneralCounts"` // Enable general per-IP counting
IPExclusions []*IPExclusion `json:"ipExclusions,omitempty"` // Full IP exclusion definition including time windows
}
RIPXCounterOpts defines user-facing configuration for the RIPX middleware. This is intended to be filled from JSON/YAML or environment variables.
func (*RIPXCounterOpts) ToConfig ¶ added in v0.9.5
func (opts *RIPXCounterOpts) ToConfig(logChannel alog.ChannelLabel) *RIPXCounterConfig
type SerializableCORSConfig ¶ added in v0.9.11
type SerializableCORSConfig struct {
AllowOrigins []string `json:"allowOrigins,omitempty"`
AllowMethods []string `json:"allowMethods,omitempty"`
AllowHeaders []string `json:"allowHeaders,omitempty"`
AllowCredentials bool `json:"allowCredentials,omitempty"`
UnsafeWildcardOriginWithAllowCredentials bool `json:"unsafeWildcardOriginWithAllowCredentials,omitempty"`
ExposeHeaders []string `json:"exposeHeaders,omitempty"`
MaxAge int `json:"maxAge,omitempty"`
}
SerializableCORSConfig is a JSON-serializable version of middleware.CORSConfig, omitting function fields.
type SessionConfig ¶
type SessionConfig struct {
Skipper middleware.Skipper // Function to skip middleware.
SessionManager *scs.SessionManager // Session manager instance from SCS.
DefaultLanguageType autils.LanguageType // Default language type for new sessions.
IsOnRequireSession bool // Flag to indicate if session creation is required.
}
SessionConfig holds the configuration for session management middleware.