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
- func FormatTimePtr(t *time.Time) *string
- func Int64PtrToUint64(val *int64) uint64
- func Int64PtrToUint64Ptr(val *int64) *uint64
- func NowRFC3339Ptr() *string
- func ParseTimestampPtr(timestamp *string) (*time.Time, error)
- func RetryWithExponentialBackoff(ctx context.Context, config RetryConfig, fn func() error) error
- func SetupOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err error)
- func SetupOTelSDKWithConfig(ctx context.Context, cfg OTelConfig) (shutdown func(context.Context) error, err error)
- func ValidateRFC3339(timestamp string) (time.Time, error)
- func ValidateRFC3339Ptr(timestamp *string) error
- type OTelConfig
- type RetryConfig
Constants ¶
const ( // OTelProtocolGRPC configures OTLP exporters to use gRPC protocol. OTelProtocolGRPC = "grpc" // OTelProtocolHTTP configures OTLP exporters to use HTTP protocol. OTelProtocolHTTP = "http" // OTelExporterOTLP configures signals to export via OTLP. OTelExporterOTLP = "otlp" // OTelExporterNone disables exporting for a signal. OTelExporterNone = "none" // OTelPropagatorTraceContext is the W3C Trace Context propagator. OTelPropagatorTraceContext = "tracecontext" // OTelPropagatorBaggage is the W3C Baggage propagator. OTelPropagatorBaggage = "baggage" // OTelPropagatorJaeger is the Jaeger propagation format. OTelPropagatorJaeger = "jaeger" // OTelDefaultPropagators is the default comma-separated propagator list. OTelDefaultPropagators = "tracecontext,baggage,jaeger" )
Variables ¶
This section is empty.
Functions ¶
func FormatTimePtr ¶
FormatTimePtr formats a time.Time pointer as an RFC3339 string pointer. Returns nil if the input is nil.
func Int64PtrToUint64 ¶
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 ¶
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 ¶
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 SetupOTelSDK ¶ added in v0.1.10
SetupOTelSDK bootstraps the OpenTelemetry pipeline with OTLP exporters. If it does not return an error, make sure to call shutdown for proper cleanup.
func SetupOTelSDKWithConfig ¶ added in v0.1.10
func SetupOTelSDKWithConfig(ctx context.Context, cfg OTelConfig) (shutdown func(context.Context) error, err error)
SetupOTelSDKWithConfig bootstraps the OpenTelemetry pipeline with the provided configuration. If it does not return an error, make sure to call shutdown for proper cleanup.
func ValidateRFC3339 ¶
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 ¶
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 OTelConfig ¶ added in v0.1.10
type OTelConfig struct {
// ServiceName is the name of the service for resource identification.
// Env: OTEL_SERVICE_NAME (default: "lfx-v2-mailing-list-service")
ServiceName string
// ServiceVersion is the version of the service.
// Env: OTEL_SERVICE_VERSION (default: build-time version from ldflags)
ServiceVersion string
// Protocol specifies the OTLP protocol to use: "grpc" or "http".
// Env: OTEL_EXPORTER_OTLP_PROTOCOL (default: "grpc")
Protocol string
// Endpoint is the OTLP collector endpoint.
// For gRPC: typically "localhost:4317"
// For HTTP: typically "localhost:4318"
// Env: OTEL_EXPORTER_OTLP_ENDPOINT
Endpoint string
// Insecure disables TLS for the connection.
// Env: OTEL_EXPORTER_OTLP_INSECURE (set to "true" for insecure connections)
Insecure bool
// TracesExporter specifies the traces exporter: "otlp" or "none".
// Env: OTEL_TRACES_EXPORTER (default: "none")
TracesExporter string
// TracesSampler specifies the sampler to use.
// When empty, defaults to parentbased_traceidratio with ratio 1.0.
// Env: OTEL_TRACES_SAMPLER (default: "")
TracesSampler string
// TracesSamplerArg specifies the sampler argument.
// Env: OTEL_TRACES_SAMPLER_ARG (default: "")
TracesSamplerArg string
// MetricsExporter specifies the metrics exporter: "otlp" or "none".
// Env: OTEL_METRICS_EXPORTER (default: "none")
MetricsExporter string
// LogsExporter specifies the logs exporter: "otlp" or "none".
// Env: OTEL_LOGS_EXPORTER (default: "none")
LogsExporter string
// Propagators is a comma-separated list of propagator names.
// Supported values: "tracecontext", "baggage", "jaeger".
// Env: OTEL_PROPAGATORS (default: "tracecontext,baggage,jaeger")
Propagators string
}
OTelConfig holds OpenTelemetry configuration options.
func OTelConfigFromEnv ¶ added in v0.1.10
func OTelConfigFromEnv() OTelConfig
OTelConfigFromEnv creates an OTelConfig from environment variables. See OTelConfig struct fields for supported environment variables.
type RetryConfig ¶
RetryConfig holds retry configuration for operations
func NewRetryConfig ¶
func NewRetryConfig(maxAttempts int, baseDelay, maxDelay time.Duration) RetryConfig
NewRetryConfig creates a RetryConfig with specified parameters