datatypex

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 11 Imported by: 2

README

datatypes

codecov Go Report Card Go Reference

Documentation

Index

Examples

Constants

View Source
const AddressSchemeName = "asset"
View Source
const DefaultTimestampLayout = "2006-01-02T15:04:05.000Z07"

DefaultTimestampLayout default timestamp layout with millisecond precision and time zone

View Source
const MaskedPassword = "--------"

Variables

View Source
var (
	UTC = time.UTC
	CST = time.FixedZone("CST", 8*60*60) // CST Asian/China
	JST = time.FixedZone("JST", 9*60*60) // JST Asian/Japan
	SGT = time.FixedZone("SGT", 8*60*60) // SGT Asian/Singapore
)

standard time zones

View Source
var (
	TimestampZero     = Timestamp{time.Time{}}
	TimestampUnixZero = Timestamp{time.Unix(0, 0)}
)
View Source
var (
	TypeDefaultSetter    = reflect.TypeFor[DefaultSetter]()
	TypeZeroChecker      = reflect.TypeFor[ZeroChecker]()
	TypeStringer         = reflect.TypeFor[Stringer]()
	TypeSecurityStringer = reflect.TypeFor[SecurityStringer]()
)

Functions

func SetDefaultTimeZone added in v0.1.0

func SetDefaultTimeZone(tz *time.Location)

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

func NewAddress

func NewAddress(group, filename string) *Address

func ParseAddress

func ParseAddress(text string) (*Address, error)

func (Address) DBType added in v0.1.0

func (a Address) DBType(driver string) string

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

func (*Address) Scan

func (a *Address) Scan(src any) error

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

func (Address) Value

func (a Address) Value() (driver.Value, error)

type Binary

type Binary []byte

func (Binary) MarshalText

func (d Binary) MarshalText() ([]byte, error)

func (*Binary) UnmarshalText

func (d *Binary) UnmarshalText(data []byte) (err error)

type DefaultSetter

type DefaultSetter interface{ SetDefault() }

type Endpoint

type Endpoint struct {
	Scheme   string
	Host     string
	Port     uint16
	Base     string
	Username string
	Password Password
	Param    url.Values
}

func ParseEndpoint

func ParseEndpoint(text string) (*Endpoint, error)

func (Endpoint) Hostname

func (e Endpoint) Hostname() string

func (Endpoint) IsZero

func (e Endpoint) IsZero() bool

func (Endpoint) MarshalText

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

func (Endpoint) SecurityString

func (e Endpoint) SecurityString() string

func (Endpoint) String

func (e Endpoint) String() string

func (*Endpoint) UnmarshalText

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

type JSONArshaler added in v0.1.0

type JSONArshaler interface {
	json.Marshaler
	json.Unmarshaler
}

type Password

type Password string

func (Password) SecurityString

func (p Password) SecurityString() string

func (Password) String

func (p Password) String() string

type SFID

type SFID uint64

func (SFID) MarshalText

func (sf SFID) MarshalText() ([]byte, error)

func (SFID) String

func (sf SFID) String() string

func (*SFID) UnmarshalText

func (sf *SFID) UnmarshalText(data []byte) error

type SFIDs

type SFIDs []SFID

func NewSFIDs added in v0.1.0

func NewSFIDs(vs ...uint64) SFIDs

func (SFIDs) ToUint64

func (sfs SFIDs) ToUint64() (integers []uint64)

type SecurityStringer

type SecurityStringer interface{ SecurityString() string }

type Stringer

type Stringer interface{ String() string }

type TextArshaler added in v0.1.0

type TextArshaler interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}

type Timestamp

type Timestamp struct{ time.Time }

openapi:strfmt date-time

func Now

func Now() Timestamp

func ParseTimestamp added in v0.1.0

func ParseTimestamp(s string) (Timestamp, error)

func ParseTimestampWithLayout added in v0.1.0

func ParseTimestampWithLayout(input, layout string) (Timestamp, error)

func (Timestamp) DBType added in v0.1.0

func (Timestamp) DBType(driver string) string

func (Timestamp) IsZero

func (t Timestamp) IsZero() bool

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

func (*Timestamp) Scan

func (t *Timestamp) Scan(value any) error

func (Timestamp) String

func (t Timestamp) String() string

String time string with default timestamp layout

Example
input := "2022-10-24T07:30:00.000+08"

SetDefaultTimeZone(UTC)
ts, _ := ParseTimestamp(input)
fmt.Println("UTC:", ts.String())

SetDefaultTimeZone(CST)
ts, _ = ParseTimestamp(input)
fmt.Println("CST:", ts.String())

SetDefaultTimeZone(JST)
ts, _ = ParseTimestamp(input)
fmt.Println("JST:", ts.String())

SetDefaultTimeZone(SGT)
ts, _ = ParseTimestamp(input)
fmt.Println("SGT:", ts.String())
Output:

UTC: 2022-10-23T23:30:00.000Z
CST: 2022-10-24T07:30:00.000+08
JST: 2022-10-24T08:30:00.000+09
SGT: 2022-10-24T07:30:00.000+08

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(data []byte) error

func (Timestamp) Value

func (t Timestamp) Value() (driver.Value, error)

type UUID added in v0.0.8

type UUID struct {
	uuid.UUID
}

func NewUUID added in v0.0.8

func NewUUID() (UUID, error)

func (UUID) DBType added in v0.1.0

func (UUID) DBType(driver string) string

type ZeroChecker added in v0.1.0

type ZeroChecker interface{ IsZero() bool }

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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