utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package utils provides utility functions for the mailing list service.

Package utils provides utility functions for the mailing list service.

Package utils provides utility functions for the mailing list service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTimePtr

func FormatTimePtr(t *time.Time) *string

FormatTimePtr formats a time.Time pointer as an RFC3339 string pointer. Returns nil if the input is nil.

func Int64PtrToUint64

func Int64PtrToUint64(val *int64) uint64

Int64PtrToUint64 safely converts *int64 to uint64 for API calls. Returns 0 if the pointer is nil. This is commonly used when converting domain model IDs to API parameter types.

WARNING: Negative values will wrap around to large uint64 values. This function assumes the input represents a valid ID (non-negative). If you need validation, check for negative values before calling this function.

func Int64PtrToUint64Ptr

func Int64PtrToUint64Ptr(val *int64) *uint64

Int64PtrToUint64Ptr safely converts *int64 to *uint64. Returns nil if the pointer is nil. This is used when optional pointer types need to be converted.

WARNING: Negative values will wrap around to large uint64 values. This function assumes the input represents a valid ID (non-negative). If you need validation, check for negative values before calling this function.

func NowRFC3339Ptr

func NowRFC3339Ptr() *string

NowRFC3339Ptr returns the current time as an RFC3339 formatted string pointer.

func ParseTimestampPtr

func ParseTimestampPtr(timestamp *string) (*time.Time, error)

ParseTimestampPtr safely parses a timestamp pointer into a time.Time pointer. Returns nil if the input is nil or empty, or a pointer to the parsed time. Returns an error if parsing fails.

func RetryWithExponentialBackoff

func RetryWithExponentialBackoff(ctx context.Context, config RetryConfig, fn func() error) error

RetryWithExponentialBackoff executes a function with exponential backoff retry logic The delay between retries follows the formula: baseDelay * 2^(attempt-1) The delay is capped at maxDelay to prevent excessively long waits

func ValidateRFC3339

func ValidateRFC3339(timestamp string) (time.Time, error)

ValidateRFC3339 validates that a timestamp string is in RFC3339 format. Returns the parsed time.Time and nil error if valid, or zero time and error if invalid.

func ValidateRFC3339Ptr

func ValidateRFC3339Ptr(timestamp *string) error

ValidateRFC3339Ptr validates a timestamp pointer string is in RFC3339 format. Returns nil error if the pointer is nil or contains a valid timestamp.

Types

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

RetryConfig holds retry configuration for operations

func NewRetryConfig

func NewRetryConfig(maxAttempts int, baseDelay, maxDelay time.Duration) RetryConfig

NewRetryConfig creates a RetryConfig with specified parameters

Jump to

Keyboard shortcuts

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