request

package
v0.1.0-20260312-120723... Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractDataFromForm

func ExtractDataFromForm[T any](c *gin.Context) result.Result[T]

ExtractDataFromForm extracts and binds form data from the request. It supports both URL-encoded and multipart form data.

func ExtractDataFromRequestBody

func ExtractDataFromRequestBody[T any](c *gin.Context) result.Result[T]

ExtractDataFromRequestBody extracts and unmarshals JSON data from the request body. It binds the JSON payload to the specified type T.

func ExtractPasetoAuthTokenFromHeaders

func ExtractPasetoAuthTokenFromHeaders(c *gin.Context) result.Result[string]

ExtractPasetoAuthTokenFromHeaders extracts the PASETO authentication token from headers. PASETO tokens are used for secure authentication and authorization.

func ExtractRefreshTokenFromHeaders

func ExtractRefreshTokenFromHeaders(c *gin.Context) result.Result[string]

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

func FetchBusinessIDFromParams(c *gin.Context) result.Result[types.BusinessID]

FetchBusinessIDFromParams fetches the business ID from route parameters. It converts the parameter to BusinessID type and validates it.

func FetchBusinessIdFromHeaders

func FetchBusinessIdFromHeaders(c *gin.Context) result.Result[types.BusinessID]

FetchBusinessIdFromHeaders fetches the business ID from request headers. It's commonly used for multi-tenant applications.

func FetchCorrelationIdFromHeaders

func FetchCorrelationIdFromHeaders(c *gin.Context) result.Result[types.CorrelationID]

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

func FetchPasetoBearerToken(c *gin.Context) result.Result[string]

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

func FetchServiceNameFromParams(c *gin.Context) result.Result[types.Service]

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

func FetchUserIdFromParams(c *gin.Context) result.Result[types.UserID]

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

func FetchXFeatureFlagsHeader(c *gin.Context) result.Result[string]

FetchXFeatureFlagsHeader fetches the X-Feature-Flags header from the request. This header contains the feature flags for the user.

func FetchXLocationIdHeader

func FetchXLocationIdHeader(c *gin.Context) result.Result[uuid.UUID]

FetchXLocationIdHeader fetches the X-Location-Id header and converts it to UUID. This header contains the location identifier in UUID format.

func FetchXOrgIdHeader

func FetchXOrgIdHeader(c *gin.Context) result.Result[uuid.UUID]

FetchXOrgIdHeader fetches the X-Org-Id header and converts it to UUID. This header identifies the organization in multi-tenant applications.

func FetchXSubjectHeader

func FetchXSubjectHeader(c *gin.Context) result.Result[string]

FetchXSubjectHeader fetches the X-Subject header from the request. This header typically contains the subject identifier for the request.

func FetchXUserIdHeader

func FetchXUserIdHeader(c *gin.Context) result.Result[uuid.UUID]

FetchXUserIdHeader fetches the X-User-Id header and converts it to UUID. This header contains the user identifier in UUID format.

func FetchXUserRoleHeader

func FetchXUserRoleHeader(c *gin.Context) result.Result[string]

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

func RetrieveFromGinContext[T any](c *gin.Context, key string) result.Result[T]

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

func RetrieveSignatureFromHeaders(c *gin.Context) result.Result[string]

RetrieveSignatureFromHeaders retrieves the signature from request headers. This is used for request authentication and verification.

func RetrieveUserIdFromContext

func RetrieveUserIdFromContext(c *gin.Context) result.Result[types.UserID]

RetrieveUserIdFromContext retrieves the user ID from the gin context. This is typically set by authentication middleware.

func RetrieveUserIdFromHeaders

func RetrieveUserIdFromHeaders(c *gin.Context) result.Result[types.UserID]

RetrieveUserIdFromHeaders retrieves the user ID from request headers. It validates the header value and converts it to UserID type.

Types

type ConvertibleType

type ConvertibleType interface {
	constraints.Integer | bool | string | uuid.UUID
}

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 RequestAuthConfig struct {
	RequireToken         bool
	RequireCorrelationID bool
	RequireXSubject      bool
}

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

Jump to

Keyboard shortcuts

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