types

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const DEFAULT_LOCALE = "en-US"

Variables

This section is empty.

Functions

func ValidatePhoneNumber added in v1.5.1

func ValidatePhoneNumber(s string) error

Types

type Email added in v1.5.1

type Email string

func NewEmail added in v1.5.1

func NewEmail(s string) (Email, error)

NewEmail validates and returns an Email.

func (Email) MarshalJSON added in v1.5.1

func (e Email) MarshalJSON() ([]byte, error)

func (Email) MarshalText added in v1.5.1

func (e Email) MarshalText() ([]byte, error)

func (*Email) Scan added in v1.5.1

func (e *Email) Scan(value any) error

func (Email) String added in v1.5.1

func (e Email) String() string

func (*Email) UnmarshalJSON added in v1.5.1

func (e *Email) UnmarshalJSON(b []byte) error

func (*Email) UnmarshalText added in v1.5.1

func (e *Email) UnmarshalText(text []byte) error

func (Email) Validate added in v1.5.1

func (e Email) Validate() error

Validate re-validates the value (useful after deserialization).

func (Email) Value added in v1.5.1

func (e Email) Value() (driver.Value, error)

type Language added in v1.5.1

type Language string

Language represents supported languages

const (
	English Language = "en"
	Spanish Language = "es"
)

func (Language) IsValid added in v1.5.1

func (l Language) IsValid() bool

type Locale added in v1.5.1

type Locale string

Locale is a string type with validation

func NewLocaleString added in v1.5.1

func NewLocaleString(locale string) (Locale, error)

NewLocaleString creates a validated locale string from a single BCP 47 tag ("es-MX") or a full Accept-Language header ("es-MX,es;q=0.9,en;q=0.8"). Tags are tried in the user's preference order: the first one with a supported language wins, keeping its region when it has an explicit one. Unsupported or malformed input falls back to DEFAULT_LOCALE instead of returning an error.

func (Locale) Language added in v1.5.1

func (l Locale) Language() Language

Language returns the language part of the locale

func (Locale) MarshalJSON added in v1.5.1

func (l Locale) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Locale) Region added in v1.5.1

func (l Locale) Region() string

Region returns the region part of the locale

func (Locale) String added in v1.5.1

func (l Locale) String() string

String returns the locale string

func (*Locale) UnmarshalJSON added in v1.5.1

func (l *Locale) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ModelWithCursor

type ModelWithCursor interface {
	GetCursor() string
}

type Optional added in v1.31.0

type Optional[T any] struct {
	Value T
	Set   bool
	Null  bool
}

Optional is a request body field that records whether the key was present. Absent: Set is false. null: Set and Null are true. A value: Set is true and Value holds it. Body fields only, never a parameter.

The api reflector documents Optional[T] as T's schema made nullable, through the OptionalType method.

func Null added in v1.31.0

func Null[T any]() Optional[T]

Null returns an Optional set to null.

func Some added in v1.31.0

func Some[T any](v T) Optional[T]

Some returns an Optional holding v.

func (Optional[T]) Get added in v1.31.0

func (o Optional[T]) Get() (T, bool)

Get returns Value and whether a non-null value was set.

func (Optional[T]) IsZero added in v1.31.0

func (o Optional[T]) IsZero() bool

IsZero reports whether the key was absent, so a field tagged omitzero is dropped when marshalling.

func (Optional[T]) MarshalJSON added in v1.31.0

func (o Optional[T]) MarshalJSON() ([]byte, error)

MarshalJSON writes null when the Optional is unset or null, else Value.

func (Optional[T]) OptionalType added in v1.31.0

func (Optional[T]) OptionalType() reflect.Type

OptionalType returns T. The api reflector finds Optional by this method, so this package does not depend on the api packages.

func (*Optional[T]) UnmarshalJSON added in v1.31.0

func (o *Optional[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON records the key as present: null sets Null, anything else decodes into Value. encoding/json only calls it for keys in the body, so an absent key leaves Set false. A decode error is EINVALID, like the other types in this package.

type PhoneNumber added in v1.5.1

type PhoneNumber string

func NewPhoneNumber added in v1.5.1

func NewPhoneNumber(s string) (PhoneNumber, error)

NewPhoneNumber validates and returns a PhoneNumber.

func (PhoneNumber) MarshalJSON added in v1.5.1

func (p PhoneNumber) MarshalJSON() ([]byte, error)

func (PhoneNumber) MarshalText added in v1.5.1

func (p PhoneNumber) MarshalText() ([]byte, error)

func (*PhoneNumber) Scan added in v1.5.1

func (p *PhoneNumber) Scan(value any) error

func (PhoneNumber) String added in v1.5.1

func (p PhoneNumber) String() string

func (*PhoneNumber) UnmarshalJSON added in v1.5.1

func (p *PhoneNumber) UnmarshalJSON(b []byte) error

func (*PhoneNumber) UnmarshalText added in v1.5.1

func (p *PhoneNumber) UnmarshalText(text []byte) error

func (PhoneNumber) Validate added in v1.5.1

func (p PhoneNumber) Validate() error

Validate re-validates the value (useful after deserialization).

func (PhoneNumber) Value added in v1.5.1

func (p PhoneNumber) Value() (driver.Value, error)

type UnixSeconds added in v1.5.2

type UnixSeconds int64

UnixSeconds is seconds since Unix epoch (1970-01-01T00:00:00Z)

func UnixSecondsFromRFC3339 added in v1.5.2

func UnixSecondsFromRFC3339(dateString string) (UnixSeconds, error)

UnixSecondsFromRFC3339 parses an RFC3339/RFC3339Nano string into Unix seconds

func UnixSecondsFromTime added in v1.5.2

func UnixSecondsFromTime(t time.Time) UnixSeconds

UnixSecondsFromTime converts a time.Time to Unix seconds (truncates sub-second)

func UnixSecondsNow added in v1.5.2

func UnixSecondsNow() UnixSeconds

UnixSecondsNow returns the current time in Unix seconds

func (UnixSeconds) FormatDate added in v1.5.2

func (us UnixSeconds) FormatDate() string

FormatDate returns dd/mm/yyyy

func (UnixSeconds) FormatDateInTimezone added in v1.5.2

func (us UnixSeconds) FormatDateInTimezone(tz string) (string, error)

FormatDateInTimezone returns dd/mm/yyyy rendered in the provided IANA timezone

func (UnixSeconds) IsZero added in v1.5.2

func (us UnixSeconds) IsZero() bool

IsZero reports whether us == 0

func (UnixSeconds) MarshalJSON added in v1.5.2

func (us UnixSeconds) MarshalJSON() ([]byte, error)

MarshalJSON emits a JSON number (unix seconds)

func (*UnixSeconds) Scan added in v1.5.2

func (us *UnixSeconds) Scan(v any) error

Scan implements sql.Scanner for BIGINT (and a few driver variants).

func (UnixSeconds) Time added in v1.5.2

func (us UnixSeconds) Time() time.Time

Time converts UnixSeconds back to time.Time

func (*UnixSeconds) UnmarshalJSON added in v1.5.2

func (us *UnixSeconds) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a JSON number (unix seconds)

func (UnixSeconds) Value added in v1.5.2

func (us UnixSeconds) Value() (driver.Value, error)

Value implements driver.Valuer for BIGINT storage.

Jump to

Keyboard shortcuts

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