Documentation
¶
Index ¶
- Variables
- func ApplyBasePathToMetadataKey(key, basePath string) string
- func BuildActionURL(baseURL string, basePath string, actionPath string, token string, ...) string
- func CloneRequestContext(ctx *models.RequestContext) *models.RequestContext
- func CompareStringArrays(arr1 []string, arr2 []string) bool
- func ConvertRouteMetadata(routes []models.RouteMapping) (map[string]map[string]any, error)
- func ExtractClientIP(logger models.Logger, req *http.Request, trustedHeaders []string, ...) (net.IP, error)
- func FormatDuration(d time.Duration) string
- func GenerateUUID() string
- func GetQueryBool(r *http.Request, key string, defaultValue bool) bool
- func GetQueryInt(r *http.Request, key string, defaultValue int) int
- func GetQueryParam(r *http.Request, key string, defaultValue string) string
- func InitValidator()
- func IsPathDisabled(method, path string, disabledPaths []string, basePath string) bool
- func IsPluginEnabled(config *models.Config, pluginID string) bool
- func JSONResponse(w http.ResponseWriter, status int, data any)
- func LoadPluginConfig[T any](config *models.Config, pluginID string, target *T) error
- func MarshalJSON(v any) (json.RawMessage, error)
- func MaskIP(ip string) string
- func MergeStringSlices(values ...[]string) []string
- func NormalizePath(p string) string
- func NormalizeRoutePattern(pattern string) string
- func ParseJSON(r *http.Request, dest any) error
- func ParsePluginConfig(source any, target any) error
- func PublishEventAsync(eventBus models.EventBus, logger models.Logger, event models.Event)
- func ReadStringSliceFromMetadata(metadata map[string]any, key string) []string
- func ReadStringSliceMetadata(reqCtx *models.RequestContext, key string) []string
- func ValidateStruct(s any) error
- func ValidateTrustedHeadersAndProxies(logger models.Logger, trustedHeaders []string, trustedProxies []string)
- func ValidateTrustedOrigins(trustedOrigins []string) error
- type MockLogger
Constants ¶
This section is empty.
Variables ¶
var SupportedRouteMethods = []string{ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, }
var Validate *validator.Validate
Functions ¶
func ApplyBasePathToMetadataKey ¶
ApplyBasePathToMetadataKey applies a basePath prefix to a metadata key (METHOD:path) If basePath is empty, the key is returned unchanged Example: ApplyBasePathToMetadataKey("GET:/me", "/api/auth") returns "GET:/api/auth/me"
func BuildActionURL ¶
func BuildActionURL(baseURL string, basePath string, actionPath string, token string, callbackURL *string) string
BuildActionURL centralizes URL building logic for token-based flows while preserving callback semantics.
func CloneRequestContext ¶
func CloneRequestContext(ctx *models.RequestContext) *models.RequestContext
CloneRequestContext creates a detached copy of a RequestContext for use in async operations. This is used for async hooks which execute in background goroutines without the response writer. The returned context uses context.Background() as its base, preventing goroutine leaks, and has a default 5-second timeout for async hook execution.
func CompareStringArrays ¶
func ConvertRouteMetadata ¶
ConvertRouteMetadata converts a list of RouteMapping configs into the internal route metadata map used by the router for plugin routing. Returns a map keyed by "METHOD:path" containing metadata with "plugins" and "permissions" fields. Route strings can either be METHOD:/path or just /path. Bare paths apply to all supported HTTP methods.
func ExtractClientIP ¶
func ExtractClientIP(logger models.Logger, req *http.Request, trustedHeaders []string, trustedProxies []string) (net.IP, error)
ExtractClientIP extracts the client IP address from various sources accurately
func FormatDuration ¶
FormatDuration converts a time.Duration to a human-readable string. It intelligently selects the most appropriate unit (minutes, hours, or days) and handles singular/plural forms correctly. Examples: "15 minutes", "1 hour", "24 hours", "2 days"
func GetQueryBool ¶
GetQueryBool retrieves a query parameter as a bool. Accepts "true", "1", "yes" (case insensitive) as true. Returns defaultValue if missing or invalid.
func GetQueryInt ¶
GetQueryInt retrieves a query parameter as an int. If missing or invalid, returns the provided default value.
func GetQueryParam ¶
GetQueryParam retrieves a query parameter from the request. If the parameter is missing, returns the provided default value.
func InitValidator ¶
func InitValidator()
func IsPathDisabled ¶ added in v1.3.0
IsPathDisabled reports whether a request method/path matches one of the configured disabled paths. Disabled entries support exact METHOD:/path rules and wildcard prefixes such as /organizations/*.
func IsPluginEnabled ¶
IsPluginEnabled checks if a plugin is enabled based on its metadata and configuration.
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, status int, data any)
func LoadPluginConfig ¶
LoadPluginConfig parses the configuration for a specific plugin from the main config. First checks PreParsedConfigs (for type safety when plugins are instantiated manually). Falls back to unmarshalling from Plugins map (for config file loading).
func MarshalJSON ¶
func MarshalJSON(v any) (json.RawMessage, error)
MarshalJSON marshals a value to JSON
func MaskIP ¶
MaskIP masks the last octet of an IPv4 address for GDPR compliance Example: "1.2.3.4" -> "1.2.3.x" For IPv6 or other formats, returns the original string unchanged
func MergeStringSlices ¶ added in v1.3.0
func NormalizePath ¶
func NormalizeRoutePattern ¶ added in v1.3.0
func ParsePluginConfig ¶
ParsePluginConfig is a utility function to parse plugin configuration from the generic config map. It uses mapstructure with custom decode hooks to handle: - Time duration strings (e.g., "5m", "300s") via StringToTimeDurationHookFunc - Comma-separated string slices via StringToSliceHookFunc
func PublishEventAsync ¶
PublishEventAsync publishes an event asynchronously without blocking the caller. If the event bus is nil, it safely returns without error. The event is published in a background goroutine with a timeout context. Event publishing failures are logged but do not block or return errors to the caller, treating events as telemetry rather than critical to request success.
func ReadStringSliceFromMetadata ¶ added in v1.3.0
func ReadStringSliceMetadata ¶
func ReadStringSliceMetadata(reqCtx *models.RequestContext, key string) []string
func ValidateStruct ¶
func ValidateTrustedOrigins ¶
ValidateTrustedOrigins validates that all trusted origins are well-formed URLs
Types ¶
type MockLogger ¶
type MockLogger struct {
}
func NewMockLogger ¶
func NewMockLogger() *MockLogger
func (*MockLogger) Debug ¶
func (m *MockLogger) Debug(msg string, args ...any)
func (*MockLogger) Error ¶
func (m *MockLogger) Error(msg string, args ...any)
func (*MockLogger) Info ¶
func (m *MockLogger) Info(msg string, args ...any)
func (*MockLogger) Warn ¶
func (m *MockLogger) Warn(msg string, args ...any)