Documentation
¶
Index ¶
- func BuildTLSConfig(certFile, keyFile, caFile string, insecureSkipVerify bool) (*tls.Config, error)
- func BytesToString(b []byte) string
- func CharSpliter(data []byte, atEOF bool) (advance int, token []byte, err error)
- func CheckErr(err error)
- func CombineError(fns ...func() error) error
- func Contains[T comparable](slice []T, elem T) bool
- func Depointer[T comparable](t *T) T
- func Deref[T any](p *T) T
- func DerefOr[T any](p *T, defaultVal T) T
- func FileExists(filename string) bool
- func FormatDurationSmart(d time.Duration, precisions ...int) string
- func GetFdFromConn(c net.Conn) int
- func GetFdFromListener(l net.Listener) int
- func GetFunctionName(x any) string
- func HandleErr(err error, notExit ...bool)
- func HashID(fields ...string) string
- func IPv6ToIPv4(ipStr string) string
- func IndexedUUID() string
- func IsConnClosed(err error) bool
- func Keys[K comparable, V any](in ...map[K]V) []K
- func Marshal(value any) ([]byte, error)
- func NoError(fn func() error) error
- func ParseScheme(req *http.Request) string
- func Ping(ip string, timeout time.Duration) (bool, error)
- func Pointer[T comparable](t T) *T
- func RequestID() string
- func Round[T float32 | float64](value T, precision uint) T
- func RunOrDie(fn func() error)
- func SafePointer[T any](v T) T
- func SpanID() string
- func SplitByDoublePipe(data []byte, atEOF bool) (advance int, token []byte, err error)
- func StringAny(x any) string
- func StringToBytes(s string) []byte
- func Tcping(host string, port int, timeout time.Duration) bool
- func TraceID() string
- func UUID(prefix ...string) string
- func Uniq[T comparable, Slice ~[]T](collection Slice) Slice
- func Unmarshal(data []byte, value any) error
- func ValueOf[T any](v T) *T
- func Values[K comparable, V any](in ...map[K]V) []V
- type Connection
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildTLSConfig ¶ added in v0.4.0
BuildTLSConfig creates a TLS configuration from the etcd config
func BytesToString ¶
BytesToString converts byte slice to string without a memory allocation. For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
func CharSpliter ¶
CharSpliter is the custom split function for bufio.Scanner.
func CombineError ¶ added in v0.0.48
CombineError combine error from fns.
func Contains ¶ added in v0.0.47
func Contains[T comparable](slice []T, elem T) bool
Contains check T in slice.
func Deref ¶ added in v0.0.58
func Deref[T any](p *T) T
Deref returns the value pointed to by the pointer. If the pointer is nil, returns the zero value for the type.
func DerefOr ¶ added in v0.0.58
func DerefOr[T any](p *T, defaultVal T) T
DerefOr returns the value pointed to by the pointer. If the pointer is nil, returns the default value.
func FileExists ¶ added in v0.0.48
FileExists check file exists.
func FormatDurationSmart ¶ added in v0.4.4
FormatDurationSmart formats a time.Duration into a string with the following rules:
- If duration is less than 1ms, display as milliseconds with the specified precision (e.g., "0.018ms").
- If duration is less than 1s, display as milliseconds with the specified precision (e.g., "123.451ms").
- If duration is less than 1min, display as seconds with the specified precision (e.g., "2.013s").
- If duration is 1min or more, display as minutes with the specified precision (e.g., "1.502min").
Negative durations are supported and formatted with a '-' sign. The precision parameter controls the number of digits after the decimal point (minimum 0, maximum 9).
func GetFdFromConn ¶ added in v0.2.0
GetFdFromConn get net.Conn's file descriptor.
func GetFdFromListener ¶ added in v0.2.0
GetFdFromListener get net.Listener's file descriptor.
func GetFunctionName ¶
func IPv6ToIPv4 ¶ added in v0.3.2
IPv6ToIPv4 converts IPv6 to IPv4 if possible
func IndexedUUID ¶
func IndexedUUID() string
func IsConnClosed ¶ added in v0.2.0
func Keys ¶ added in v0.7.1
func Keys[K comparable, V any](in ...map[K]V) []K
Keys creates an array of the map keys. Play: https://go.dev/play/p/Uu11fHASqrU
func ParseScheme ¶
func Ping ¶
Ping work like command `ping`. If target ip is reachable, return true, nil, If target ip is unreachable, return false, nil, If error encountered, return false, error. More usage see tests in `pkg/util/util_test.go`.
func Pointer ¶
func Pointer[T comparable](t T) *T
Pointer will return a pointer to T with given value.
func Round ¶ added in v0.0.65
Round returns a rounded version of x with a specified precision.
The precision parameter specifies the number of decimal places to round to. Round uses the "round half away from zero" rule to break ties.
Examples:
Round(3.14159, 2) returns 3.14 Round(3.14159, 1) returns 3.1 Round(-3.14159, 1) returns -3.1
Example ¶
fmt.Printf("%.3f\n", Round(3.14159, 3)) fmt.Printf("%.2f\n", Round(2.71828, 2)) fmt.Printf("%.1f\n", Round(-3.14159, 1))
Output: 3.142 2.72 -3.1
func SafePointer ¶
func SafePointer[T any](v T) T
func SplitByDoublePipe ¶
SplitByDoublePipe is the custom split function for bufio.Scanner.
func StringToBytes ¶
StringToBytes convers string to byte slice without a memory allocation. For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
func Uniq ¶ added in v0.7.1
func Uniq[T comparable, Slice ~[]T](collection Slice) Slice
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. Play: https://go.dev/play/p/DTzbeXZ6iEN
func ValueOf ¶ added in v0.0.58
func ValueOf[T any](v T) *T
ValueOf returns a pointer to the given value
func Values ¶ added in v0.7.1
func Values[K comparable, V any](in ...map[K]V) []V
Values creates an array of the map values. Play: https://go.dev/play/p/nnRTQkzQfF6
Types ¶
type Connection ¶ added in v0.2.0
func GetConnection ¶ added in v0.2.0
func GetConnection(conn net.Conn) Connection