utils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 22 Imported by: 5

Documentation

Index

Constants

View Source
const (
	STRUCT_DATE_TIME_FORMAT_LAYOUT = "2006-01-02 15:04:05"
	STRUCT_DATE_FORMAT_LAYOUT      = "2006-01-02"
)

Variables

View Source
var (
	TAG_STYLE_NONE      = 0
	TAG_STYLE_ORIG      = 1
	TAG_STYLE_SNAKE     = 2
	TAG_STYLE_UNDERLINE = 3
)
View Source
var (
	StructTimeType = reflect.TypeOf(time.Now())
)

Functions

func Abs

func Abs(x int) int

func Abs64

func Abs64(x int64) int64

func AnyIndirect

func AnyIndirect(v reflect.Value) reflect.Value

func AsyncInvokeWithTimeout

func AsyncInvokeWithTimeout(timeout time.Duration, args ...func()) bool

usage: var respInfos []string

result := AsyncInvokeWithTimeout(time.Second*4, func() {
	time.Sleep(time.Second*2)
	respInfos = []string{"we add1","we add2"}
	fmt.Println("1done")
},func() {
	time.Sleep(time.Second*1)
	//respInfos = append(respInfos,"we add3")
	fmt.Println("2done")
})

fmt.Println("1alldone:",result)

func AsyncInvokesWithTimeout

func AsyncInvokesWithTimeout(timeout time.Duration, fs []func()) bool

func AutoGenTags

func AutoGenTags(vo interface{}, tagDefs map[string]TAG_STYLE) string

func BaseConvert

func BaseConvert(src interface{}, dstType reflect.Type) interface{}

func CheckKeyValueExpected

func CheckKeyValueExpected(keyValues map[string]string, keyName, defaultKeyValue string, expectKeyValues []string) bool

检查keyname的keyvalue是否符合预期值expectKeyValues,如果不存在keyvalue,使用defaultKeyValue判断

func ComposeKey

func ComposeKey(keys ...string) string

func ContextWithTrace

func ContextWithTrace() context.Context

func ConvertFieldStyle

func ConvertFieldStyle(str string, style TAG_STYLE) string

func CopyStruct

func CopyStruct(src, dest interface{}, f StructConvFunc) error

dest 必须是指针

func CopyStructDefault

func CopyStructDefault(src, dest interface{}) error

func CopyStructs

func CopyStructs(src, dest interface{}, f StructConvFunc) error

dest 必须是数组的指针

func CopyStructsDefault

func CopyStructsDefault(src, dest interface{}) error

func CreateModel

func CreateModel(name string) interface{}

func CreateModels

func CreateModels(name string) interface{}

返回的是 结构体的数组指针 即 []*struct

func FileExist

func FileExist(filePath string) bool

func FileExt

func FileExt(filePath string) string

func GBK2UTF8

func GBK2UTF8(s []byte) ([]byte, error)

func GetCurrPath added in v1.0.14

func GetCurrPath() string

func GetModelNames

func GetModelNames() []string

func GetRegModel

func GetRegModel(name string) interface{}

func GetRegModelType

func GetRegModelType(modelName string) reflect.Type

func GetRegModels

func GetRegModels() []interface{}

func IsGBK added in v1.0.16

func IsGBK(data []byte) bool

func IsModelHasField

func IsModelHasField(modelName string, fieldName string) bool

func IsNil

func IsNil(value interface{}) bool

func IsUtf8 added in v1.0.16

func IsUtf8(data []byte) bool

func MD5

func MD5(origStr string) string

func Max

func Max(x, y int) int

func Max64

func Max64(x, y int64) int64

func MaxU

func MaxU(x, y uint32) uint32

func MergeStructs

func MergeStructs(src, dest interface{}, f StructConvFunc, keyField string, fieldMapping ...string) error

func Min

func Min(x, y int) int

func Min64

func Min64(x, y int64) int64

func MinU

func MinU(x, y uint32) uint32

func NewUUID

func NewUUID() string

func ParseContentByTag added in v1.0.14

func ParseContentByTag(content, tagStart, tagEnd string) (string, int)

func ReadImage

func ReadImage(filePath string) (image.Image, error)

func RegisterModels

func RegisterModels(models ...interface{})

func SafeIsNil

func SafeIsNil(value *reflect.Value) bool

func StringsExcept

func StringsExcept(ss1 []string, ss2 []string) (se []string)

func StringsInArray

func StringsInArray(s []string, e string) (bool, int)

func StringsReverse

func StringsReverse(s []string) []string

func UTF82GBK

func UTF82GBK(s []byte) ([]byte, error)

func WriteImage

func WriteImage(img image.Image, filePath string) error

Types

type StructConvFunc

type StructConvFunc func(interface{}, reflect.Type) interface{}

type TAG_STYLE

type TAG_STYLE = int

Directories

Path Synopsis
cmd
Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321.
Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321.
Package snowflake provides a very simple Twitter snowflake generator and parser.
Package snowflake provides a very simple Twitter snowflake generator and parser.

Jump to

Keyboard shortcuts

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