pkgutils

package module
v1.0.2-0...-46d4d79 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 29 Imported by: 0

README

pkgutils

自用公共库,来自github的集合

go utils

Documentation

Overview

*

  • @author Liu Yongshuai<liuyongshuai@hotmail.com>
  • @date 2018-03-27 15:20

Index

Constants

This section is empty.

Variables

View Source
var (
	LocalHostIP        = ""
	LocalHostIpArr     []string
	LocalHostIpTraceId = ""

	ScreenWidth  int
	ScreenHeight int
)
View Source
var (
	//一些错误信息
	ErrorOverflowMaxInt64  = errors.New("this value overflow math.MaxInt64")
	ErrorOverflowMaxUint64 = errors.New("this value overflow math.MaxUint64")
	ErrorLessThanMinInt64  = errors.New("this value less than math.MinInt64")
	ErrorLessThanZero      = errors.New("this value less than zero")
	ErrorBadComparisonType = errors.New("invalid type for comparison")
	ErrorBadComparison     = errors.New("incompatible types for comparison")
	ErrorNoComparison      = errors.New("missing argument for comparison")
	ErrorInvalidInputType  = errors.New("invalid input type")
)
View Source
var CustomizeMap = make(map[string]Rules)

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

func AuthKeyFromBytes

func AuthKeyFromBytes(key []byte) (*ecdsa.PrivateKey, error)

JWT加密

func BreakPointContinue

func BreakPointContinue(content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string) (error, string)

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

bytes转float

func ByteToStr

func ByteToStr(b []byte) string

字节切片转为字符串

func Bytes2str

func Bytes2str(b []byte) string

func BytesToInt64

func BytesToInt64(buf []byte) int64

bytes转int64

func CheckAppleID

func CheckAppleID(data []byte, id string, err error) bool

解密苹果返回的data中的id_token中的用户id和客户端post的id否一致

func CheckFileIsExist

func CheckFileIsExist(path string) bool

func CheckMd5

func CheckMd5(content []byte, chunkMd5 string) (CanUpload bool)

func CreateUUID

func CreateUUID() (uuid string)

CreateUUID 生成UUID

func DecryptDES

func DecryptDES(src []byte) []byte

func EncryptDES

func EncryptDES(src []byte) []byte

func Eq

func Eq(mark string) string

等于入参(==) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func FakeTraceId

func FakeTraceId() (traceId string)

生成一个假的traceId

func FilterIds

func FilterIds(ids []interface{}) (ret []int64)

根据业务特点,过滤非法的ID并去重,一般用于批量根据ID提取信息时

func Float64ToByte

func Float64ToByte(float float64) []byte

float64转byte

func Ge

func Ge(mark string) string

大于等于入参(>=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func GetAppleLoginData

func GetAppleLoginData(clientId string, clientSecret string, code string) ([]byte, error)

请求苹果用户信息

func GetAppleSecret

func GetAppleSecret(keyId string, teamId string, clientId string, keySecret string) string

生成client_secret

func GetMessageIndex

func GetMessageIndex(sendFrom, sendTo string) (msgIndex string)

func GetPageParam

func GetPageParam(page, size int32) (int32, int32)

func Gt

func Gt(mark string) string

大于入参(>) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func InSlice

func InSlice(val interface{}, sl []interface{}) bool

检查interface类型是否在slice里

func Int64ToBytes

func Int64ToBytes(i int64) []byte

int64转byte

func Int64ToString

func Int64ToString(intNum int64) (result string)

func IntToString

func IntToString(intNum int) (result string)

func Le

func Le(mark string) string

小于等于入参(<=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func Lt

func Lt(mark string) string

小于入参(<) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func MD5V

func MD5V(str []byte) string

func MakeFile

func MakeFile(fileName string, FileMd5 string) (error, string)

func MakeMyRespError

func MakeMyRespError(code int32, msg string) error

func MaxInt64

func MaxInt64(args ...interface{}) (int64, error)

返回最大的一个int型

func MinInt64

func MinInt64(args ...interface{}) (int64, error)

返回最小的一个int型

func Ne

func Ne(mark string) string

不等于入参(!=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func NotEmpty

func NotEmpty() string

非空 不能为其对应类型的0值

func Paginator

func Paginator(page, pageSize int, nums int64, list interface{}) map[string]interface{}

分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数

func ParseMyRespError

func ParseMyRespError(errStr string) (code int32, msg string)

func PathExists

func PathExists(path string) (bool, error)

func ProcTime

func ProcTime(st, et int64) float64

处理请求的时间proc_time 时间要求time.Now().UnixNano()

func RandFloat64InRange

func RandFloat64InRange(min, max float64) float64

在指定浮点数范围内生成随机数

func ReRandSeed

func ReRandSeed()

重新设置随机数种子

func RegisterRule

func RegisterRule(key string, rule Rules) (err error)

注册自定义规则方案建议在路由初始化层即注册

func RemoveChunk

func RemoveChunk(FileMd5 string) error

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkSlice [][]interface{})

将一个slice切成若干个大小的子slice

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffSlice []interface{})

计算两个slice的差集

func SliceFilter

func SliceFilter(slice []interface{}, a filterCallbackFunc) (filteredSlice []interface{})

返回给定的slice在回调函数返回true的新slice

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (intersectSlice []interface{})

计算slice交集

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

合并两个slice

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

填充slice

func SliceRand

func SliceRand(a []interface{}) (b interface{})

从给定的slice里随机提取新的slice

func SliceReduce

func SliceReduce(slice []interface{}, a reduceCallbackFunc) (dSlice []interface{})

对给定的slice调用回调函数,生成一个新的slice

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

打乱一个slice

func SliceSum

func SliceSum(slice []interface{}) (sum int64)

计算int64型slice的和

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueSlice []interface{})

