utilp

package
v0.2.28 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 13 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

func Bytes2String(b []byte) string

func FormatDateTime

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

func FromGob

func FromGob(input []byte, parse any) error

func GobConv

func GobConv(src any, dst any) error

func If

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

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

func JsonConv

func JsonConv(src any, dst any) error

func MapConv

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

func OrZero

func OrZero[T any](data *T) T

如果data为nil,则返回0值,否则返回data

func Recover

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

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

func SplitBy

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

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

func SplitHead

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

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

func String2Bytes

func String2Bytes(s string) []byte

func ToGob

func ToGob(input any) ([]byte, error)

func ToStr added in v0.2.28

func ToStr(data any) string

ToStr 将任意类型转换为字符串

func ToTimeHookFunc

func ToTimeHookFunc() mapstructure.DecodeHookFunc

func Try

func Try(invoke func())

Try 保护方法运行

func TryCatch

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

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

Types

type NoCopy

type NoCopy struct{}

func (*NoCopy) Lock

func (*NoCopy) Lock()

func (*NoCopy) Unlock

func (*NoCopy) Unlock()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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