datatypex

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 13 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 Init added in v0.1.0

func Init(initializer any) error

func InitByContext added in v0.1.0

func InitByContext(ctx context.Context, initializer any) error

func NewErrParseAddressByURL added in v0.1.0

func NewErrParseAddressByURL(input string, cause error) error

func NewErrParseEndpointByURL added in v0.1.0

func NewErrParseEndpointByURL(input string, cause error) error

func NewErrTimestampScanBytes added in v0.1.0

func NewErrTimestampScanBytes(input []byte) error

func NewErrTimestampScanInvalidInput added in v0.1.0

func NewErrTimestampScanInvalidInput(got any) error

func NewErrUnmarshalSFID added in v0.1.0

func NewErrUnmarshalSFID(input []byte, cause error) error

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(engine DBEngineType) 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 DBEngineType added in v0.1.0

type DBEngineType string

DBEngineType identifies rdb engine type, usually it is `postgres`, `mysql`, `sqlite` or `sqlite3`, etc.

type DBValue added in v0.1.0

type DBValue interface {
	driver.Valuer
	sql.Scanner
	DBType(engine DBEngineType) string
}

DBValue can convert between rdb value and go value with description of rdb datatype

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 ErrParseAddressByURL added in v0.1.0

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

func (*ErrParseAddressByURL) Error added in v0.1.0

func (e *ErrParseAddressByURL) Error() string

func (*ErrParseAddressByURL) Unwrap added in v0.1.0

func (e *ErrParseAddressByURL) Unwrap() error

type ErrParseEndpointByURL added in v0.1.0

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

func (*ErrParseEndpointByURL) Error added in v0.1.0

func (e *ErrParseEndpointByURL) Error() string

func (*ErrParseEndpointByURL) Unwrap added in v0.1.0

func (e *ErrParseEndpointByURL) Unwrap() error

type ErrTimestampScanBytes added in v0.1.0

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

func (*ErrTimestampScanBytes) Error added in v0.1.0

func (e *ErrTimestampScanBytes) Error() string

type ErrTimestampScanInvalidInput added in v0.1.0

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

func (*ErrTimestampScanInvalidInput) Error added in v0.1.0

type ErrUnmarshalSFID added in v0.1.0

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

func (*ErrUnmarshalSFID) Error added in v0.1.0

func (e *ErrUnmarshalSFID) Error() string

func (*ErrUnmarshalSFID) Unwrap added in v0.1.0

func (e *ErrUnmarshalSFID) Unwrap() error

type Initializer added in v0.1.0

type Initializer interface{ Init() }

type InitializerByContext added in v0.1.0

type InitializerByContext interface{ Init(context.Context) }

type InitializerByContextWithError added in v0.1.0

type InitializerByContextWithError interface{ Init(context.Context) error }

type InitializerWithError added in v0.1.0

type InitializerWithError interface{ Init() 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(engine DBEngineType) 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(engine DBEngineType) 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