Documentation ¶
Overview ¶
Package com is an open source project for commonly used functions for the Go programming language.
Index ¶
- Constants
- Variables
- func AESDecrypt(key, text []byte) ([]byte, error)
- func AESEncrypt(key, text []byte) ([]byte, error)
- func AppendStr(strs []string, str string) []string
- func Base64Decode(str string) (string, error)
- func Base64Decode_(str string) ([]byte, error)
- func Base64Encode(str string) string
- func Base64Encode_(str []byte) string
- func BeBig(source, compare float64) bool
- func BeBigOrEqual(source, compare float64) bool
- func BeEqual(source, compare float64) bool
- func BeSmall(source, compare float64) bool
- func BeSmallOrEqual(source, compare float64) bool
- func BytesFormat(b int64) string
- func BytesParse(val string) (int64, error)
- func Camel2Underline(s string) string
- func ColorLog(format string, a ...interface{})
- func ColorLogS(format string, a ...interface{}) string
- func CompareSliceStr(s1, s2 []string) bool
- func CompareSliceStrU(s1, s2 []string) bool
- func Copy(src, dest string) error
- func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error
- func Date(ti int64, format string) string
- func DateParse(dateString, format string) (time.Time, error)
- func DateS(ts string, format string) string
- func DateT(t time.Time, format string) string
- func Decrypt3(key, src []byte) ([]byte, error)
- func DesDecrypt(src, key []byte) ([]byte, error)
- func DesDecryptIv(crypted, key, iv []byte) ([]byte, error)
- func DesEncrypt(src, key []byte) (string, error)
- func DesEncryptIv(origData, key, iv []byte) (string, error)
- func Encrypt3(key1 string, src []byte) (string, error)
- func EncryptDesECB(ori, key []byte) ([]byte, error)
- func ExecCmd(cmdName string, args ...string) (string, string, error)
- func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error)
- func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error)
- func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error)
- func ExecPath() (string, error)
- func Expand(template string, match map[string]string, subs ...string) string
- func FetchFiles(client *http.Client, files []RawFile, header http.Header) error
- func FetchFilesCurl(files []RawFile, curlOptions ...string) error
- func FileMTime(file string) (int64, error)
- func FileSize(file string) (int64, error)
- func Format10(time time.Time) string
- func Format10ToTimestamp(formatTime string) (int, error)
- func Format14(time time.Time) string
- func Format14ToTimestamp(formatTime string) (int, error)
- func Format17(time time.Time) string
- func Format17ToTimestamp(formatTime string) (int, error)
- func Format19(time time.Time) string
- func Format19ToTimestamp(formatTime string) (int, error)
- func Format8(time time.Time) string
- func Format8ToTimestamp(formatTime string) (int, error)
- func Generate() string
- func GetAllSubDirs(rootPath string) ([]string, error)
- func GetFileListBySuffix(dirPath, suffix string) ([]string, error)
- func GetGOPATHs() []string
- func GetNightTimestamp(day int) int
- func GetNowTime() time.Time
- func GetNowTimestamp() int
- func GetSrcPath(importPath string) (appPath string, err error)
- func GetTimeIntervalDay(day int) int
- func HexStr2int(hexStr string) (int, error)
- func HomeDir() (home string, err error)
- func Html2JS(data []byte) []byte
- func HtmlDecode(str string) string
- func HtmlEncode(str string) string
- func HttpCall(client *http.Client, method, url string, header http.Header, body io.Reader) (io.ReadCloser, error)
- func HttpGet(client *http.Client, url string, header http.Header) (io.ReadCloser, error)
- func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error)
- func HttpGetJSON(client *http.Client, url string, v interface{}) error
- func HttpGetToFile(client *http.Client, url string, header http.Header, fileName string) error
- func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error)
- func HttpPostJSON(client *http.Client, url string, body, v interface{}) error
- func HumaneFileSize(s uint64) string
- func If(condition bool, trueVal, falseVal interface{}) interface{}
- func Int2HexStr(num int) (hex string)
- func IntSliceDeduplication(ints []int) []int
- func Ints2Strings(src []int) []string
- func IsDir(dir string) bool
- func IsEmail(email string) bool
- func IsEmailRFC(email string) bool
- func IsExist(path string) bool
- func IsFile(filePath string) bool
- func IsLetter(l uint8) bool
- func IsSliceContainsInt64(sl []int64, i int64) bool
- func IsSliceContainsStr(sl []string, str string) bool
- func IsUrl(url string) bool
- func Md5(str string) string
- func Md5_16(str string) []byte
- func MysqlFilter(key string) string
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func Nl2br(str string) string
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PKCS7Padding(src []byte) []byte
- func PKCS7UnPadding(src []byte) ([]byte, error)
- func ParseInLocation(layout string, value string) (time.Time, error)
- func PasswordEncrypt(account, password string) string
- func PowInt(x int, y int) int
- func RandomCreateBytes(n int, alphabets ...byte) []byte
- func RandomString(length uint8, charsets ...string) string
- func Reverse(s string) string
- func Round(f float64, n int) float64
- func Sha256(str string) string
- func StatDir(rootPath string, includeDir ...bool) ([]string, error)
- func Strings2Ints(src []string) (dst []int, err error)
- func Strings2IntsAsc(src []string) (dst []int, err error)
- func StripTags(src string) string
- func SubString(str string, begin, length int) string
- func SubstrByByte(str string, length int) string
- func TimeIntervalDay(t1, t2 time.Time) int
- func TimeIntervalSecond(time1 time.Time, time2 time.Time) int
- func TimeSub(t1, t2 time.Time) int
- func ToFixed(l float64, n float64) float64
- func ToFixed10K(l float64) float64
- func ToStr(value interface{}, args ...int) (s string)
- func Underline2Camel(s string) string
- func UrlDecode(str string) (string, error)
- func UrlEncode(str string) string
- func WriteFile(filename string, data []byte, perm os.FileMode) error
- func ZeroPadding(ciphertext []byte, blockSize int) []byte
- func ZeroUnPadding(origData []byte) []byte
- type Bytes
- type NotFoundError
- type Random
- type RawFile
- type RemoteError
- type StrTo
- func (f StrTo) Exist() bool
- func (f StrTo) Float32() (float32, error)
- func (f StrTo) Float64() (float64, error)
- func (f StrTo) Int() (int, error)
- func (f StrTo) Int64() (int64, error)
- func (f StrTo) MustInt() int
- func (f StrTo) MustInt64() int64
- func (f StrTo) MustUint8() uint8
- func (f StrTo) String() string
- func (f StrTo) Uint8() (uint8, error)
Constants ¶
const ( B = 1 << (10 * iota) KB MB GB TB PB EB )
const ( Gray = uint8(iota + 90) Red Green Yellow Blue Magenta //NRed = uint8(31) // Normal EndColor = "\033[0m" )
Color number constants.
const ( Byte = 1 KByte = Byte * 1024 MByte = KByte * 1024 GByte = MByte * 1024 TByte = GByte * 1024 PByte = TByte * 1024 EByte = PByte * 1024 )
Storage unit constants.
const ( Uppercase string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Lowercase = "abcdefghijklmnopqrstuvwxyz" Alphabetic = Uppercase + Lowercase Numeric = "0123456789" Alphanumeric = Alphabetic + Numeric Symbols = "`" + `~!@#$%^&*()-_+={}[]|\;:"<>,./?` Hex = Numeric + "abcdef" )
Charsets
const ( LAYOUT_FORMAT19 = "2006-01-02 15:04:05" LAYOUT_FORMAT14 = "20060102150405" LAYOUT_FORMAT10 = "2006-01-02" LAYOUT_FORMAT8 = "20060102" LAYOUT_FORMAT17 = "20060102 15:04:05" )
const (
ACCURACY = 0.00001 //精度
)
const (
UNDERLINE = "_"
)
Variables ¶
var UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1541.0 Safari/537.36"
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts text and given key with AES.
func AESEncrypt ¶
AESEncrypt encrypts text and given key with AES.
func BytesParse ¶
Parse wraps global Bytes's Parse function.
func Camel2Underline ¶
camel2Underline:snake string, XxYy to xx_yy , XxYY to xx_yy
func ColorLog ¶
func ColorLog(format string, a ...interface{})
ColorLog prints colored log to stdout. See color rules in function 'ColorLogS'.
func ColorLogS ¶
ColorLogS colors log and return colored content. Log format: <level> <content [highlight][path]> [ error ]. Level: TRAC -> blue; ERRO -> red; WARN -> Magenta; SUCC -> green; others -> default. Content: default; path: yellow; error -> red. Level has to be surrounded by "[" and "]". Highlights have to be surrounded by "# " and " #"(space), "#" will be deleted. Paths have to be surrounded by "( " and " )"(space). Errors have to be surrounded by "[ " and " ]"(space). Note: it hasn't support windows yet, contribute is welcome.
func CompareSliceStr ¶
CompareSliceStr compares two 'string' type slices. It returns true if elements and order are both the same.
func CompareSliceStrU ¶
CompareSliceStr compares two 'string' type slices. It returns true if elements are the same, and ignores the order.
func CopyDir ¶
CopyDir copy files recursively from source to target directory.
The filter accepts a function that process the path info. and should return true for need to filter.
It returns error when error occurs in underlying functions.
func DateT ¶
Format time.Time struct to string MM - month - 01 M - month - 1, single bit DD - day - 02 D - day 2 YYYY - year - 2006 YY - year - 06 HH - 24 hours - 03 H - 24 hours - 3 hh - 12 hours - 03 h - 12 hours - 3 mm - minute - 04 m - minute - 4 ss - second - 05 s - second = 5
func DesDecrypt ¶
func DesDecryptIv ¶
func DesEncrypt ¶
func DesEncryptIv ¶
func ExecCmd ¶
ExecCmd executes system command and return stdout, stderr in string type, along with possible error.
func ExecCmdBytes ¶
ExecCmdBytes executes system command and return stdout, stderr in bytes type, along with possible error.
func ExecCmdDir ¶
ExecCmdDir executes system command in given directory and return stdout, stderr in string type, along with possible error.
func ExecCmdDirBytes ¶
ExecCmdDirBytes executes system command in given directory and return stdout, stderr in bytes type, along with possible error.
func FetchFiles ¶
FetchFiles fetches files specified by the rawURL field in parallel.
func FetchFilesCurl ¶
FetchFiles uses command `curl` to fetch files specified by the rawURL field in parallel.
func Format10ToTimestamp ¶
Format10ToTimestamp 格式化的时间(YYYY-MM-DD)转时间戳
func Format14ToTimestamp ¶
Format14ToTimestamp 格式化的时间(YYYYMMDDHHmmss)转时间戳
func Format17ToTimestamp ¶
Format17ToTimestamp 格式化的时间(YYYYMMDD HH:mm:ss)转时间戳
func Format19ToTimestamp ¶
Format19ToTimestamp 格式化的时间(YYYY-MM-DD HH:mm:ss)转时间戳
func Format8ToTimestamp ¶
Format8ToTimestamp 格式化的时间(YYYYMMDD)转时间戳
func GetAllSubDirs ¶
GetAllSubDirs returns all subdirectories of given root path. Slice does not include given path itself.
func GetFileListBySuffix ¶
GetFileListBySuffix returns an ordered list of file paths. It recognize if given path is a file, and don't do recursive find.
func GetNightTimestamp ¶
GetNightTimestamp 获取前一天的时间戳:day = -1 , 获取今天晚上的时间戳:0 ,获取明天的凌晨时间戳:1
func GetSrcPath ¶
GetSrcPath returns app. source code path. It only works when you have src. folder in GOPATH, it returns error not able to locate source folder path.
func GetTimeIntervalDay ¶
GetTimeIntervalDay 与当前时间的时间间隔 单位天 如 GetTimeIntervalDay(1) 为延后一天
func HexStr2int ¶
HexStr2int converts hex format string to decimal number.
func HomeDir ¶
HomeDir returns path of '~'(in Linux) on Windows, it returns error when the variable does not exist.
func HttpCall ¶
func HttpCall(client *http.Client, method, url string, header http.Header, body io.Reader) (io.ReadCloser, error)
HttpCall makes HTTP method call.
func HttpGet ¶
HttpGet gets the specified resource. ErrNotFound is returned if the server responds with status 404.
func HttpGetBytes ¶
HttpGetBytes gets the specified resource. ErrNotFound is returned if the server responds with status 404.
func HttpGetJSON ¶
HttpGetJSON gets the specified resource and mapping to struct. ErrNotFound is returned if the server responds with status 404.
func HttpGetToFile ¶
HttpGetToFile gets the specified resource and writes to file. ErrNotFound is returned if the server responds with status 404.
func HttpPost ¶
func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error)
HttpPost posts the specified resource. ErrNotFound is returned if the server responds with status 404.
func HttpPostJSON ¶
HttpPostJSON posts the specified resource with struct values, and maps results to struct. ErrNotFound is returned if the server responds with status 404.
func HumaneFileSize ¶
HumaneFileSize calculates the file size and generate user-friendly string.
func Int2HexStr ¶
Int2HexStr converts decimal number to hex format string.
func IntSliceDeduplication ¶
IntSliceDeduplication int的切片去重复
func IsDir ¶
IsDir returns true if given path is a directory, or returns false when it's a file or does not exist.
func IsEmail ¶
validate string is an email address, if not return false basically validation can match 99% cases
func IsEmailRFC ¶
validate string is an email address, if not return false this validation omits RFC 2822
func IsExist ¶
IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.
func IsFile ¶
IsFile returns true if given path is a file, or returns false when it's a directory or does not exist.
func IsSliceContainsInt64 ¶
IsSliceContainsInt64 returns true if the int64 exists in given slice.
func IsSliceContainsStr ¶
IsSliceContainsStr returns true if the string exists in given slice, ignore case.
func IsUrl ¶
validate string is a url link, if not return false simple validation can match 99% cases
func MysqlFilter ¶
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func PKCS7Padding ¶
PKCS7Padding pads as prescribed by the PKCS7 standard
func PKCS7UnPadding ¶
PKCS7UnPadding unpads as prescribed by the PKCS7 standard
func ParseInLocation ¶
ParseInLocation 根据格式解析格式化为字符串的的时间
func RandomCreateBytes ¶
RandomCreateBytes generate random []byte by specify chars.
func RandomString ¶
func StatDir ¶
StatDir gathers information of given directory by depth-first. It returns slice of file list and includes subdirectories if enabled; it returns error and nil slice when error occurs in underlying functions, or given path is not a directory or does not exist.
Slice does not include given path itself. If subdirectories is enabled, they will have suffix '/'.
func Strings2IntsAsc ¶
[]string 转 []int 排序从小到大
func TimeIntervalSecond ¶
TimeIntervalSecond 两个时间相隔秒数
func Underline2Camel ¶
underline2Camel camel string, xx_yy to XxYy 大驼峰
func WriteFile ¶
WriteFile writes data to a file named by filename. If the file does not exist, WriteFile creates it and its upper level paths.
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type Bytes ¶
type Bytes struct { }
type NotFoundError ¶
type NotFoundError struct {
Message string
}
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type RemoteError ¶
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string