types

package
v0.0.1-20260118-131225... Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesRefToUUIDRef

func BytesRefToUUIDRef(byteDataRef *[]byte) *uuid.UUID

BytesRefToUUIDRef converts a byte slice pointer to a UUID pointer.

func BytesToUUID

func BytesToUUID(byteData []byte) uuid.UUID

BytesToUUID converts a byte slice to a UUID.

func CastTo

func CastTo[T any](value any) (T, bool)

CastTo is a generic function to safely cast a value to a specific type. It returns the cast value and a boolean indicating whether the cast was successful. CastTo tries to cast or convert any value to the given type T.

func ConvertUUIDToBytes

func ConvertUUIDToBytes(uuidVal uuid.UUID) []byte

ConvertUUIDToBytes converts a UUID to a byte slice.

func ConvertUUIDToBytesRef

func ConvertUUIDToBytesRef(uuidRef *uuid.UUID) *[]byte

ConvertUUIDToBytesRef converts a UUID pointer to a byte slice pointer.

func CreateRef

func CreateRef[T any](value T) *T

CreateRef generates a pointer for any given data.

func FloatToPgClean

func FloatToPgClean(val float64, places int) pgtype.Numeric

FloatToPgClean trims decimals for integers and enforces precision

func FloatToPgFixed

func FloatToPgFixed(val float64, places int) pgtype.Numeric

FloatToPgFixed converts with exact decimal precision

func FloatToPgNumeric

func FloatToPgNumeric(val float64, opts ...DecimalOpt) pgtype.Numeric

FloatToPgNumeric converts a float64 into pgtype.Numeric using configurable precision rules

func FloatToPgWhole

func FloatToPgWhole(val float64) pgtype.Numeric

FloatToPgWhole ensures integers remain cleanly formatted

func MillisRefToTimeRef

func MillisRefToTimeRef(millisRef *int64) *time.Time

MillisRefToTimeRef converts a milliseconds pointer to a time.Time pointer.

func MillisToTime

func MillisToTime(millis int64) time.Time

MillisToTime converts milliseconds to a time.Time value.

func ParseToPgTypeInterval

func ParseToPgTypeInterval(input string) pgtype.Interval

ParseInterval converts a human-readable duration string into pgtype.Interval. Supports formats like "30s", "45 sec", "2 minutes", etc.

func ToJSONBAny

func ToJSONBAny(v any) []byte

ToJSONBAny marshals v to JSON and returns the resulting bytes suitable for JSONB storage. If v is nil or marshaling fails, it returns nil.

func ToLanguageTag

func ToLanguageTag(l LanguageTag) language.Tag

Convert LanguageTag to language.Tag

func ToPgTime

func ToPgTime(t time.Time) pgtype.Time

ToPgTime converts t to a pgtype.Time representing the number of microseconds since midnight and marks it invalid if t is the zero time.

When t is not the zero value, Microseconds is set to the total microseconds elapsed since midnight (hours, minutes, seconds, and nanoseconds converted) and Valid is true. When t is zero, Valid is false.

func ToPgType

func ToPgType[T PgType](value any, opts ...DecimalOpt) (T, error)

ToPgType converts a Go value into a specific pgtype, constrained by PgType.

func ToPgTypeBool

func ToPgTypeBool(value bool) pgtype.Bool

ToPgTypeBool converts a bool to pgtype.Bool.

func ToPgTypeDate

func ToPgTypeDate(t time.Time) pgtype.Date

ToPgTypeDate converts t to a pgtype.Date; if t is the zero time the returned Date has Valid set to false.

func ToPgTypeFloat8

func ToPgTypeFloat8(value float64) pgtype.Float8

ToPgTypeFloat8 converts a float64 to pgtype.Float8.

func ToPgTypeInt2

func ToPgTypeInt2(value int16) pgtype.Int2

ToPgTypeInt2 converts an int value to pgtype.Int2 (PostgreSQL INTEGER).

func ToPgTypeInt4

func ToPgTypeInt4(value int32) pgtype.Int4

ToPgTypeInt4 converts an int to pgtype.Int4.

func ToPgTypeInt8

func ToPgTypeInt8(value int64) pgtype.Int8

ToPgTypeInt8 converts an int value to pgtype.Int2 (PostgreSQL INTEGER).

func ToPgTypeNil

func ToPgTypeNil[T PgType]() T

ToPgTypeNil returns the zero value of the specified pgtype T, which can be used to represent a NULL/invalid value for that PostgreSQL type.

func ToPgTypeText

func ToPgTypeText(value string) pgtype.Text

ToPgTypeText converts the provided string into a pgtype.Text for PostgreSQL. It returns a Text with Valid set to false when the input is empty or contains only whitespace; otherwise it sets String to the input and Valid to true.

func ToPgTypeTimestamp

func ToPgTypeTimestamp(value time.Time) pgtype.Timestamp

