utils

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 8 Imported by: 4

Documentation

Overview

Package utils is a library of commonly used utility functions.

Index

Constants

View Source
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 added in v1.6.1

func AdaptiveMongodbDsn(dsn string) string

AdaptiveMongodbDsn adaptive mongodb dsn

func AdaptiveMysqlDsn added in v1.5.16

func AdaptiveMysqlDsn(dsn string) string

AdaptiveMysqlDsn adaptation of various mysql format dsn address

func AdaptivePostgresqlDsn added in v1.5.16

func AdaptivePostgresqlDsn(dsn string) string

AdaptivePostgresqlDsn convert postgres dsn to kv string

func AdaptiveSqlite added in v1.6.1

func AdaptiveSqlite(dbFile string) string

AdaptiveSqlite adaptive sqlite

func FormatDateTimeLayout added in v1.8.7

func FormatDateTimeLayout(t time.Time) string

FormatDateTimeLayout formats the given time to the layout string "2006-01-02 15:04:05".

func FormatDateTimeLayoutWithMS added in v1.8.7

func FormatDateTimeLayoutWithMS(t time.Time) string

FormatDateTimeLayoutWithMS formats the given time to the layout string "2006-01-02 15:04:05.000".

func FormatDateTimeLayoutWithMSAndTZ added in v1.8.7

func FormatDateTimeLayoutWithMSAndTZ(t time.Time) string

FormatDateTimeLayoutWithMSAndTZ formats the given time to the layout string "2006-01-02T15:04:05.000Z".

func FormatDateTimeRFC3339 added in v1.8.7

func FormatDateTimeRFC3339(t time.Time) string

FormatDateTimeRFC3339 formats the given time to the layout string "2006-01-02T15:04:05Z07:00".

func GetAvailablePort

func GetAvailablePort() (int, error)

GetAvailablePort get available port

func GetHostname

func GetHostname() string

GetHostname get hostname

func GetLocalHTTPAddrPairs

func GetLocalHTTPAddrPairs() (serverAddr string, requestAddr string)

GetLocalHTTPAddrPairs get available http server and request address

func Int64ToStr

func Int64ToStr(v int64) string

Int64ToStr int64 to string

func IntToStr

func IntToStr(v int) string

IntToStr int to string

func ParseDateTimeLayout added in v1.8.7

func ParseDateTimeLayout(s string) (time.Time, error)

ParseDateTimeLayout parses the given string to time with layout string "2006-01-02 15:04:05".

func ParseDateTimeLayoutWithMS added in v1.8.7

func ParseDateTimeLayoutWithMS(s string) (time.Time, error)

ParseDateTimeLayoutWithMS parses the given string to time with layout string "2006-01-02 15:04:05.000".

func ParseDateTimeLayoutWithMSAndTZ added in v1.8.7

func ParseDateTimeLayoutWithMSAndTZ(s string) (time.Time, error)

ParseDateTimeLayoutWithMSAndTZ parses the given string to time with layout string "2006-01-02T15:04:05.000Z".

func ParseDateTimeRFC3339 added in v1.8.7

func ParseDateTimeRFC3339(s string) (time.Time, error)

ParseDateTimeRFC3339 parses the given string to time with layout string "2006-01-02T15:04:05Z07:00".

func SafeRun added in v1.2.0

func SafeRun(ctx context.Context, fn func(ctx context.Context))

SafeRun safe run

func SafeRunWithTimeout added in v1.2.0

func SafeRunWithTimeout(d time.Duration, fn func(cancel context.CancelFunc))

SafeRunWithTimeout safe run with limit timeouts

func StrToFloat32

func StrToFloat32(str string) float32

StrToFloat32 string to float32

func StrToFloat32E

func StrToFloat32E(str string) (float32, error)

StrToFloat32E string to float32 with error

func StrToFloat64

func StrToFloat64(str string) float64

StrToFloat64 string to float64

func StrToFloat64E

func StrToFloat64E(str string) (float64, error)

StrToFloat64E string to float64 with error

func StrToInt

func StrToInt(str string) int

StrToInt string to int

func StrToIntE

func StrToIntE(str string) (int, error)

StrToIntE string to int with error

func StrToUint32

func StrToUint32(str string) uint32

StrToUint32 string to uint32

func StrToUint32E

func StrToUint32E(str string) (uint32, error)

StrToUint32E string to uint32 with error

func StrToUint64

func StrToUint64(str string) uint64

StrToUint64 string to uint64

func StrToUint64E

func StrToUint64E(str string) (uint64, error)

StrToUint64E string to uint64 with error

func Uint64ToStr

func Uint64ToStr(v uint64) string

Uint64ToStr uint64 to string

Types

This section is empty.

Jump to

Keyboard shortcuts

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