utils

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KC_RAND_KIND_NUM   = 0 // 纯数字
	KC_RAND_KIND_LOWER = 1 // 小写字母
	KC_RAND_KIND_UPPER = 2 // 大写字母
	KC_RAND_KIND_ALL   = 3 // 数字、大小写字母
)
View Source
const (
	STR_PAD_LEFT int = iota
	STR_PAD_RIGHT
	STR_PAD_BOTH
)
View Source
const (
	DefaultDateFormat     = "2006-01-02"
	DefaultDatetimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var ErrNil = errors.New("nil or type error")

数据类型转换

Functions

func CamelCase added in v0.0.6

func CamelCase(s string) string

CamelCase 将一个字符串转为大驼峰命名

func CamelCaseInitialism added in v0.0.6

func CamelCaseInitialism(s string) string

CamelCaseInitialism 将一个字符串转为大驼峰命名,强制首字母缩写命名规范

func Concat added in v0.0.6

func Concat(args ...string) string

Concat 连接字符串

func CopyFile added in v0.0.6

func CopyFile(s, d string) error

CopyFile copy source file to destination file

func DateToTime added in v0.0.6

func DateToTime(date string) int64

日期字符串转时间戳

func ExecShell

func ExecShell(s string) (string, error)

调用shell脚本执行

func FilterSpace added in v0.0.6

func FilterSpace(s string) string

过滤换行和空格

func Float64

func Float64(reply interface{}) (float64, error)

func GetExt added in v0.0.6

func GetExt(file string) string

GetExt get file extenstion, not contains dot

func Getenv

func Getenv(key string, args ...string) string

returns a non-empty env, or the default

func Glob added in v0.0.6

func Glob(base, pattern string, abs bool) ([]string, error)

Glob 查找指定目录下的文件列表

func HTTPAuthDownload added in v0.0.6

func HTTPAuthDownload(uri, save, user, passwd string, timeout int64) error

basic auth download

func HTTPAuthDownloadWithHeader added in v0.0.6

func HTTPAuthDownloadWithHeader(uri, save, user, passwd string, timeout int64, headers map[string]string) error

basic auth download

func HTTPAuthGet added in v0.0.6

func HTTPAuthGet(uri string, user, passwd string, timeout int64) ([]byte, error)

func HTTPAuthPostForm added in v0.0.6

func HTTPAuthPostForm(uri string, data url.Values, user, passwd string, timeout int64) ([]byte, error)

func HTTPAuthPostJSON added in v0.0.6

func HTTPAuthPostJSON(uri string, body []byte, user, passwd string, timeout int64, isGzip bool) ([]byte, error)

func HTTPDownload added in v0.0.6

func HTTPDownload(uri, path string) (int, error)

HTTPDownload HTTP下载文件

func HTTPGet added in v0.0.6

func HTTPGet(uri string, timeout int) ([]byte, error)

HTTPGet 带超时设置的请求一个url,单位: 秒

func HTTPPostFile added in v0.0.6

func HTTPPostFile(uri string, params map[string]string, cookie string, timeout int) ([]byte, http.Header, error)

HTTPPostFile 使用POST上传文件,超时 单位:秒 在参数中,如果要上传文件,设 params[file]=@/data/upload/1.zip 即可,注意 @ 符号

func HTTPPostJSON added in v0.0.6

func HTTPPostJSON(uri string, params interface{}, timeout int) ([]byte, error)

HTTPPostJSON 使用POST JSON方式请求数据,超时 单位:秒

func HTTPRangeDownload added in v0.0.6

func HTTPRangeDownload(uri, path string, process chan<- float64) (int64, error)

HTTPRangeDownload HTTP断点续传下载文件,提供下载进度,通过 range process得到进度条

func InSlice added in v0.0.6

func InSlice(si interface{}, s interface{}, t string) bool

InSlice 判断元素s是否在slice si中出现过,返回 bool

func Int

func Int(reply interface{}) (int, error)

func Int64

func Int64(reply interface{}) (int64, error)

func IntToString added in v0.0.6

func IntToString(i int) string

IntToString 将数字转换为字符串

func IsExist added in v0.0.6

func IsExist(path string) bool

IsExist check path is exists, exist return true, not exist return false

func IsFile added in v0.0.6

func IsFile(filename string) bool

判断是否文件

func IsNumeric added in v0.0.6

func IsNumeric(s string) bool

IsNumeric 判断是否是纯数字,空字符串不是数字,0才是

func JsonEncode

func JsonEncode(obj interface{}) (string, error)

json化,但不转义字符

func MD5

func MD5(str string) string

MD5 checksum for str

func MD5File

func MD5File(filepath string) string

MD5File checksum for file path

func MaskEmail added in v0.0.6

func MaskEmail(email string, masks ...string) string

MaskEmail 使用指定字符遮罩邮箱

func MaskMobile added in v0.0.6

func MaskMobile(mobile string, masks ...string) string

MaskMobile 使用指定字符遮罩手机号

func MaskString added in v0.0.6

func MaskString(str string, masks ...string) string

MaskString 使用指定字符遮罩字符串

func MixedToSliceInt added in v0.0.6

func MixedToSliceInt(v interface{}) []int

MixedToSliceInt 将混合类型转为 数字slice

func MixedToSliceString added in v0.0.6

func MixedToSliceString(v interface{}) []string

MixedToSliceString 将混合类型转为 字符串slice

func MkdirAll added in v0.0.6

func MkdirAll(path string) error

MkdirAll check the path isexist or mkdir, and check writable

func MtRand

func MtRand(m ...int) int

生成随机数

func MustFloat64

func MustFloat64(v interface{}) float64

MustFloat64 转换值为 float64 类型

func MustInt

func MustInt(v interface{}) int

MustInt 转换值为 int 类型

func MustInt64

func MustInt64(v interface{}) int64

MustInt64 转换值为 int64 类型

func PowerShell

func PowerShell(args ...string) (string, error)

func RandFileName

func RandFileName() string

RandFileName 随机生成一个文件名

func RandRangeNumber

func RandRangeNumber(min, max int) int

获取起止范围内随机数

func RandStr

func RandStr(size int, kind int) []byte

随机字符串

func ReadDir added in v0.0.6

func ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir read path return files by os.FileInfo

func ReadFile added in v0.0.6

func ReadFile(file string) ([]byte, error)

ReadFile read file content

func Remove added in v0.0.6

func Remove(filename string) error

删除文件

func SliceIntDiff added in v0.0.6

func SliceIntDiff(a []int, b []int) []int

SliceIntDiff 获取在数字切片 a 中但不在数字切片 b 中的差集

func SliceIntEqual added in v0.0.6

func SliceIntEqual(a, b []int) bool

SliceIntEqual 判断两个数字切片中的内容是否相同,忽略元素的排序 [1,2,3] == [3,2,1]

func SliceIntRand added in v0.0.6

func SliceIntRand(a []int) []int

SliceIntRand 将切片顺序打乱随机返回

func SliceIntToString added in v0.0.6

func SliceIntToString(a []int) []string

SliceIntToString 将数字切片转换为字符串切片 [11,22,33] 转换为 ["11","22","33"]

func SliceInterfaceRand added in v0.0.6

func SliceInterfaceRand(a []interface{}) []interface{}

SliceInterfaceRand 将切片顺序打乱随机返回

func SliceStringDiff added in v0.0.6

func SliceStringDiff(a []string, b []string) []string

SliceStringDiff 获取在字符串切片 a 中但不在字符串切片 b 中的差集

func SplitStringToSlice added in v0.0.6

func SplitStringToSlice(s string, sep string) []string

SplitStringToSlice 将字符串分割成数组,并去除空行

func StrNatCut added in v0.0.6

func StrNatCut(s string, length int, dot ...string) string

StrNatCut 字符串截取,中文算一个 英文算两个

func StrPad added in v0.0.6

func StrPad(v interface{}, length int, pad string, padType int) string

StrPad 使用另一个字符串填充字符串为指定长度

func String

func String(reply interface{}) (string, error)

func StringToInt added in v0.0.6

func StringToInt(s string) int

StringToInt 将字符串转为int

func StringToInt64 added in v0.0.6

func StringToInt64(s string) int64

StringToInt64 将字符串转为int64

func StringToTime added in v0.0.12

func StringToTime(str string) time.Time

string to time

func TimeToDate added in v0.0.6

func TimeToDate(timestamp int64, params ...string) string

时间戳转日期/时间,可传递格式化字符串

func TimeToDateInt added in v0.0.6

func TimeToDateInt(timestamp int64, params ...string) int

时间戳转日期int

func ToString added in v0.0.6

func ToString(v interface{}) string

ToString 将任意一个类型转换为字符串

func WriteFile added in v0.0.6

func WriteFile(file string, body []byte) (int, error)

WriteFile read content to the file

Types

This section is empty.

Jump to

Keyboard shortcuts

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