Documentation
¶
Index ¶
- func Contains[T comparable](slice []T, element T) bool
- func ConvertToSeconds(timeStr string, opts ...Option) (uint64, error)
- func EnumSliceToStringSlice[T ~string](inputSlice []T) []string
- func Ptr[T any](v T) *T
- type CalculationError
- type CalculationErrorType
- type DurationConverter
- type Option
- type ValidationError
- func NewAboveMaximumError(value, maximum uint64) *ValidationError
- func NewBelowMinimumError(value, minimum uint64) *ValidationError
- func NewInvalidFormatError(input, reason string) *ValidationError
- func NewInvalidUnitError(unit string, validUnits []string) *ValidationError
- func NewInvalidValueError(input, reason string) *ValidationError
- func NewValidationError(errorType ValidationErrorType, input, reason string, context map[string]any) *ValidationError
- type ValidationErrorType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](slice []T, element T) bool
func ConvertToSeconds ¶ added in v0.18.0
ConvertToSeconds converts a time string in the form of <value><unit> (e.g., "30m", "1h") into a total number of seconds as a uint64.
The function uses a default set of units:
- "s": seconds
- "m": minutes
- "h": hours
- "d": days (24 hours)
- "M": months (calendar-aware)
Optional configurations can be provided using the Option type, such as setting minimum/maximum second boundaries (WithMinSeconds, WithMaxSeconds) or providing a custom set of units (WithUnits).
It returns an error if the format is invalid, the unit is unsupported, or if the calculated value violates any provided boundaries.
func EnumSliceToStringSlice ¶ added in v0.19.0
EnumSliceToStringSlice is a generic function to convert a slice of any type T that has the underlying type 'string' to a slice of string. The constraint ~string allows T to be any type whose underlying type is string (like the enum types from the generated STACKIT SDK modules).
Types ¶
type CalculationError ¶ added in v0.18.0
type CalculationError struct {
Type CalculationErrorType // The specific type of calculation error
Value uint64 // The value that caused the error
Reason string // Human-readable reason
Context map[string]any // Additional context (multiplier, operation, etc.)
}
CalculationError represents errors that occur during duration calculations.
func NewCalculationError ¶ added in v0.18.0
func NewCalculationError(errorType CalculationErrorType, value uint64, reason string, context map[string]any) *CalculationError
NewCalculationError creates a new CalculationError with the specified type and details.
func (*CalculationError) Error ¶ added in v0.18.0
func (e *CalculationError) Error() string
func (*CalculationError) Is ¶ added in v0.18.0
func (e *CalculationError) Is(target error) bool
Is implements error matching for errors.Is()
type CalculationErrorType ¶ added in v0.18.0
type CalculationErrorType string
const ( CalculationErrorOutOfBounds CalculationErrorType = "out_of_bounds" CalculationErrorNegativeResult CalculationErrorType = "negative_result" CalculationErrorNegativeMultiplier CalculationErrorType = "negative_multiplier" )
type DurationConverter ¶ added in v0.18.0
type DurationConverter interface {
// ToDuration converts a numeric value into a time.Duration.
//
// The function takes the following parameters:
// - value: The numeric value to convert (e.g., 30 for 30 days).
// - now: The reference time for calendar-based calculations. It can be
// ignored by implementations that are not calendar-dependent.
//
// It returns the calculated time.Duration and a nil error on success. On
// failure, it returns an error, for example if the value is too large to
// be processed.
ToDuration(value