ToPgTypeTimestamp converts the provided time.Time into a pgtype.Timestamp and marks the result invalid when the input is the zero time value.

func ToPgTypeTimestamptz

func ToPgTypeTimestamptz(value time.Time) pgtype.Timestamptz

ToPgTypeTimestamptz converts a time.Time to a pgtype.Timestamptz, marking the result invalid if the input is the zero time.

func ToPgTypeUUID

func ToPgTypeUUID(u uuid.UUID) pgtype.UUID

ToPgTypeUUID converts a uuid.UUID to a pgtype.UUID, treating uuid.Nil as a NULL value. If u is uuid.Nil the returned pgtype.UUID has Valid set to false; otherwise Bytes is set to u and Valid is true.

func ToUUID

func ToUUID(p pgtype.UUID) (uuid.UUID, error)

ToUUID converts a pgtype.UUID to uuid.UUID.

Types

type Action

type Action string

Action represents an action.

func (Action) String

func (a Action) String() string

String returns the string representation of the Action.

type Bool

type Bool bool

Implement EmptyCheck for common types

func (Bool) IsEmpty

func (i Bool) IsEmpty() bool

IsEmpty checks if the bool is empty

type BusinessID

type BusinessID uuid.UUID

BusinessID represents a business ID.

func (BusinessID) String

func (e BusinessID) String() string

String returns the string representation of the BusinessID.

type Byte

type Byte byte

Implement EmptyCheck for common types

func (Byte) IsEmpty

func (i Byte) IsEmpty() bool

IsEmpty checks if the byte is empty

type CodecType

type CodecType string

CodecType defines the type of encoder (e.g., JSON, XML).

func (CodecType) String

func (e CodecType) String() string

String returns the string representation of the CodecType.

func (CodecType) ToUpperCase

func (s CodecType) ToUpperCase() string

Method to convert string to uppercase

type ComponentErrorType

type ComponentErrorType string

ComponentErrorType represents the type of component error.

func (ComponentErrorType) String

func (e ComponentErrorType) String() string

String returns the string representation of the ComponentErrorType.

type ContentType

type ContentType string

ContentType defines the type for a ContentType.

func (ContentType) String

func (c ContentType) String() string

Method to convert ContentType Type to string

type CorrelationID

type CorrelationID string

CorrelationID represents a correlation ID.

func (CorrelationID) String

func (c CorrelationID) String() string

String returns the string representat ion of the CorrelationID.

type DBType

type DBType string

DBType defines the type of database (e.g., PostgreSQL, MySQL).

func (DBType) String

func (e DBType) String() string

String returns the string representation of the DBType.

type DecimalConfig

type DecimalConfig struct {
	Places       int  // default: 3
	TrimIntegers bool // omit decimals for whole numbers
	MinPlaces    int  // lower bound on precision
	MaxPlaces    int  // upper bound on precision
}

DecimalConfig defines configuration for FloatToPgNumeric

type DecimalOpt

type DecimalOpt func(*DecimalConfig)

DecimalOpt modifies DecimalConfig

func Limit

func Limit(min, max int) DecimalOpt

Limit sets the minimum and maximum precision bounds

func Prec

func Prec(n int) DecimalOpt

Prec sets the number of decimal places

func SmartTrim

func SmartTrim() DecimalOpt

SmartTrim enables whole-number trimming

type EmptyCheck

type EmptyCheck interface {
	IsEmpty() bool
}

EmptyCheck defines an interface for checking if a value is empty.

type ErrorCode

type ErrorCode string

ErrorCode represents an error code.

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the string representation of the ErrorCode.

type Field

type Field = zap.Field

Field type to represent structured log fields

type Float32

type Float32 float32

Implement EmptyCheck for common types

func (Float32) IsEmpty

func (i Float32) IsEmpty() bool

IsEmpty checks if the float is empty

type Float64

type Float64 float64

Implement EmptyCheck for common types

func (Float64) IsEmpty

func (i Float64) IsEmpty() bool

IsEmpty checks if the float is empty

type IDType

type IDType interface {
	~string | ~int64 | ~int32 | uuid.UUID
}

IDType is a composite constraint that allows only specific ID types.

type Int

type Int int

Implement EmptyCheck for common types

func (Int) IsEmpty

func (i Int) IsEmpty() bool

IsEmpty checks if the integer is empty

type Int16

type Int16 int16

Implement EmptyCheck for common types

func (Int16) IsEmpty

func (i Int16) IsEmpty() bool

IsEmpty checks if the integer is empty

type Int32

type Int32 int32

Implement EmptyCheck for common types

func (Int32) IsEmpty

func (i Int32) IsEmpty() bool

IsEmpty checks if the integer is empty

type Int64

type Int64 int64

Implement EmptyCheck for common types

func (Int64) IsEmpty

func (i Int64) IsEmpty() bool

IsEmpty checks if the integer is empty

type Int8

