Documentation
¶
Index ¶
- Constants
- func HashRequest(request interface{}) (string, error)
- type IdempotencyRecord
- func (i *IdempotencyRecord) CanRetry() bool
- func (i *IdempotencyRecord) GetRequest(target interface{}) error
- func (i *IdempotencyRecord) GetResponse(target interface{}) error
- func (i *IdempotencyRecord) IsLocked() bool
- func (i *IdempotencyRecord) SetError(err error)
- func (i *IdempotencyRecord) SetRequest(request interface{}) error
- func (i *IdempotencyRecord) SetResponse(response interface{}, statusCode int) error
- func (i *IdempotencyRecord) TableName() string
- type RateLimitRecord
- type SlidingWindowEntry
Constants ¶
const ( IdempotencyStatusPending = "PENDING" IdempotencyStatusProcessing = "PROCESSING" IdempotencyStatusCompleted = "COMPLETED" IdempotencyStatusFailed = "FAILED" )
Status constants
const ( RateLimitByIP = "ip" RateLimitByUser = "user" RateLimitByTenant = "tenant" RateLimitByCustom = "custom" )
RateLimitType constants for different rate limiting strategies
Variables ¶
This section is empty.
Functions ¶
func HashRequest ¶
HashRequest creates a SHA256 hash of the request for comparison
Types ¶
type IdempotencyRecord ¶
type IdempotencyRecord struct {
LockedUntil time.Time `json:"locked_until,omitempty"`
CompletedAt time.Time `json:"completed_at,omitempty"`
UpdatedAt time.Time `dynamorm:"updated_at" json:"updated_at"`
CreatedAt time.Time `dynamorm:"created_at" json:"created_at"`
ExpiresAt time.Time `dynamorm:"ttl" json:"expires_at"`
Timestamp time.Time `dynamorm:"index:gsi-timestamp,pk" json:"timestamp"`
Status string `dynamorm:"index:gsi-status,pk" json:"status"`
RequestBody string `dynamorm:"json" json:"request_body"`
Response string `dynamorm:"json" json:"response"`
LockToken string `json:"lock_token,omitempty"`
RequestHash string `json:"request_hash"`
IdempotencyKey string `dynamorm:"pk" json:"idempotency_key"`
TenantID string `dynamorm:"index:gsi-tenant,pk" json:"tenant_id,omitempty"`
FunctionName string `dynamorm:"index:gsi-function,pk" json:"function_name"`
SK string `dynamorm:"sk" json:"sk" default:"IDEMPOTENCY"`
ErrorMessage string `json:"error_message,omitempty"`
StatusCode int `json:"status_code"`
RetryCount int `json:"retry_count,omitempty"`
}
IdempotencyRecord stores idempotent request data
func NewIdempotencyRecord ¶
func NewIdempotencyRecord(key string, functionName string) *IdempotencyRecord
NewIdempotencyRecord creates a new idempotency record
func (*IdempotencyRecord) CanRetry ¶
func (i *IdempotencyRecord) CanRetry() bool
CanRetry checks if the record can be retried
func (*IdempotencyRecord) GetRequest ¶
func (i *IdempotencyRecord) GetRequest(target interface{}) error
GetRequest unmarshals the stored request
func (*IdempotencyRecord) GetResponse ¶
func (i *IdempotencyRecord) GetResponse(target interface{}) error
GetResponse unmarshals the stored response
func (*IdempotencyRecord) IsLocked ¶
func (i *IdempotencyRecord) IsLocked() bool
IsLocked checks if the record is currently locked for processing
func (*IdempotencyRecord) SetError ¶
func (i *IdempotencyRecord) SetError(err error)
SetError marks the record as failed with an error message
func (*IdempotencyRecord) SetRequest ¶
func (i *IdempotencyRecord) SetRequest(request interface{}) error
SetRequest stores the request body and hash
func (*IdempotencyRecord) SetResponse ¶
func (i *IdempotencyRecord) SetResponse(response interface{}, statusCode int) error
SetResponse stores the response and marks as completed
func (*IdempotencyRecord) TableName ¶
func (i *IdempotencyRecord) TableName() string
TableName returns the DynamoDB table name from environment
type RateLimitRecord ¶
type RateLimitRecord struct {
ExpiresAt time.Time `dynamorm:"ttl" json:"expires_at"`
CreatedAt time.Time `dynamorm:"created_at" json:"created_at"`
UpdatedAt time.Time `dynamorm:"updated_at" json:"updated_at"`
Identifier string `dynamorm:"pk" json:"identifier"`
WindowTime string `dynamorm:"sk" json:"window_time"`
IPAddress string `dynamorm:"index:gsi-ip,pk" json:"ip_address,omitempty"`
UserID string `dynamorm:"index:gsi-user,pk" json:"user_id,omitempty"`
TenantID string `dynamorm:"index:gsi-tenant,pk" json:"tenant_id,omitempty"`
BucketKey string `dynamorm:"index:gsi-bucket,pk" json:"bucket_key"`
Count int `json:"count"`
}
RateLimitRecord is compatible with both DynamORM and the Limited library
func NewRateLimitRecord ¶
func NewRateLimitRecord(identifier string, window time.Time) *RateLimitRecord
NewRateLimitRecord creates a new rate limit record with defaults
func (*RateLimitRecord) IncrementCount ¶
func (r *RateLimitRecord) IncrementCount()
IncrementCount atomically increments the count
func (*RateLimitRecord) IsExpired ¶
func (r *RateLimitRecord) IsExpired() bool
IsExpired checks if the record has expired
func (*RateLimitRecord) SetIdentifierMetadata ¶
func (r *RateLimitRecord) SetIdentifierMetadata(identifierType string, value string)
SetIdentifierMetadata sets IP, UserID, and TenantID based on the identifier type
func (*RateLimitRecord) TableName ¶
func (r *RateLimitRecord) TableName() string
TableName returns the DynamoDB table name from environment
type SlidingWindowEntry ¶
type SlidingWindowEntry struct {
Timestamp time.Time `json:"timestamp"`
PK string `dynamorm:"pk" json:"-"`
SK string `dynamorm:"sk" json:"-"`
RateLimitKey string `json:"rate_limit_key"`
RequestID string `json:"request_id"`
Weight int `json:"weight,omitempty"`
ExpiresAt int64 `dynamorm:"ttl" json:"-"`
}
SlidingWindowEntry represents a single request in the sliding window
func (*SlidingWindowEntry) GetTableName ¶
func (s *SlidingWindowEntry) GetTableName() string
GetTableName returns the DynamoDB table name for this model