utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileMode0755 = 0755
	FileMode0644 = 0644
)

Variables

View Source
var (
	CharArr = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	NumArr  = []byte("1234567890")
)

Functions

func AppendStrToFile

func AppendStrToFile(path, content string) (err error)

AppendStrToFile 在已经存在的文件中,添加字符串

func Base64Decode

func Base64Decode(content string) (string, error)

func Base64Encode

func Base64Encode(content string) string

func ContentToQRCodeStr

func ContentToQRCodeStr(content string, level qrcode.RecoveryLevel, size int) (string, error)

ContentToQRCodeStr 根据content返回二维码图片的base64

func CountDirFiles

func CountDirFiles(dirName string) int

func CreateDir

func CreateDir(path string) error

func CreateFileByAllPath

func CreateFileByAllPath(fileName string) error

func FileMD5

func FileMD5(file *os.File) (string, error)

func FileMD5ByPath

func FileMD5ByPath(path string) (string, error)

FileMD5ByPath count file md5

func GeneratedToken

func GeneratedToken(userID int64, phone string, expire int) (string, error)

GeneratedToken ...

func HashPassword

func HashPassword(password, salt string) (string, error)

func HttpGet

func HttpGet(ctx context.Context, url string, headers map[string]string, params map[string]interface{}, timeout ...time.Duration) ([]byte, error)

HttpGet 发送get请求

func HttpPostJson

func HttpPostJson(ctx context.Context, url string, headers map[string]string, body interface{}, timeout ...time.Duration) ([]byte, error)

HttpPostJson 以json格式发送post请求

func InterfaceToStr

func InterfaceToStr(value interface{}) string

InterfaceToStr interface转string

func IsDir

func IsDir(path string) bool

func IsExist

func IsExist(path string) bool

IsExist 文件是否存在,true-存在,false-不存在

func MkFileFullPathDir

func MkFileFullPathDir(fileName string) error

func ParseToken

func ParseToken(tokenString string) (int64, string, error)

ParseToken ...

func RandCharStr

func RandCharStr(n int) string

RandCharStr 生成随机字符串

func RandNumStr

func RandNumStr(n int) string

RandNumStr 生成随机数字串

func ReadFileToBytes

func ReadFileToBytes(path string) ([]byte, error)

ReadFileToBytes 按字节读取文件

func ReadFileToLines

func ReadFileToLines(path string) ([]string, error)

ReadFileToLines 按行读取文件为字符串数组

func SplitStrToSubStrArr

func SplitStrToSubStrArr(s string, l int) []string

SplitStrToSubStrArr 字符串根据长度切割为字符串数组

func StrToUint64

func StrToUint64(str string) uint64

StrToUint64 string to uint64

func StrToUint64E

func StrToUint64E(str string) (uint64, error)

StrToUint64E string to uint64 with error

func Tar

func Tar(src, dst, trimPrefix string) error

func Untar

func Untar(src, dst string) error

func ValueIsBlank

func ValueIsBlank(value reflect.Value) bool

func ValueMd5

func ValueMd5(value interface{}) string

func WriteToFile

func WriteToFile(content interface{}, path string) error

WriteToFile 追加内容到现存文件中

Types

type Claims

type Claims struct {
	UserID int64
	Phone  string
	jwt.StandardClaims
}

type FileInfo

type FileInfo struct {
	os.FileInfo
	Path string
}

func AllFilesInDir

func AllFilesInDir(path string) ([]FileInfo, error)

Jump to

Keyboard shortcuts

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