utils

package module
v0.0.0-...-873084b Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2016 License: MIT Imports: 32 Imported by: 0

README

utils

golang 常用工具

Documentation

Index

Constants

View Source
const TIME_LAYOUT_OFTEN = "2006-01-02 15:04:05"

Variables

View Source
var (
	MaxDepth = 32
)

Functions

func AesDecode

func AesDecode(src []byte) ([]byte, error)

AES解码

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEncode

func AesEncode(src []byte) ([]byte, error)

AES编码

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func Array2String

func Array2String(array []string) string

将数组转换为字符串,英文逗号分隔

func ArrayInt2String

func ArrayInt2String(array []int64) string

将数组转换为字符串,英文逗号分隔

func Base64Decode

func Base64Decode(src string) ([]byte, error)

Base64解码

func Base64Encode

func Base64Encode(src []byte) string

Base64编码

func ClearDir

func ClearDir(dir string) bool

清空dir下所有的文件和文件夹 RemoveAll会清空本文件夹, 所以还要创建之

func Date

func Date(t time.Time, format string) string

Date takes a PHP like date func to Go's time format.

func DateFormat

func DateFormat(t time.Time, layout string) (datestring string)

func DateLocal

func DateLocal() time.Time

返回当前时区的当前时间

func DateParse

func DateParse(dateString, format string) (time.Time, error)

Parse Date use PHP time format.

func DateTime2String

func DateTime2String(dt time.Time) string

把指定的时间转换为字符串

func DirExists

func DirExists(path string) bool

文件夹是否存在

func ExecSystem

func ExecSystem(s string)

func FileSize

func FileSize(size int) string

文件大小

func GBKToUtf8

func GBKToUtf8(str string) string

gbk转utf-8

func GetAppRoot

func GetAppRoot() string

当前应用的绝对路径

func GetDateAsDirName

func GetDateAsDirName() string

以时间作为文件夹目录

func GetDateYYYYMMDD

func GetDateYYYYMMDD() string

以时间作为文件夹目录

func GetDir

func GetDir(path string) error

检查文件夹是否存在,如果不存在,则创建一个新文件夹

func GetEnv

func GetEnv(key string, def ...string) string

获取系统变量,如果没有设置就用默认值

func GetExecFuncId

func GetExecFuncId(key ...interface{}) (Id string)

返回调用此方法的方法名及key值,组合为缓存用的Key

func GetFilename

func GetFilename(path string) string

func GetFilesize

func GetFilesize(path string) int64

file size length in bytes

func Html2str

func Html2str(html string) string

Html过滤

func Int2str

func Int2str(i int) string

整形转字符串

func IpInt2String

func IpInt2String(ipint int64) string

将十进制IP转换为IPv4地址样式

func IpString2Int64

func IpString2Int64(ipstr string) int64

Ip地址字符串转换为十进制

func IsDir

func IsDir(path string) bool

是否目录

func IsEmail

func IsEmail(email string) bool

是否是email

func IsFile

func IsFile(path string) bool

是否文件

func IsMap_String_String

func IsMap_String_String(obj interface{}) bool

/检测是否为map[string]string类型

func IsUsername

func IsUsername(username string) bool

是否只包含数字, 字母 -, _

func ListContains

func ListContains(list []interface{}, key interface{}) (finded bool)

列表是否包含给定项

func ListDir

func ListDir(dir string) []string

list dir's all file, return filenames

func LoadJsonFile

func LoadJsonFile(filePath string) (map[string]interface{}, error)

load json file to a map

func MD5

func MD5(s string) string

md5加密

func MD5Ex

func MD5Ex(s string) string

加盐强密码

func MD5byte

func MD5byte(s string) []byte

func MakeDirAll

func MakeDirAll(path string, perm os.FileMode) error

按路径创建文件夹

func MapIntKeys

func MapIntKeys(data map[int]int) []int

获取map的key,返回所有key组成的slice

func MapKeys

func MapKeys(data map[string]interface{}) []string

获取map的key,返回所有key组成的slice

func MapToStruct

func MapToStruct(m map[string]interface{}, s interface{})

map & struct convert is from https://github.com/sdegutis/go.mapstruct convert map to struct

func Merge

func Merge(dst, src map[string]interface{}) map[string]interface{}

Merge recursively merges the src and dst maps. Key conflicts are resolved by preferring src, or recursively descending, if both src and dst are maps.

