utils

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt added in v1.3.30

func AesDecrypt(encryptedData []byte, key []byte) (string, error)

AesDecrypt 实现解密

func AesEncrypt added in v1.3.30

func AesEncrypt(origData []byte, key []byte) ([]byte, error)

AesEncrypt 实现加密

func Base64ToImage

func Base64ToImage(imageBase64 string) ([]byte, error)

func CheckExist

func CheckExist(src string) bool

CheckExist 检查文件是否存在

func CheckPermission

func CheckPermission(src string) bool

CheckPermission 检查文件权限

func ClientIpAddr added in v1.3.30

func ClientIpAddr(r *http.Request) string

func CompareSignature added in v1.3.30

func CompareSignature(signature, message, accessSecret string) bool

func Copy added in v1.3.30

func Copy(dst, src interface{}) error

func DivisibleBy2 added in v1.3.30

func DivisibleBy2(x float64) int

func FastSimpleUUID added in v1.3.30

func FastSimpleUUID() string

func Gcd added in v1.3.30

func Gcd(x, y int) int

func GenerateRandomCode added in v1.3.30

func GenerateRandomCode(num int) string

func GenerateRandomString added in v1.3.30

func GenerateRandomString(num int) string

func GetCurrentTimeStamp

func GetCurrentTimeStamp() int64

func GetDirFiles

func GetDirFiles(dir string) ([]string, error)

func GetDistance added in v1.3.30

func GetDistance(lat1, lon1, lat2, lon2 float64) float64

GetDistance 使用文森特公式(Vincenty's formulae),它考虑了地球的椭球形状,因此可以提供更精确的结果。但是,这种方法的计算复杂度更高,可能需要更多的计算资源

func GetExt

func GetExt(fileName string) string

GetExt 获取文件后缀

func GetGcd added in v1.3.30

func GetGcd(times []int) int

func GetIP added in v1.3.30

func GetIP() string

func GetIPWithPrefix added in v1.3.30

func GetIPWithPrefix(prefix string) string

func GetImgType

func GetImgType(p string) (string, error)

GetImgType 获取Img文件类型

func GetLcm added in v1.3.30

func GetLcm(times []int) int

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize 获取文件大小

func GetType

func GetType(p string) (string, error)

GetType 获取文件类型

func GetUUID

func GetUUID() string

func HashFile added in v1.3.30

func HashFile(filename string) (string, error)

func HashString added in v1.3.30

func HashString(content string) string

func Hmac

func Hmac(data string) string

func HmacSignature added in v1.3.30

func HmacSignature(message, accessSecret string) []byte

func HttpGet added in v1.4.11

func HttpGet(url string) ([]byte, error)

func HttpPost added in v1.3.30

func HttpPost(url, content string) ([]byte, error)

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir 检查文件夹是否存在 如果不存在则新建文件夹

func IsStringEmpty

func IsStringEmpty(str string) bool

func Lcm added in v1.3.30

func Lcm(x, y int) int

func MkDir

func MkDir(src string) error

MkDir 新建文件夹

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open 打开文件

func PasswordCheck added in v1.3.30

func PasswordCheck(ps string, minLength, maxLength int, level int) error

func PathExists

func PathExists(path string) bool

func Pos added in v1.3.30

func Pos(haystack, needle string, startOffset ...int) int

func RemoveRepByMap

func RemoveRepByMap(slc []string) []string

slice去重

func ReplaceI added in v1.3.30

func ReplaceI(origin, search, replace string, count ...int) string

func ResolveIPFromHostsFile added in v1.3.30

func ResolveIPFromHostsFile() (string, error)

func Round added in v1.3.30

func Round(x float64) int

func Sha1String added in v1.3.30

func Sha1String(content string) string

func StringIsEmpty added in v1.3.30

func StringIsEmpty(text string) bool

func StringIsNotEmpty added in v1.3.30

func StringIsNotEmpty(text string) bool

func UniqueId added in v1.4.11

func UniqueId(prefix string) string

func UserAgentToOsBrowser added in v1.3.30

func UserAgentToOsBrowser(userAgent string) (os string, browser string)

Types

type APIException

type APIException struct {
	Code      int         `json:"code"`
	Success   bool        `json:"success"`
	Msg       string      `json:"msg"`
	Timestamp int64       `json:"timestamp"`
	Result    interface{} `json:"result"`
}

api结构体

func AuthError

func AuthError(message string) *APIException

授权错误

func NotFound

func NotFound() *APIException

404 错误

func ParameterError

func ParameterError(message string) *APIException

参数错误

func ResponseJson

func ResponseJson(message string, data interface{}, success bool) *APIException

200

func ServerError

func ServerError() *APIException

500 错误处理

func UnknownError

func UnknownError(message string) *APIException

未知错误

func (*APIException) Error

func (e *APIException) Error() string

实现接口

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan valueof time.Time

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type VerifierAuth added in v1.4.0

type VerifierAuth struct {
}

func NewVerifierAuth added in v1.4.0

func NewVerifierAuth() *VerifierAuth

func (*VerifierAuth) GetCode added in v1.4.0

func (v *VerifierAuth) GetCode(secret string) (string, error)

GetCode 获取动态码

func (*VerifierAuth) GetQrcode added in v1.4.0

func (v *VerifierAuth) GetQrcode(user, secret string) string

GetQrcode 获取动态码二维码内容

func (*VerifierAuth) GetQrcodeUrl added in v1.4.0

func (v *VerifierAuth) GetQrcodeUrl(user, secret string) string

GetQrcodeUrl 获取动态码二维码图片地址,这里是第三方二维码api

func (*VerifierAuth) GetSecret added in v1.4.0

func (v *VerifierAuth) GetSecret() string

GetSecret 获取秘钥

func (*VerifierAuth) VerifyCode added in v1.4.0

func (v *VerifierAuth) VerifyCode(secret, code string) (bool, error)

VerifyCode 验证动态码

Jump to

Keyboard shortcuts

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