type Int8 int8

Implement EmptyCheck for common types

func (Int8) IsEmpty

func (i Int8) IsEmpty() bool

IsEmpty checks if the integer is empty

type Key

type Key string

key defines the type for a key.

func (Key) String

func (e Key) String() string

Method to convert Key Type to string

func (Key) ToEd25519PrivateKey

func (e Key) ToEd25519PrivateKey() ed25519.PrivateKey

Method to convert Key Type to Ed25519PrivateKey

func (Key) ToEd25519PublicKey

func (e Key) ToEd25519PublicKey() ed25519.PublicKey

Method to convert Key Type to Ed25519PublicKey

type LanguageTag

type LanguageTag language.Tag

Implement EmptyCheck for common types

func (LanguageTag) IsEmpty

func (l LanguageTag) IsEmpty() bool

IsEmpty checks if the language tag is empty

func (LanguageTag) String

func (l LanguageTag) String() string

Convert LanguageTag to string

type LogMode

type LogMode string

LogMode represents the logging mode

func (LogMode) String

func (l LogMode) String() string

String returns the string representation of the LogMode.

type Milliseconds

type Milliseconds int64

Milliseconds represents a duration in milliseconds.

func (Milliseconds) Int64

func (e Milliseconds) Int64() int64

Int64 returns the int64 representation of the Milliseconds.

type OrgID

type OrgID uuid.UUID

func ToOrgID

func ToOrgID(uuid uuid.UUID) OrgID

ToOrgID returns the OrgID representation of the uuid.

func (OrgID) MarshalJSON

func (o OrgID) MarshalJSON() ([]byte, error)

func (OrgID) String

func (e OrgID) String() string

String returns the string representation of the OrgID.

func (OrgID) UUID

func (e OrgID) UUID() uuid.UUID

UUID returns the uuid representation of the OrgID.

func (*OrgID) UnmarshalJSON

func (o *OrgID) UnmarshalJSON(data []byte) error

type PgType

PgType is a constraint that lists supported pgtype structs.

type Protocol

type Protocol string

Protocol represents a protocol.

func (Protocol) String

func (p Protocol) String() string

String returns the string representation of the Protocol.

type RequestID

type RequestID string

RequestID represents a request ID.

func (RequestID) String

func (r RequestID) String() string

String returns the string representation of the RequestID.

type ResponseErrorType

type ResponseErrorType string

ResponseErrorType represents the type of response error.

func (ResponseErrorType) String

func (e ResponseErrorType) String() string

String returns the string representation of the ResponseErrorType.

type Rune

type Rune rune

Implement EmptyCheck for common types

func (Rune) IsEmpty

func (i Rune) IsEmpty() bool

IsEmpty checks if the rune is empty

type Service

type Service string

Service represents a service.

func (Service) String

func (s Service) String() string

String returns the string representation of the Service.

type Status

type Status string

Status represents a status.

func (Status) String

func (s Status) String() string

String returns the string representation of the Status.

type String

type String string

Implement EmptyCheck for common types

func (String) IsEmpty

func (s String) IsEmpty() bool

IsEmpty checks if the string is empty or contains only whitespace

type StringConstant

type StringConstant string

StringConstant represents a constant string value.

func (StringConstant) String

func (s StringConstant) String() string

String returns the string representation of the StringConstant.

type Uint

type Uint uint

Implement EmptyCheck for common types

func (Uint) IsEmpty

func (i Uint) IsEmpty() bool

IsEmpty checks if the unsigned integer is empty

type Uint16

type Uint16 uint16

Implement EmptyCheck for common types

func (Uint16) IsEmpty

func (i Uint16) IsEmpty() bool

IsEmpty checks if the unsigned integer is empty

type Uint32

type Uint32 uint32

Implement EmptyCheck for common types

func (Uint32) IsEmpty

func (i Uint32) IsEmpty() bool

IsEmpty checks if the unsigned integer is empty

type Uint64

type Uint64 uint64

Implement EmptyCheck for common types

func (Uint64) IsEmpty

func (i Uint64) IsEmpty() bool

IsEmpty checks if the unsigned integer is empty

type Uint8

type Uint8 uint8

Implement EmptyCheck for common types

func (Uint8) IsEmpty

func (i Uint8) IsEmpty() bool

IsEmpty checks if the unsigned integer is empty

type UserID

type UserID uuid.UUID

UserID represents a user ID.

func ToUserID

func ToUserID(uuid uuid.UUID) UserID

ToUserID returns the UserID representation of the uuid.

func (UserID) MarshalJSON

func (o UserID) MarshalJSON() ([]byte, error)

func (UserID) String

func (e UserID) String() string

String returns the string representation of the UserID.

func (UserID) UUID

func (e UserID) UUID() uuid.UUID

UUID returns the underlying uuid.UUID value.

func (*UserID) UnmarshalJSON

func (o *UserID) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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