utils

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
)

Variables

View Source
var ErrPartSizeMismatch = data.NewEmptyError().AppendDesc("part size mismatch with data from reader")

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, *data.CodeError)

解密数据

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, *data.CodeError)

加密数据

func BytesToReadable

func BytesToReadable(size int64) (readable string)

BytesToReadable 将字节转化为人工可读的字符串 b - 表示文件大小,单位字节, readable - 可读字符串 比如1304 ==》1304/1024 ==> 1.27KB

func CmdExistByFail added in v2.9.0

func CmdExistByFail()

func CmdExistBySuccess added in v2.9.0

func CmdExistBySuccess()

func CmdExistByUserCancel added in v2.9.0

func CmdExistByUserCancel()

func CreateDirIfNotExist

func CreateDirIfNotExist(path string) *data.CodeError

func CreateFileDirIfNotExist

func CreateFileDirIfNotExist(path string) *data.CodeError

func CreateFileIfNotExist

func CreateFileIfNotExist(path string) *data.CodeError

func CreateRandString

func CreateRandString(num int) (rcode string)

CreateRandString 生成随机的字符串

func Decode

func Decode(encodedURI string) (uri string, err *data.CodeError)

func DirCache

func DirCache(cacheRootPath string, cacheResultFile string) (int64, *data.CodeError)

DirCache generate the file list for the specified directory @param cacheRootPath - dir to generate cache file @param cacheResultFile - cache result file path @return (fileCount, retErr) - total file count and any error meets

func Encode

func Encode(uri string) string

Encode URL:

http://host/url
https://host/url

Path:

AbsolutePath	(Must start with '/')
Pid:RelPath	(Pid.len = 16)
Id: 			(Id.len = 16)
:LinkId:RelPath
:LinkId

func Endpoint

func Endpoint(useHttps bool, host string) string

func EtagV1

func EtagV1(reader io.Reader) (string, *data.CodeError)

func EtagV2

func EtagV2(reader io.Reader, parts []int64) (string, *data.CodeError)

func ExistDir

func ExistDir(path string) (bool, *data.CodeError)

func ExistFile

func ExistFile(path string) (bool, *data.CodeError)

func FileLineCounts

func FileLineCounts(filePath string) (count int64, err *data.CodeError)

func FileSize

func FileSize(filePath string) (fileSize int64, err *data.CodeError)

func FormatFileSize

func FormatFileSize(size int64) (result string)

FormatFileSize 转化文件大小到人工可读的字符串,以相应的单位显示

func Gbk2Utf8

func Gbk2Utf8(text string) (string, *data.CodeError)

func GenEncoding

func GenEncoding() []byte

func GetAkBucketFromUploadToken

func GetAkBucketFromUploadToken(token string) (ak, bucket string, err *data.CodeError)

func GetEtag

func GetEtag(filename string) (etag string, err *data.CodeError)

func GetFileLineCount

func GetFileLineCount(filePath string) (totalCount int64)

GetFileLineCount 获取文件行数

func GetHomePath

func GetHomePath() (string, *data.CodeError)

func GetLineCount

func GetLineCount(reader io.Reader) (totalCount int64)

GetLineCount 获取reader中行数

func GetNotEmptyStringIfExist

func GetNotEmptyStringIfExist(values ...string) string

func GetNotZeroInt16IfExist

func GetNotZeroInt16IfExist(values ...int16) int16

func GetNotZeroInt64IfExist

func GetNotZeroInt64IfExist(values ...int64) int64

func GetNotZeroInt8IfExist

func GetNotZeroInt8IfExist(values ...int8) int8

func GetNotZeroIntIfExist

func GetNotZeroIntIfExist(values ...int) int

func GetNotZeroUInt16IfExist

func GetNotZeroUInt16IfExist(values ...uint16) uint16

func GetNotZeroUInt64IfExist

func GetNotZeroUInt64IfExist(values ...uint64) uint64

func GetNotZeroUInt8IfExist

func GetNotZeroUInt8IfExist(values ...uint8) uint8

func GetNotZeroUIntIfExist

func GetNotZeroUIntIfExist(values ...uint) uint

func GetTrueBoolValueIfExist

func GetTrueBoolValueIfExist(values ...bool) bool

func IsCmdExist

func IsCmdExist(cmd string) bool

func IsFileMatchFileSize added in v2.9.0

func IsFileMatchFileSize(filePath string, fileSize int64) (match bool, err *data.CodeError)

func IsGBKEncoding

func IsGBKEncoding(encoding string) bool

func IsHostUnavailableError

func IsHostUnavailableError(err error) bool

func IsIPString

func IsIPString(host string) bool

func IsIPUrlString

func IsIPUrlString(host string) bool

func IsLocalFileMatchFileModifyTime added in v2.9.1

func IsLocalFileMatchFileModifyTime(filePath string, modifyTime int64) (match bool, err *data.CodeError)

func IsNetworkSource

func IsNetworkSource(filePath string) bool

func IsSignByEtagV2

func IsSignByEtagV2(etag string) bool

func IsWindowsOS

func IsWindowsOS() bool

func JsonDataTrimComments added in v2.9.1

func JsonDataTrimComments(data []byte) (data1 []byte)

func KeyFromUrl

func KeyFromUrl(uri string) (key string, err *data.CodeError)

KeyFromUrl 从URL中获取文件名字

func LocalFileModify added in v2.9.0

func LocalFileModify(filePath string) (int64, *data.CodeError)

func LocalFileSize

func LocalFileSize(filePath string) (int64, *data.CodeError)

func MarshalToFile added in v2.8.0

func MarshalToFile(filePath string, v interface{}) *data.CodeError

func Md5Hex

func Md5Hex(from string) string

字符串的md5值

func NetworkFileLength

func NetworkFileLength(srcResUrl string) (fileSize int64, err *data.CodeError)

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

加密解密需要数据一定的格式, 如果愿数据不符合要求,需要加一些padding

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

加密解密需要数据一定的格式, 如果愿数据不符合要求,需要加一些padding

func ParseEtag added in v2.10.0

func ParseEtag(etag string) string

func RemoveUrlScheme

func RemoveUrlScheme(url string) string

func RunCmd added in v2.9.0

func RunCmd(name string, params []string) (string, *data.CodeError)

func SimpleUnescape

func SimpleUnescape(s *string) string

func SplitString

func SplitString(line, sep string) []string

func UnMarshalFromFile

func UnMarshalFromFile(filePath string, v interface{}) *data.CodeError

func Unzip

func Unzip(zipFilePath string, unzipPath string) (err *data.CodeError)

func UserAgent

func UserAgent() string

生成客户端代理名称

Types

type NetworkFileInfo added in v2.10.0

type NetworkFileInfo struct {
	Size int64
	Hash string
}

func GetNetworkFileInfo added in v2.10.0

func GetNetworkFileInfo(srcResUrl string) (*NetworkFileInfo, *data.CodeError)

type Template added in v2.9.0

type Template struct {
	// contains filtered or unexported fields
}

func NewTemplate added in v2.9.0

func NewTemplate(templateString string) (*Template, *data.CodeError)

func (*Template) Run added in v2.9.0

func (t *Template) Run(param interface{}) (string, *data.CodeError)

func (*Template) RunWithJsonString added in v2.9.0

func (t *Template) RunWithJsonString(paramJson string) (string, *data.CodeError)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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