Documentation
¶
Index ¶
- func ExtractDataFromForm[T any](c *gin.Context) result.Result[T]
- func ExtractDataFromRequestBody[T any](c *gin.Context) result.Result[T]
- func ExtractPasetoAuthTokenFromHeaders(c *gin.Context) result.Result[string]
- func ExtractRefreshTokenFromHeaders(c *gin.Context) result.Result[string]
- func FetchBoolParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[bool]
- func FetchBusinessIDFromParams(c *gin.Context) result.Result[types.BusinessID]
- func FetchBusinessIdFromHeaders(c *gin.Context) result.Result[types.BusinessID]
- func FetchCorrelationIdFromHeaders(c *gin.Context) result.Result[types.CorrelationID]
- func FetchIntParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[int64]
- func FetchPasetoBearerToken(c *gin.Context) result.Result[string]
- func FetchServiceNameFromParams(c *gin.Context) result.Result[types.Service]
- func FetchTextParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[string]
- func FetchUUIDParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[uuid.UUID]
- func FetchUserIdFromParams(c *gin.Context) result.Result[types.UserID]
- func FetchValidatedTextParam(c *gin.Context, paramName string, origin ParamOrigin, required bool, ...) result.Result[string]
- func FetchXFeatureFlagsHeader(c *gin.Context) result.Result[string]
- func FetchXLocationIdHeader(c *gin.Context) result.Result[uuid.UUID]
- func FetchXOrgIdHeader(c *gin.Context) result.Result[uuid.UUID]
- func FetchXSubjectHeader(c *gin.Context) result.Result[string]
- func FetchXUserIdHeader(c *gin.Context) result.Result[uuid.UUID]
- func FetchXUserRoleHeader(c *gin.Context) result.Result[string]
- func ParseUnixTimeFromParams(key string, mandatory bool, c *gin.Context) result.Result[types.Milliseconds]
- func RetrieveFromGinContext[T any](c *gin.Context, key string) result.Result[T]
- func RetrieveSignatureFromHeaders(c *gin.Context) result.Result[string]
- func RetrieveUserIdFromContext(c *gin.Context) result.Result[types.UserID]
- func RetrieveUserIdFromHeaders(c *gin.Context) result.Result[types.UserID]
- type ConvertibleType
- type EssentialHeaders
- type EssentialHeadersOption
- type ParamConverterFunc
- type ParamOrigin
- type ParamValidatorFunc
- type RequestAuthConfig
- type RequestAuthOption
- type RequestAuthValues
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractDataFromForm ¶
ExtractDataFromForm extracts and binds form data from the request. It supports both URL-encoded and multipart form data.
func ExtractDataFromRequestBody ¶
ExtractDataFromRequestBody extracts and unmarshals JSON data from the request body. It binds the JSON payload to the specified type T.
func ExtractPasetoAuthTokenFromHeaders ¶
ExtractPasetoAuthTokenFromHeaders extracts the PASETO authentication token from headers. PASETO tokens are used for secure authentication and authorization.
func ExtractRefreshTokenFromHeaders ¶
ExtractRefreshTokenFromHeaders extracts the refresh token from request headers. Refresh tokens are used to obtain new access tokens without re-authentication.
func FetchBoolParam ¶
func FetchBoolParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[bool]
FetchBoolParam fetches and converts a parameter to boolean. It parses string values like "true", "false", "1", "0" to boolean.
func FetchBusinessIDFromParams ¶
FetchBusinessIDFromParams fetches the business ID from route parameters. It converts the parameter to BusinessID type and validates it.
func FetchBusinessIdFromHeaders ¶
FetchBusinessIdFromHeaders fetches the business ID from request headers. It's commonly used for multi-tenant applications.
func FetchCorrelationIdFromHeaders ¶
FetchCorrelationIdFromHeaders fetches the correlation ID from request headers. FetchCorrelationIdFromHeaders retrieves the correlation ID from the request headers and returns it as a types.CorrelationID reference. If the header is missing or cannot be fetched, it returns a failure result produced by blame.CorrelationIDHeaderMissing with underlying causes.
func FetchIntParam ¶
func FetchIntParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[int64]
FetchIntParam fetches and converts a parameter to int64. It returns a Result containing the converted integer or an error if conversion fails.
func FetchPasetoBearerToken ¶
FetchPasetoBearerToken fetches and extracts the PASETO bearer token from authorization headers. It validates the Bearer token format and extracts the actual token value.
func FetchServiceNameFromParams ¶
FetchServiceNameFromParams fetches the service name from route parameters. This is used for service identification and routing.
func FetchTextParam ¶
func FetchTextParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[string]
FetchTextParam fetches and validates a string parameter. It ensures the parameter is not empty and returns a Result with the string value.
func FetchUUIDParam ¶
func FetchUUIDParam(c *gin.Context, paramName string, origin ParamOrigin, required bool) result.Result[uuid.UUID]
FetchUUIDParam fetches and converts a parameter to UUID. It parses the string value as a UUID and returns a Result with the parsed UUID.
func FetchUserIdFromParams ¶
FetchUserIdFromParams fetches the user ID from query parameters. It validates and converts the parameter to UserID type.
func FetchValidatedTextParam ¶
func FetchValidatedTextParam( c *gin.Context, paramName string, origin ParamOrigin, required bool, validator ParamValidatorFunc[string], ) result.Result[string]
FetchValidatedTextParam fetches a string parameter and applies custom validation. It combines string fetching with user-provided validation logic.
func FetchXFeatureFlagsHeader ¶
FetchXFeatureFlagsHeader fetches the X-Feature-Flags header from the request. This header contains the feature flags for the user.
func FetchXLocationIdHeader ¶
FetchXLocationIdHeader fetches the X-Location-Id header and converts it to UUID. This header contains the location identifier in UUID format.
func FetchXOrgIdHeader ¶
FetchXOrgIdHeader fetches the X-Org-Id header and converts it to UUID. This header identifies the organization in multi-tenant applications.
func FetchXSubjectHeader ¶
FetchXSubjectHeader fetches the X-Subject header from the request. This header typically contains the subject identifier for the request.
func FetchXUserIdHeader ¶
FetchXUserIdHeader fetches the X-User-Id header and converts it to UUID. This header contains the user identifier in UUID format.
func FetchXUserRoleHeader ¶
FetchXUserRoleHeader fetches the X-User-Role header from the request. This header contains the user's role information for authorization.
func ParseUnixTimeFromParams ¶
func ParseUnixTimeFromParams(key string, mandatory bool, c *gin.Context) result.Result[types.Milliseconds]
ParseUnixTimeFromParams parses a Unix timestamp from query parameters. It converts the timestamp to Milliseconds type for time handling.
func RetrieveFromGinContext ¶
RetrieveFromGinContext retrieves an arbitrary value from the gin context by key. It performs type assertion and returns a Result with the typed value.
func RetrieveSignatureFromHeaders ¶
RetrieveSignatureFromHeaders retrieves the signature from request headers. This is used for request authentication and verification.
func RetrieveUserIdFromContext ¶
RetrieveUserIdFromContext retrieves the user ID from the gin context. This is typically set by authentication middleware.
Types ¶
type ConvertibleType ¶
ConvertibleType defines the generic type constraints for parameters that can be converted. It includes integers, booleans, strings, and UUIDs.
type EssentialHeaders ¶
type EssentialHeaders struct {
OrgId types.OrgID `json:"org_id"`
UserId types.UserID `json:"user_id"`
LocationId uuid.UUID `json:"location_id"`
UserRole string `json:"user_role"`
FeatureFlags string `json:"feature_flags"`
}
func GetEssentialHeadersValues ¶
func GetEssentialHeadersValues(ctx *context.ServiceContext, options ...EssentialHeadersOption) (*EssentialHeaders, blame.Blame)
GetEssentialHeadersValues extracts essential header values from the request using the provided options.
func NewEssentialHeaders ¶
func NewEssentialHeaders() *EssentialHeaders
NewEssentialHeaders creates and returns an empty EssentialHeaders value.
type EssentialHeadersOption ¶
type EssentialHeadersOption func(*essentialHeadersConfig)
Option type
func WithFeatureFlagRequired ¶
func WithFeatureFlagRequired() EssentialHeadersOption
require X-Feature-Flags header
func WithLocationIdRequired ¶
func WithLocationIdRequired() EssentialHeadersOption
require X-Location-Id header
type ParamConverterFunc ¶
type ParamConverterFunc[T ConvertibleType] func(string) result.Result[T]
ParamConverterFunc is a function type for converting string values to type T.
type ParamOrigin ¶
type ParamOrigin int
ParamOrigin represents the source of a parameter (route, query, or header).
const ( Unknown ParamOrigin = iota RouteParam QueryParam HeaderParam )
func (ParamOrigin) String ¶
func (p ParamOrigin) String() string
String returns the string representation of ParamOrigin.
type ParamValidatorFunc ¶
type ParamValidatorFunc[T ConvertibleType] func(T) bool
ParamValidatorFunc is a function type for validating parameters of type T.
type RequestAuthConfig ¶
type RequestAuthOption ¶
type RequestAuthOption func(*RequestAuthConfig)
func WithRequireCorrelationID ¶
func WithRequireCorrelationID() RequestAuthOption
WithRequireCorrelationID marks the correlation ID header as required when fetching request auth values.
func WithRequireToken ¶
func WithRequireToken() RequestAuthOption
WithRequireToken marks the auth token as required when fetching request auth values.
func WithRequireXSubject ¶
func WithRequireXSubject() RequestAuthOption
WithRequireXSubject marks the X-Subject header as required when fetching request auth values.
type RequestAuthValues ¶
type RequestAuthValues struct {
Token string
CorrelationID types.CorrelationID
XSubject string
}
func GetRequestAuthValues ¶
func GetRequestAuthValues(ctx *context.ServiceContext, options ...RequestAuthOption) (*RequestAuthValues, blame.Blame)
GetRequestAuthValues returns the request auth values
func MustGetRequestAuthValues ¶
func MustGetRequestAuthValues(ctx *context.ServiceContext) (*RequestAuthValues, blame.Blame)
MustGetRequestAuthValues returns the request auth values or if an error occurs