util

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DateTime = "2006-01-02 15:04:05"
	DateOnly = "2006-01-02"
	TimeOnly = "15:04:05"
)

Functions

func Bytes2String added in v0.0.12

func Bytes2String(b []byte) string

func FormatDateTime added in v0.0.13

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

func GobConv added in v0.2.9

func GobConv(src any, dst any) error

func If added in v0.0.12

func If[T any](condition bool, trueVal, falseVal T) T

伪三元表达式 PS: 请注意,由于go的机制, trueVal, falseVal 都是已定值(在传入if前就确定了), 可能会导致panic

func JsonConv added in v0.0.13

func JsonConv(src any, dst any) error

func MapConv added in v0.0.13

func MapConv(src map[string]any, dst any) error

func Recover added in v0.0.12

func Recover(msg string, goAfterRecover func(err error))

Recover 恢复panic 仅限于在 go routine 中,放置在第一行执行 严禁在主线程使用

func SplitBy added in v0.0.12

func SplitBy(content, spliter, escape string) (ret []string)

使用分隔符与转义符对字符串进行分割 $content 字符串内容 $spliter 分隔符 $escape 转义符

func SplitHead added in v0.0.12

func SplitHead(content, spliter, escape string) (ret [2]string)

使用分隔符与转义符对字符串进行分割(只拆分出第一个) $content 字符串内容 $spliter 分隔符 $escape 转义符

func String2Bytes added in v0.0.12

func String2Bytes(s string) []byte

func ToTimeHookFunc added in v0.0.13

func ToTimeHookFunc() mapstructure.DecodeHookFunc

func Try added in v0.0.12

func Try(invoke func())

Try 保护方法运行

func TryCatch added in v0.0.12

func TryCatch(invoke func(), fallback func(err error))

TryCatch 保护方法运行,如果失败,则执行fallback方法

Types

type NoCopy added in v0.0.12

type NoCopy struct{}

func (*NoCopy) Lock added in v0.0.12

func (*NoCopy) Lock()

func (*NoCopy) Unlock added in v0.0.12

func (*NoCopy) Unlock()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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