Documentation ¶
Overview ¶
Package utils is a library of commonly used utility functions.
Index ¶
- Constants
- func AdaptiveMongodbDsn(dsn string) string
- func AdaptiveMysqlDsn(dsn string) string
- func AdaptivePostgresqlDsn(dsn string) string
- func AdaptiveSqlite(dbFile string) string
- func FormatDateTimeLayout(t time.Time) string
- func FormatDateTimeLayoutWithMS(t time.Time) string
- func FormatDateTimeLayoutWithMSAndTZ(t time.Time) string
- func FormatDateTimeRFC3339(t time.Time) string
- func GetAvailablePort() (int, error)
- func GetHostname() string
- func GetLocalHTTPAddrPairs() (serverAddr string, requestAddr string)
- func Int64ToStr(v int64) string
- func IntToStr(v int) string
- func ParseDateTimeLayout(s string) (time.Time, error)
- func ParseDateTimeLayoutWithMS(s string) (time.Time, error)
- func ParseDateTimeLayoutWithMSAndTZ(s string) (time.Time, error)
- func ParseDateTimeRFC3339(s string) (time.Time, error)
- func SafeRun(ctx context.Context, fn func(ctx context.Context))
- func SafeRunWithTimeout(d time.Duration, fn func(cancel context.CancelFunc))
- func StrToFloat32(str string) float32
- func StrToFloat32E(str string) (float32, error)
- func StrToFloat64(str string) float64
- func StrToFloat64E(str string) (float64, error)
- func StrToInt(str string) int
- func StrToIntE(str string) (int, error)
- func StrToUint32(str string) uint32
- func StrToUint32E(str string) (uint32, error)
- func StrToUint64(str string) uint64
- func StrToUint64E(str string) (uint64, error)
- func Uint64ToStr(v uint64) string
Constants ¶
const ( // DateTimeLayout is the layout string for datetime format. DateTimeLayout = "2006-01-02 15:04:05" // DateTimeLayoutWithMS is the layout string for datetime format with milliseconds. DateTimeLayoutWithMS = "2006-01-02 15:04:05.000" // RFC3339 is the layout string for RFC3339 format. RFC3339 = "2006-01-02T15:04:05Z07:00" // DateTimeLayoutWithMSAndTZ is the layout string for datetime format with milliseconds and timezone. DateTimeLayoutWithMSAndTZ = "2006-01-02T15:04:05.000Z" // TimeLayout is the layout string for time format. TimeLayout = "15:04:05" // DateLayout is the layout string for date format. DateLayout = "2006-01-02" )
Variables ¶
This section is empty.
Functions ¶
func AdaptiveMongodbDsn ¶
AdaptiveMongodbDsn adaptive mongodb dsn
func AdaptiveMysqlDsn ¶
AdaptiveMysqlDsn adaptation of various mysql format dsn address
func AdaptivePostgresqlDsn ¶
AdaptivePostgresqlDsn convert postgres dsn to kv string
func FormatDateTimeLayout ¶
FormatDateTimeLayout formats the given time to the layout string "2006-01-02 15:04:05".
func FormatDateTimeLayoutWithMS ¶
FormatDateTimeLayoutWithMS formats the given time to the layout string "2006-01-02 15:04:05.000".
func FormatDateTimeLayoutWithMSAndTZ ¶
FormatDateTimeLayoutWithMSAndTZ formats the given time to the layout string "2006-01-02T15:04:05.000Z".
func FormatDateTimeRFC3339 ¶
FormatDateTimeRFC3339 formats the given time to the layout string "2006-01-02T15:04:05Z07:00".
func GetLocalHTTPAddrPairs ¶
GetLocalHTTPAddrPairs get available http server and request address
func ParseDateTimeLayout ¶
ParseDateTimeLayout parses the given string to time with layout string "2006-01-02 15:04:05".
func ParseDateTimeLayoutWithMS ¶
ParseDateTimeLayoutWithMS parses the given string to time with layout string "2006-01-02 15:04:05.000".
func ParseDateTimeLayoutWithMSAndTZ ¶
ParseDateTimeLayoutWithMSAndTZ parses the given string to time with layout string "2006-01-02T15:04:05.000Z".
func ParseDateTimeRFC3339 ¶
ParseDateTimeRFC3339 parses the given string to time with layout string "2006-01-02T15:04:05Z07:00".
func SafeRunWithTimeout ¶
func SafeRunWithTimeout(d time.Duration, fn func(cancel context.CancelFunc))
SafeRunWithTimeout safe run with limit timeouts
func StrToFloat32E ¶
StrToFloat32E string to float32 with error
func StrToFloat64E ¶
StrToFloat64E string to float64 with error
func StrToUint32E ¶
StrToUint32E string to uint32 with error
func StrToUint64E ¶
StrToUint64E string to uint64 with error
Types ¶
This section is empty.