func NewGuid

func NewGuid() string

Guid

func NewGuidWith

func NewGuidWith(str string) string

后面加个str生成之, 更有保障, 确保唯一

func PKCS5Padding

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

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func Print

func Print(ob interface{})

func RandomInt

func RandomInt(min int, max int) int

生成随机数字

func RandomInt64

func RandomInt64(min int, max int) int64

生成随机数字

func RandomPwd

func RandomPwd(num int) string

随机密码 num 几位

func RandomString

func RandomString(num int) string

生成随机字符串

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(a []string) (ret []string)

数组排重去空

func RemoveFormatting

func RemoveFormatting(html string) string

Simplify HTML text by removing tags

func SHA1

func SHA1(s string) string

sha1加密

func SHA1Byte

func SHA1Byte(s string) []byte

func SendMail

func SendMail(subject string, message string, from string, to []string, smtpConfig SmtpConfig, isHtml bool) error

send mail

func SnakeCasedName

func SnakeCasedName(name string) string

convert like this: "HelloWorld" to "hello_world"

func SplitFilename

func SplitFilename(filename string) (baseName, ext string)

分离文件名与扩展名(包含.)

func Sprint

func Sprint(ob interface{}) string

func Str2int

func Str2int(s string) (int, error)

字符串转整形

func Str2int64

func Str2int64(s string) (int64, error)

字符串转长整型

func StringEqual

func StringEqual(a, b []string) bool

func StringsContains

func StringsContains(list []string, key string) (finded bool)

字符串数组中是否包含给定项

func StripTags

func StripTags(html string) string

func StructName

func StructName(s interface{}) string

get the Struct's name

func StructToMap

func StructToMap(s interface{}) map[string]interface{}

convert struct to map

func StructToSnakeKeyMap

func StructToSnakeKeyMap(s interface{}) map[string]interface{}

convert struct to map but struct's field name to snake cased map key

func Substr

func Substr(str string, start, length int) string

func Substring

func Substring(str string, start int) string

func SubstringByte

func SubstringByte(str string, start int) string

以byte来截取

func TarGz

func TarGz(srcDirPath string, destFilePath string) error

Gzip and tar from source directory or file to destination file you need check file exist before you call this function

func TarGzFiles

func TarGzFiles(src []string, destFilePath string) error

main functions shows how to TarGz a directory/file and UnTarGz a file func main() { targetFilePath := "testdata.tar.gz" srcDirPath := "testdata" TarGz(srcDirPath, targetFilePath) UnTarGz(targetFilePath, srcDirPath+"_temp") }

func TheTime

func TheTime(counts time.Duration) time.Time

得到多少分钟前的时间

func TheTimeString

func TheTimeString(counts time.Duration) string

得到多少分钟前的时间

func TheYearMonthString

func TheYearMonthString() (yms string, ymi int)

返回当前月份,yms str类型,ymi int 类型

func TimeLocal

func TimeLocal() time.Time

返回当前时区的当前时间

func TimeLocalMDHString

func TimeLocalMDHString() string

返回当前时区的当前月日时,120615,12月6号15时

func TimeLocalString

func TimeLocalString() string

返回当前时区的当前时间

func TimeLocalYYYYMMDDHHMMSSString

func TimeLocalYYYYMMDDHHMMSSString() string

返回当前时区的当前时间的字符串

func TimeParseOften

func TimeParseOften(value string) (time.Time, error)

解析常用的日期时间格式:2014-01-11 16:18:00,东八区

func Timestamp2String

func Timestamp2String(timestamp int64) string

将unix 时间戳转换为时间字符串 1441070992=>2015-09-01 09:29:52

func TransferExt

func TransferExt(path string, toExt string) string

转换文件的格式 toExt包含.

func UnTarGz

func UnTarGz(srcFilePath string, destDirPath string) error

Ungzip and untar from source file to destination directory you need check file exist before you call this function

func UrlEncode

func UrlEncode(s string) string

url编码

func Utf8ToGBK

func Utf8ToGBK(str string) string

utf-8转gbk

func ZeroPadding

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

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type Node

type Node struct {
	Children      []*Node
	FiledType     string
	FiledRealType string
	FieldName     string
	FieldValue    string
	Deep          int
	IsNil         bool
}

type SmtpConfig

type SmtpConfig struct {
	Username string
	Password string
	Host     string
	Addr     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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