Documentation
¶
Index ¶
- Variables
- func ApplyBasePathToMetadataKey(key, basePath string) string
- func ApplyFieldUpdates(q *bun.UpdateQuery, fields map[string]any) *bun.UpdateQuery
- func BuildActionURL(baseURL string, basePath string, actionPath string, token string, ...) string
- func BuildVerificationURL(baseURL string, basePath string, token string, callbackURL *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 CreateMockRequest(method string, path string, query map[string]string, body io.Reader, ...) *http.Request
- func ExtractClientIP(logger models.Logger, req *http.Request, trustedHeaders []string, ...) (net.IP, error)
- 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 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 NewMockPlugin() *mockPlugin
- func NormalizePath(p 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 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 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:/auth/me", "/api") returns "GET:/api/auth/me"
func ApplyFieldUpdates ¶
func ApplyFieldUpdates(q *bun.UpdateQuery, fields map[string]any) *bun.UpdateQuery
ApplyFieldUpdates applies map fields to a Bun UpdateQuery safely
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 BuildVerificationURL ¶
func BuildVerificationURL(baseURL string, basePath string, token string, callbackURL *string) string
BuildVerificationURL constructs the verification endpoint URL with optional callback.
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" field. Example:
Input: RouteMapping{Path: "/me", Method: "GET", Plugins: ["session.auth"]}
Output: {"GET:/me": {"plugins": ["session.auth"]}}
func CreateMockRequest ¶
func CreateMockRequest(method string, path string, query map[string]string, body io.Reader, headers map[string]string) *http.Request
createMockRequest creates a basic mock HTTP request for testing
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 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 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 NewMockPlugin ¶
func NewMockPlugin() *mockPlugin
func NormalizePath ¶
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 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)