slice去重

func Str2JsonStr

func Str2JsonStr(oStr string) map[string]interface{}

func Str2bytes

func Str2bytes(s string) []byte

func StrToByte

func StrToByte(s string) []byte

字符串转为字节切片

func StringToInt

func StringToInt(parseString string) (result int, err error)

func StringToInt64

func StringToInt64(parseString string) (result int64, err error)

func StructToMap

func StructToMap(obj interface{}) (data map[string]interface{}, err error)

利用反射将结构体转化为map

func ToFloat64Slice

func ToFloat64Slice(arg []interface{}, ignoreErr bool) (ret []float64, err error)

转为float64地slice

func ToInt64Slice

func ToInt64Slice(arg []interface{}, ignoreErr bool) (ret []int64, err error)

转为int64地slice

func ToSliceIface

func ToSliceIface(in interface{}) []interface{}

将其他类型转为interface的切片,支持slice/map/[u]int[8-64]/float../string

func ToStringSlice

func ToStringSlice(arg []interface{}, ignoreErr bool) (ret []string, err error)

转为字符串slice

func TryBestToBool

func TryBestToBool(value interface{}) (bool, error)

尽最大努力转为bool类型

func TryBestToFloat

func TryBestToFloat(value interface{}) (float64, error)

尽最大努力转换为float64

func TryBestToInt64

func TryBestToInt64(value interface{}) (int64, error)

尽最大努力将给定的类型转换为int64 如"45.67"->45、"98.4abc3"->98、"34.87"->34

func TryBestToString

func TryBestToString(value interface{}) (string, error)

尽最大努力转换为字符串

func TryBestToUint64

func TryBestToUint64(value interface{}) (uint64, error)

尽最大努力将给定的类型转换为uint64 如"45.67"->45、"98.4abc3"->98、"34.87"->34

func Verify

func Verify(st interface{}, roleMap Rules) (err error)

校验方法 接收两个参数 入参实例,规则map

func ZipFiles

func ZipFiles(filename string, files []string, oldform, newform string) error

Types

type AppleAuth

type AppleAuth struct {
	AccessToken  string `json:"access_token,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	IdToken      string `json:"id_token,omitempty"`
}

type AppleIdToken

type AppleIdToken struct {
	Iss            string `json:"iss,omitempty"`
	Aud            string `json:"aud,omitempty"`
	Exp            int    `json:"exp,omitempty"`
	Iat            int    `json:"iat,omitempty"`
	Sub            string `json:"sub,omitempty"`
	AtHash         string `json:"at_hash,omitempty"`
	Email          string `json:"email,omitempty"`
	EmailVerified  string `json:"email_verified,omitempty"`
	IsPrivateEmail string `json:"is_private_email,omitempty"`
	AuthTime       int    `json:"auth_time,omitempty"`
	NonceSupported bool   `json:"nonce_supported,omitempty"`
}

type Basickind

type Basickind int
const (
	//转换时最大值
	MaxInt64Float  = float64(math.MaxInt64)
	MinInt64Float  = float64(math.MinInt64)
	MaxUint64Float = float64(math.MaxUint64)
	//基本类型归纳,类型转换时用得着
	InvalidKind Basickind = iota
	BoolKind
	ComplexKind
	IntKind
	FloatKind
	StringKind
	UintKind
	PtrKind
	ContainerKind
	FuncKind
)

func GetBasicKind

func GetBasicKind(v reflect.Value) (Basickind, error)

转换成特定类型,便于判断

type CommonResponse

type CommonResponse struct {
	Code int32       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func NewCommonResponse

func NewCommonResponse() *CommonResponse

type Page

type Page struct {
	PageNo     int         `json:"page_num"`
	PageSize   int         `json:"page_size"`
	TotalPage  int         `json:"total_page"`
	TotalCount int         `json:"total_count"`
	FirstPage  bool        `json:"first_page"`
	LastPage   bool        `json:"last_page"`
	List       interface{} `json:"list"`
}

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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