Documentation ¶
Index ¶
- Constants
- Variables
- func Byte8(s []byte) []byte
- func Bytes2I(b [8]byte) uint64
- func Bytes2IAuto(b []byte) uint64
- func BytesToFloat64(bytes []byte) (data float64, err error)
- func CharCount(str string) int
- func Contain(tar interface{}, container interface{}) (bool, error)
- func ContainByte(tar byte, container ...byte) bool
- func ContainFloat32(tar float32, container ...float32) bool
- func ContainFloat64(tar float64, container ...float64) bool
- func ContainInt(tar int, container ...int) bool
- func ContainInt32(tar int32, container ...int32) bool
- func ContainInt64(tar int64, container ...int64) bool
- func ContainMust(tar interface{}, container interface{}) bool
- func ContainString(tar string, container ...string) bool
- func Convert2AnyTypeSlice(slice interface{}) ([]interface{}, error)
- func Create(name string) (*os.File, error)
- func Dir(fp string) string
- func DirsUnder(dirPath string) ([]string, error)
- func DistinctBytes(tar byte, container ...byte) bool
- func DistinctFloat32s(tar float32, container ...float32) bool
- func DistinctFloat64s(tar float64, container ...float64) bool
- func DistinctInt32s(tar int32, container ...int32) bool
- func DistinctInt64s(tar int64, container ...int64) bool
- func DistinctInts(tar int, container ...int) bool
- func DistinctStrings(tar string, container ...string) bool
- func EnsureDirRW(dataDir string) error
- func Ext(fp string) string
- func FileEmpty(name string) bool
- func FileExists(filename string) bool
- func FileMTime(fp string) (int64, error)
- func FileSize(fp string) (int64, error)
- func FilesUnder(dirPath string) ([]string, error)
- func FindProjectAbs() (string, error)
- func Float64Precision(f float64, precision int, round bool) float64
- func Float64ToBytes(input float64) []byte
- func Float64ToStr(num float64, precision int) string
- func GetRandomOne(arr interface{}) interface{}
- func HasAny(src string, sub ...string) bool
- func I2Bytes(v uint64) []byte
- func InsureDir(fp string) error
- func Is400(str string) bool
- func IsChineseCharacter(str string) bool
- func IsEmail(str string) bool
- func IsExist(fp string) bool
- func IsFile(fp string) bool
- func IsFloat(str string) bool
- func IsHMS(str string) bool
- func IsHMS_APM(str string) bool
- func IsIP(str string) bool
- func IsNumber(str string) bool
- func IsPhone(str string) bool
- func IsSlice(o interface{}) (val reflect.Value, ok bool)
- func IsSpecialSymbols(str string) bool
- func IsTel(str string) bool
- func IsYMD(str string) bool
- func IsYMDHMS(str string) bool
- func JoinByte(arr []byte, splitter ...string) string
- func JoinInt(arr []int, splitter ...string) string
- func JoinInt32(arr []int32, splitter ...string) string
- func JoinInt64(arr []int64, splitter ...string) string
- func Json(o interface{}) string
- func JsonPretty(o interface{}) string
- func Logf(s string, args ...interface{})
- func MapToStruct(obj map[string]interface{}, data interface{}) (interface{}, error)
- func MatchAny(src string, tars ...string) bool
- func MatchString(pattern, input string) (bool, error)
- func Name(fp string) string
- func OpenFile(filename string) (*os.File, error)
- func ParseDate(s string) time.Time
- func ParseTime(s string) time.Time
- func Pascal(title string) string
- func RFC3339(value interface{}) error
- func RandInt(n int) int
- func RandInt64(n int64) int64
- func RandIntX(n int) intdeprecated
- func RandNumStr(n int) string
- func RandPassword(n int) string
- func RandScopeInt(m, n int) int
- func RandSequence(n int) string
- func RandString(n int) string
- func RangeStringsFunc(arr []string, f func(string) string)
- func RangeToTitle(arr []string)
- func ReadFile(path string) string
- func RealPath(fp string) (string, error)
- func Register(pattern string) (*regexp.Regexp, error)
- func Remove(name string) error
- func Rename(src string, target string) error
- func ReplaceAllString(pattern, input, repl string) (string, error)
- func ReverseBytes(arr ...int)
- func ReverseFloat32s(arr ...int)
- func ReverseFloat64s(arr ...int)
- func ReverseInt32s(arr ...int)
- func ReverseInt64s(arr ...int)
- func ReverseInts(arr ...int)
- func ReverseStrings(arr ...int)
- func SQLInInt(items ...int) (inSql string)
- func SQLInInt32(items ...int32) (inSql string)
- func SQLInInt64(items ...int64) (inSql string)
- func SQLInString(items ...string) (inSql string)
- func SearchFile(filename string, paths ...string) (fullPath string, err error)
- func SearchFileWithAffix(dirPath, prefix, suffix string) (fullPath string, exist bool)
- func SelfDir() string
- func SelfPath() string
- func StrToFloat64(str string, precision int) float64
- func StrToFloat64Round(str string, precision int, round bool) float64
- func StringsRemove(ss []string, s string) []string
- func StringsToInts(ss []string) (ints []int, err error)
- func StringsToSlice(strings []string) []interface{}
- func StructToMap(obj interface{}) map[string]interface{}
- func Time1970() time.Timedeprecated
- func ToBool(b string) bool
- func ToInt(n string) (ret int)
- func ToInt64(num string) int64
- func TrimSpace(str string) string
- func TrimStrings(ss []string, cutSet ...string) (ns []string)
- type JsonTime
- type Loggerx
- type Once
Examples ¶
Constants ¶
const ( NumberSymbol = "0123456789" LetterSymbol = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" PassSymbol = "!@#$%^&*()[]{}+-*/_=." )
const ( DefaultDateLayout = "2006-01-02" DefaultTimeLayout = "2006-01-02 15:04:05" )
const BLANK = ""
Variables ¶
var ( ErrNotFound = errors.New("not found") // 未找到资源 ErrParam = errors.New("param error") // 参数错误 ErrAuth = errors.New("auth error") // 鉴权失败 ErrIllegalUser = errors.New("illegal user") // 非法用户(跨账号操作等) ErrCSRFFail = errors.New("CSRF invalid") // 跨站请求失败 ErrForbidden = errors.New("forbidden") // 无权操作 ErrNetwork = errors.New("network error") // 网络错误 ErrRepeatRequest = errors.New("repeat request") // 重复请求(非幂等) ErrOutdatedVer = errors.New("outdated version") // 版本过期/不兼容 ErrFileData = errors.New("file data error") // 文件格式/编码错误 ErrFileSize = errors.New("file size error") // 文件尺寸错误 ErrUploadFailed = errors.New("upload failed") // 文件上传失败 ErrGateway = errors.New("gateway error") // 网关错误 ErrServer = errors.New("server error") // 服务错误 ErrServerTimeout = errors.New("server timeout") // 服务处理超时 ErrInMaintenance = errors.New("in maintenance") // 系统维护中 ErrDataOperation = errors.New("data operation failed") // 数据(库)处理错误 )
var ( ErrUnsupportedInputType = errors.New("unsupported input type") ErrInvalidFormatRFC3339 = errors.New("must comply with RFC3339") )
var ERR_BYTES_INVALILD = errors.New("BytesToFloat64 bytes invalid")
ERR_BYTES_INVALILD
var ERR_NEED_NUMERIC = errors.New("ToInt64 need numeric")
ERR_NEED_NUMERIC
var Logger *log.Logger
Functions ¶
func Byte8 ¶
Byte8 将给定的切片转换为[8]byte类型
说明: 使用copy(to,from)函数自由填充目标切片或数组,如: n:=copy(arr,slice) 或 n:=copy(slice,arr)
Example ¶
fmt.Println(Byte8([]byte{'a', 'b', 'c'})) fmt.Println(Byte8([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9})) // out: // [97 98 99 0 0 0 0 0] // [1 2 3 4 5 6 7 8]
Output:
func BytesToFloat64 ¶
BytesToFloat64 convert bytes to float64
func CharCount ¶
CharCount 统计字符个数
与javascript中的string.length一致
Example ¶
str := "Hello, 世界" fmt.Println("bytes =", len(str)) fmt.Println("runes =", CharCount(str))
Output: bytes = 13 runes = 9
func Contain ¶
目标元素tar是否包含在container集合中,container必须是切片类型
如:Contain(1,[]int{1,2,3}) Contain(u,[]User{u1,u2,u3}) Contain(&u,[]*User{&u1,&u2,&u3}) Contain(1.0, []interface{}{1.0,"a",'b'})
func ContainFloat32 ¶
目标元素tar是否包含在container集合中
func ContainFloat64 ¶
目标元素tar是否包含在container集合中
func ContainMust ¶
func ContainMust(tar interface{}, container interface{}) bool
同Contain,但需手动处理panic
func ContainString ¶
目标元素tar是否包含在container集合中
func Convert2AnyTypeSlice ¶
func Convert2AnyTypeSlice(slice interface{}) ([]interface{}, error)
Convert2AnyTypeSlice 将对象切片转换为接口切片
如: AnyTypeSlice([]int{1,2,3}) => []interface{}{1,2,3}
func DistinctFloat32s ¶
目标元素tar是否包含在container集合中
func DistinctFloat64s ¶
目标元素tar是否包含在container集合中
func DistinctInt32s ¶
目标元素tar是否包含在container集合中
func DistinctInt64s ¶
目标元素tar是否包含在container集合中
func DistinctStrings ¶
目标元素tar是否包含在container集合中
func EnsureDirRW ¶
EnsureDirRW ensure the datadir and make sure it's rw-able
func Ext ¶
Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.
func FileExists ¶
func FilesUnder ¶
FilesUnder list files under dirPath
func FindProjectAbs ¶
FindProjectAbs find absolute path that have go.mod in parent folder.
func Float64Precision ¶
Float64Precision float指定精度; round为true时, 表示支持四舍五入
func Float64ToBytes ¶
Float64ToBytes convert float64 to bytes; []uint8
func Float64ToStr ¶
Float64ToStr convert float64 to string 支持指定精度
func GetRandomOne ¶
func GetRandomOne(arr interface{}) interface{}
GetRandomOne get random element from an array/slice
func HasAny ¶
HasAny raw中是否包含sub...中的任意子串
如: HasSub("datetime","date") => true HasSub("datetime","time") => true
func IsExist ¶
IsExist checks whether a file or directory exists It returns false when the file or directory does not exist.
func IsFile ¶
IsFile checks whether the path is a file, it returns false when it's a directory or does not exist.
func MapToStruct ¶
MapToStruct map obj to struct data
func MatchString ¶
MatchString returns true if current string match the pattern, false otherwise.
func ParseDate ¶
ParseDate 日前转换 (推荐使用 time.ParseInLocation)
将"2006-01-02"格式的字符串转换为时间. 参数错误时返回 1970-01-01(08:00:00GMT).
func ParseTime ¶
ParseTime 时间转换 (推荐使用 time.ParseInLocation)
将"2006-01-02 15:04:05"格式的字符串转换为时间. 参数错误时返回 1970-01-01(08:00:00GMT).
func RFC3339 ¶
func RFC3339(value interface{}) error
RFC3339 validates input is compliance with RFC3339
func RandSequence ¶
RandSequence 带有时间序列的随机数字串,即14位时间字符+N个随机字符, 如:20060102150405+99999
func RangeStringsFunc ¶
RangeStringsFunc 遍历处理集合成员
func Register ¶
Register creates a new regex from pattern it has not been created at least once yet.
func ReplaceAllString ¶
ReplaceAllString returns a copy of input, replacing matches of the Regexp with the replacement string repl. Inside repl, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match.
func ReverseStrings ¶
func ReverseStrings(arr ...int)
倒序翻转(string), 如:["a","r","e"] => ["e","r","a"]
func SearchFile ¶
Search a file in the give paths. this is often used in search config file in /etc ~/
func SearchFileWithAffix ¶
func StrToFloat64 ¶
StrToFloat64 convert string to float64, supported the given precision
func StrToFloat64Round ¶
StrToFloat64Round convert string to float64, supported the given precision and round
func StringsRemove ¶
StringsRemove a value form a string slice
func StringsToInts ¶
StringsToInts string slice to int slice
func StringsToSlice ¶
func StringsToSlice(strings []string) []interface{}
StringsToSlice convert []string to []interface{}
func StructToMap ¶
func StructToMap(obj interface{}) map[string]interface{}
StructToMap struct convert to map
func ToBool ¶
ToBool 将字符串转换为bool类型,参数错误时返回false
1,t,T,TRUE, true, True => true 0,f,F,FALSE,false,False => false
func TrimStrings ¶
TrimStrings trim string slice item.
Usage:
// output: [a, b, c] ss = arrutil.TrimStrings([]string{",a", "b.", ",.c,"}, ",.")
Types ¶
type Loggerx ¶
type Loggerx interface { Trace(requestID string, fields map[string]interface{}, message string) Debug(requestID string, fields map[string]interface{}, message string) Info(requestID string, fields map[string]interface{}, message string) Warn(requestID string, err error, fields map[string]interface{}, message string) Error(requestID string, err error, fields map[string]interface{}, message string) Fatal(requestID string, err error, fields map[string]interface{}, message string) }
type Once ¶
type Once struct {
// contains filtered or unexported fields
}
Once is an object that will perform exactly one action until Reset is called. See http://golang.org/pkg/sync/#Once
func (*Once) Do ¶
func (o *Once) Do(f func())
Do simulates sync.Once.Do by executing the specified function only once, until Reset is called. See http://golang.org/pkg/sync/#Once
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bitset implements bitsets, a mapping between non-negative integers and boolean values.
|
Package bitset implements bitsets, a mapping between non-negative integers and boolean values. |
Package color 精简快捷的彩色字体工具包(Linux版本)
|
Package color 精简快捷的彩色字体工具包(Linux版本) |
Package money 货币单位/换算
|
Package money 货币单位/换算 |
pkg
|
|
srcimporter
Package srcimporter implements importing directly from source files rather than installed packages.
|
Package srcimporter implements importing directly from source files rather than installed packages. |
Package rat:实验鼠
|
Package rat:实验鼠 |
Package zero 类型缺省值
|
Package zero 类型缺省值 |