Documentation ¶
Overview ¶
Package util @Description: 工具包 @Link: https://github.com/panjf2000/ants 是一个高性能且低损耗的 goroutine 池 @Ref:
Index ¶
- Variables
- func AddTicker(tag string)
- func AnyToStr(a interface{}) (string, error)
- func ConvertStringByByteSlice(bytes []byte) string
- func ConvertToPB[T protoreflect.ProtoMessage](data []byte) (t T)
- func CopyMeta(src, dst map[string]string)
- func ExcelExport()
- func GenerateCSApiService()
- func GenerateKey() ([]byte, error)
- func GenerateSnowflakeId() string
- func GeneratorAPI[T any](moduleName, version string, pushServices ...string)
- func GeneratorRPC[T any](moduleName, version string)
- func GetFileList(path string, ext string) []string
- func GetFileMd5(file string) string
- func GetFiledName(name string) string
- func GetLocalHost() (ip string)
- func GetLocalHost2() (ip string)
- func Go(f func())
- func InitGoroutinePool()
- func IsNil[Val any](val Val)
- func JsonToErrorStruct(packageName, fileName, outPath string, data []TemplateKeyValueData)
- func JsonToKeyValueGoFile(packageName, fileName, outPath, fieldType string, data []TemplateKeyValueData)
- func Max[T number](a, b T) T
- func Min[T number](a, b T) T
- func RandNumber[T number](min, max T) T
- func ReflectType[T any]() reflect.Type
- func RemoveAllKey(s []string, r string) []string
- func RemoveOneKey(s []string, r string) []string
- func SetAutoGenerateAPICSCode(path, namespace string)
- func SetExcelPath(path string)
- func SetExcelToClientJsonPath(path string)
- func SetExcelToGoPath(path string)
- func SetExcelToJsonPath(path string)
- func SetExcelToUnityNamespace(namespace string)
- func SetExcelToUnityPath(path string)
- func SetTgfUnityFramework()
- func SliceDeduplication[S comparable](s []S) []S
- func StrToAny[T any](a string) (T, error)
- func StringToSliceByte(s string) []byte
- type Aes
- type CSStruct
- type IWeight
- type IWeightBuilder
- type IWeightData
- type IWeightItem
- type TemplateKeyValueData
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var C, S = "c", "s"
var Snowflake *snowflake.Node
Functions ¶
func AnyToStr ¶
AnyToStr
@Description: 任意数据转换成字符串,默认结构化数据使用json序列化 @param a @return string @return error
func ConvertStringByByteSlice ¶
ConvertStringByByteSlice @Description: 字节转字符串 @param bytes @return string
func ConvertToPB ¶
func ConvertToPB[T protoreflect.ProtoMessage](data []byte) (t T)
func GenerateCSApiService ¶
func GenerateCSApiService()
func GenerateSnowflakeId ¶
func GenerateSnowflakeId() string
func GeneratorAPI ¶
GeneratorAPI @Description: 生成api文件 @param ref
func GeneratorRPC ¶
func GetFileList ¶
func GetFileMd5 ¶ added in v1.0.8
func GetFiledName ¶ added in v1.0.11
func GetLocalHost2 ¶
func GetLocalHost2() (ip string)
func InitGoroutinePool ¶
func InitGoroutinePool()
func JsonToErrorStruct ¶ added in v1.0.7
func JsonToErrorStruct(packageName, fileName, outPath string, data []TemplateKeyValueData)
func JsonToKeyValueGoFile ¶
func JsonToKeyValueGoFile(packageName, fileName, outPath, fieldType string, data []TemplateKeyValueData)
func Max ¶ added in v1.0.4
func Max[T number](a, b T) T
Max Max[T number]
@Description: 获取最大值 @param a @param b @return T
func Min ¶ added in v1.0.4
func Min[T number](a, b T) T
Min Min[T number]
@Description: 获取最小值 @param a @param b @return T
func RandNumber ¶ added in v1.0.3
func RandNumber[T number](min, max T) T
func ReflectType ¶
func RemoveAllKey ¶
func RemoveOneKey ¶
func SetAutoGenerateAPICSCode ¶
func SetAutoGenerateAPICSCode(path, namespace string)
func SetExcelToClientJsonPath ¶ added in v1.0.7
func SetExcelToClientJsonPath(path string)
SetExcelToClientJsonPath @Description: 设置Excel导出客户端Json地址,可以追加多个输出地址 @param path
func SetExcelToGoPath ¶
func SetExcelToGoPath(path string)
SetExcelToGoPath @Description: 设置Excel导出Go地址 @param path
func SetExcelToJsonPath ¶
func SetExcelToJsonPath(path string)
SetExcelToJsonPath @Description: 设置Excel导出Json地址,可以追加多个输出地址 @param path
func SetExcelToUnityNamespace ¶
func SetExcelToUnityNamespace(namespace string)
SetExcelToUnityNamespace @Description: 设置excel导出到unity的命名空间,默认不设置的话为 HotFix.Config @param namespace
func SetExcelToUnityPath ¶
func SetExcelToUnityPath(path string)
SetExcelToUnityPath @Description: 设置Excel导出Unity地址 @param path
func SetTgfUnityFramework ¶ added in v1.0.11
func SetTgfUnityFramework()
func SliceDeduplication ¶ added in v1.0.7
func SliceDeduplication[S comparable](s []S) []S
SliceDeduplication @Description: 去重 @param s @return []S
func StrToAny ¶
StrToAny
@Description: string转任意类型 @param a @return T @return error
Example ¶
package main import ( "fmt" "github.com/thkhxm/tgf/util" ) //*************************************************** //@Link https://github.com/thkhxm/tgf //@Link https://gitee.com/timgame/tgf //@QQ群 7400585 //author tim.huang<thkhxm@gmail.com> //@Description //2023/3/6 //*************************************************** type StrToAnyStruct struct { Name string Age int32 } func main() { //to int if numInt, err := util.StrToAny[int]("1024"); err == nil { fmt.Println("numInt:", numInt) } //to interface{} if structData, err2 := util.StrToAny[StrToAnyStruct]("{\"Name\":\"tim\",\"Age\":5}"); err2 == nil { fmt.Println("json data:", structData.Name) } }
Output: numInt: 1024 json data: tim
func StringToSliceByte ¶ added in v1.0.14
Types ¶
type Aes ¶ added in v1.0.14
type Aes struct {
// contains filtered or unexported fields
}
func (*Aes) DecryptAES ¶ added in v1.0.14
type IWeight ¶
type IWeight[T any] interface { // Roll // @Description: 根据权重随机出一个数据,并且减少物品的数量 // @return T // Roll() (res IWeightData[T]) // AllItem // @Description: 这里不会进行切片的拷贝,所以在使用的时候需要注意 // @return IWeightItem[T] // AllItem() []IWeightData[T] TotalRatio() int32 BaseRatio() int32 BaseAmount() int32 Len() int OnlyRoll() (res IWeightData[T]) UpdateItemStock(data IWeightData[T]) }
type IWeightBuilder ¶
type IWeightBuilder[T any] interface { AddWeight(weightRatio, amount int32, data T) IWeightBuilder[T] Build() IWeight[T] Seed(seed uint64) IWeightBuilder[T] }
func NewWeightBuilder ¶
func NewWeightBuilder[T any]() IWeightBuilder[T]
type IWeightData ¶
type IWeightItem ¶
type IWeightItem[T any] interface { IWeightData[T] Hit() (IWeightItem[T], bool) }
type TemplateKeyValueData ¶
type TemplateKeyValueData struct { FieldName interface{} Values interface{} Other interface{} }