util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Browsers = []string{"chrome", "firefox", "safari", "opera", "edge", "ie", "wx", "qq", "theworld", "liebao", "baidu", "maxthon", "sogou", "miui", "uc", "360", "taobao", "2345"}
View Source
var (
	ErrInvalidPadding = errors.New("aes invalid padding")
)
View Source
var IntranetIPs = append(LocalIPs, "10.0.0.0/8", "172.31.0.0/16", "172.16.0.0/16", "192.168.0.0/16")
View Source
var LocalIPs = []string{"127.0.0.1/32"}

////////////////////////////////////////////////////////////////////////////////////////////////////// coding by Shang Peng 使用GetRealIP前需要调用SpIpInit初始化内网IP库

View Source
var Platforms = []string{"Linux", "Unix", "Mac OS X", "Windows", "iOS", "Android", "Windows Phone"}
View Source
var SpecialIPs = make([]*net.IPNet, 0, len(IntranetIPs)) //内网IP库

Functions

func AesDecrypt

func AesDecrypt(key []byte, data []byte, unpadding UnPaddingFunc) ([]byte, error)

func AesEncrypt

func AesEncrypt(key []byte, data []byte, padding PaddingFunc) ([]byte, error)

func Assign

func Assign(ptr interface{}, val interface{})

Assign val to the address of ptr. And the type of val must be *ptr. You can think that it works like this:

v, ok := val.(type(*ptr))
if !ok { panic() }
*ptr = v

func BeanCopy

func BeanCopy(src, dst interface{}) error

func BeanCopyByJson

func BeanCopyByJson(source, result interface{}) error

func Bool2Int

func Bool2Int(b bool) int64

func BytesToInt16

func BytesToInt16(b []byte) int16

func BytesToInt32

func BytesToInt32(b []byte) int32

func BytesToInt64

func BytesToInt64(b []byte) int64

func BytesToUint16

func BytesToUint16(b []byte) uint16

func BytesToUint32

func BytesToUint32(b []byte) uint32

func BytesToUint64

func BytesToUint64(b []byte) uint64

func CharCount

func CharCount(s string) int

func Contain

func Contain(array interface{}, val interface{}) bool

func ContainsString

func ContainsString(slice []string, s string) bool

func Find

func Find(array interface{}, val interface{}) int

func GetBase64Md5

func GetBase64Md5(raw []byte) string

func GetDevice

func GetDevice(req *http.Request, body url.Values) *model.Device

func GetDeviceType

func GetDeviceType(req *http.Request, body url.Values) string

func GetMd5

func GetMd5(raw []byte) string

func GetRealBrowser

func GetRealBrowser(ua string) string

func GetRealIP

func GetRealIP(r *http.Request) string

func GetRealPlatform

func GetRealPlatform(ua string) string

func GetVersion

func GetVersion(ua string, keyword string) string

func Int16ToBytes

func Int16ToBytes(u int16) []byte

func Int2Bool

func Int2Bool(i int64) bool

func Int32ToBytes

func Int32ToBytes(u int32) []byte

func Int64ToBytes

func Int64ToBytes(u int64) []byte

func IsCommonBrowser

func IsCommonBrowser(browser string) bool

func IsCommonPlatform

func IsCommonPlatform(platform string) bool

func IsEmail

func IsEmail(email string) bool

func IsValidCellPhone

func IsValidCellPhone(phonenumber string) bool

func Join

func Join(array interface{}, sep string) string

func JoinInts

func JoinInts(a []int64, sep string) string

func Map

func Map(mapping func(interface{}) interface{}, strs ...interface{}) []interface{}

func Map2Struct

func Map2Struct(vals map[string]interface{}, dst interface{}, structTag string) (err error)

func NowMsec

func NowMsec() int64

func ParseCellPhone

func ParseCellPhone(phonenumber string) (region string, phone string)

func Pkcs5Padding

func Pkcs5Padding(data []byte) []byte

func Pkcs5Unpadding

func Pkcs5Unpadding(data []byte) ([]byte, error)

func Remove

func Remove(ptrArray interface{}, val interface{}) int

Remove all elems equals to Val in Array. Return the number of elems removed.

func Reverse

func Reverse(array interface{})

func Slice

func Slice(s string) (b []byte)

no copy to change string to slice use your own risk

func SpIpInit

func SpIpInit()

func SplitFilename

func SplitFilename(fname string) (base string, ext string)

return base name and ext with leading "."

func String

func String(b []byte) (s string)

no copy to change slice to string use your own risk

func Struct2Map

func Struct2Map(s interface{}) map[string]interface{}

func Struct2MapByTag

func Struct2MapByTag(s interface{}, tagName string) map[string]interface{}

func ToExportBrowser

func ToExportBrowser(browser string) string

func Uint16ToBytes

func Uint16ToBytes(u uint16) []byte

func Uint32ToBytes

func Uint32ToBytes(u uint32) []byte

func Uint64ToBytes

func Uint64ToBytes(u uint64) []byte

Types

type PaddingFunc

type PaddingFunc func([]byte) []byte

type UnPaddingFunc

type UnPaddingFunc func([]byte) ([]byte, error)

Jump to

Keyboard shortcuts

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