fn

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	OptIgnore    = "-"         // 忽略当前这个域
	OptOmitempty = "omitempty" // 当这个域的值为空,忽略这个域
	OptDive      = "dive"      // 递归地遍历这个结构体,将所有字段作为键
	OptWildcard  = "wildcard"  // 只适用于字符串类型,返回"%"+值+"%",这是为了方便数据库的模糊查询
)

Variables

This section is empty.

Functions

func Apply

func Apply(obj_func interface{}, args []interface{}) []reflect.Value

Apply 通过反射支持字符串直接调用函数

func Assign

func Assign(a, b interface{}) interface{}

Assign

func B2S

func B2S(b []byte) string

B2S Byte to String 高性能转换

func Call

func Call(obj_func interface{}, args ...interface{}) []reflect.Value

Call 通过反射支持字符串直接调用函数

func CallMethod

func CallMethod(obj interface{}, methodName string, args ...interface{}) []reflect.Value

CallMethod @param obj 为结构体指针

func FmtString

func FmtString(src string, data map[string]interface{}) string

FmtString @param str @param data @example FmtString("{a}",map[string]interfacle{}{"a":1})

func GetField

func GetField(obj interface{}, name string) (reflect.StructField, bool)

GetField

func GetKind

func GetKind(v interface{}) reflect.Kind

GetKind 通过反射获取数据类型 GetKind(string) == reflect.String GetKind(nil) == reflect.Invalid

func GetReflectType

func GetReflectType(v interface{}) reflect.Type

GetType 获取类型 不包括指针

func GetStructTypeName

func GetStructTypeName(v interface{}) string

获取一个struct的类型名称

func GetTag

func GetTag(obj struct{}, name, tagName string) string

GetTag 获取结构体标签

func GetType

func GetType(v interface{}) string

GetType(string) == "string" GetType(int) == "int" GetType(int32) == "int32" GetType(int64) == "int64"

func GoFns

func GoFns(num int, fns []func()) (wg *sync.WaitGroup)

GoFns @example GoFns(16,tasks); // 将tasks拆分成16组,并发执行

func GoFnsGroupBy

func GoFnsGroupBy(count int, num int, fns []func()) *sync.WaitGroup

GoFnsGroupBy

func Has

func Has(obj interface{}, name string) bool

Has 通过判断对象是否包含某一个类型

func IsBool

func IsBool(v interface{}) bool

IsBool

func IsInt

func IsInt(v interface{}) bool

IsInt

func IsMap

func IsMap(v interface{}) bool

IsInt

func IsPtr

func IsPtr(v interface{}) bool

IsPtr 是否为指针

func IsString

func IsString(v interface{}) bool

IsString

func IsStringBlank

func IsStringBlank(str string) bool

IsStringBlank 是否空字符串

func IsStringEmail

func IsStringEmail(value string) bool

IsStringEmail 判断字符串是否符合邮箱地址

func IsStringNumber

func IsStringNumber(str string) bool

IsStringNumber 判断字符串是否是数字

func IsStringURL

func IsStringURL(str string) bool

判断字符串是否是一个url地址

func Map2Struct

func Map2Struct(m map[string]interface{}, s struct{}) error

ToStruct 用map填充结构

func New

func New(v interface{}) interface{}

New 通过反射创建结构体对象,这里最好只传递引用类型

func NewSlice

func NewSlice(v interface{}) interface{}

NewSlice 通过反射创建结构体对象

func ParseBool

func ParseBool(str string) bool

ParseBool 将字符串转换为布尔值 它接受真值:1, t, T, TRUE, true, True 它接受假值:0, f, F, FALSE, false, False. 其它任何值都返回一个错误

func ParseFloat32

func ParseFloat32(str string) float32

ParseFloat32

func ParseFloat64

func ParseFloat64(str string) float64

类似于javascript,全局的parseInt、parseFloat ParseFloat64

func ParseHex

func ParseHex(str string) uint64

ParseHex

func ParseInt

func ParseInt(str string) int

ParseInt 解析失败时,返回int默认值

func ParseInt16

func ParseInt16(str string) int16

ParseInt16

func ParseInt32

func ParseInt32(str string) int32

ParseInt32

func ParseInt64

func ParseInt64(str string) int64

ParseInt64

func ParseInt8

func ParseInt8(str string) int8

ParseInt8

func ParseUint

func ParseUint(str string) uint

ParseUint

func ParseUint64

func ParseUint64(str string) uint64

ParseUint64

func RandBool

func RandBool() bool

RandBool 生成随机bool值

func RandBytes

func RandBytes(num int) []byte

RandString 生成随机字符串

func RandCaps

func RandCaps() string

RandCaps 生成随机大写字母

func RandLowerCase

func RandLowerCase() string

RandLowerCase 生成随机小写字母

func RandString

func RandString(num int) string

RandString 生成随机字符串

func S2B

func S2B(s string) []byte

S2B String to Bytes 高性能转换

func SetSleep

func SetSleep(action func() bool, delay int)

SetSleep 循环执行,同步等待 不同于setInterval的非阻塞执行,这里会停止直到返回false delay 1s

func StringReverse

func StringReverse(s string) string

ReverseString 反转字符串

func StringReverseOffset

func StringReverseOffset(s string, offset rune) string

StringReverseOffset

func StructToMap

func StructToMap(s interface{}, tag string, methodName string) (res map[string]interface{}, err error)

StructToMap 结构体转map fn.StructToMap(struct, "map", "")

func TimeCost

func TimeCost() func(name string)

TimeCost defer TimeCost()("执行时间耗时")

func ToCamelCase

func ToCamelCase(val string) string

ToCamelCase ToCamelCase("camel-case") == "camelCase"

func ToSliceReflectValue

func ToSliceReflectValue(args []interface{}) []reflect.Value

ToSliceReflectValue

func ToSnakeCase

func ToSnakeCase(val string) string

ToSnakeCase ToSnakeCase("snakeCase") == "snake-case"

func Unicode2ZH

func Unicode2ZH(from string) string

Unicode2ZH 将unicode编码转成中文

Types

type GoFnStruct

type GoFnStruct struct {
	Wg *sync.WaitGroup
}

func (GoFnStruct) Go

func (m GoFnStruct) Go(fn func(args ...interface{}), args ...interface{})

Jump to

Keyboard shortcuts

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