goutils

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EL = "\n"
)

Variables

View Source
var (
	TimeLayout string = "2006-01-02 15:04:05"
	DateLayout        = "20060102"
	TimeFormat        = map[string]string{
		"Y-m-d H:i:s": "2006-01-02 15:04:05",
		"Y-m-d":       "2006-01-02",
		"Ymd":         "20060102",
		"H:i:s":       "15:04:05",
		"Y":           "2006",
		"m":           "01",
		"d":           "02",
	}
)
View Source
var (
	ErrInitialize = errors.New("not yet initialized")
)

Functions

func AESCBCDecrypt

func AESCBCDecrypt(cipherData, key, iv []byte) ([]byte, error)

func AESCBCEncrypt

func AESCBCEncrypt(rawData, key, iv []byte) ([]byte, error)

func AESECBDecrypt

func AESECBDecrypt(buf, key []byte) ([]byte, error)

func AESECBEncrypt

func AESECBEncrypt(data, key []byte) ([]byte, error)

func AsyncFunc

func AsyncFunc(fn func())

异步执行(安全)

func AsyncFuncGroup

func AsyncFuncGroup(fns ...func())

异步并发执行(安全)

func Base59Decoding

func Base59Decoding(strByte []byte, key ...string) []byte

func Base59Encoding

func Base59Encoding(strByte []byte, key ...string) string

如果遇到特殊字符,需要用 url.PathEscape(str) 解决

func Base64Decode

func Base64Decode(str string) []byte

func Base64Encode

func Base64Encode(buf []byte) string

func BigIntAdd

func BigIntAdd(num1 string, num2 string) string

func BigIntCmp

func BigIntCmp(num1 string, num2 string) int

比大小,大于返回1,等于返回0,小于返回-1

func BigIntDiv

func BigIntDiv(num1 string, num2 string) string

func BigIntMod

func BigIntMod(num1 string, num2 string) string

取模

func BigIntMul

func BigIntMul(num1 string, num2 string) string

func BigIntReduce

func BigIntReduce(num1 string, num2 string) string

func Camel2Case

func Camel2Case(str string) string

驼峰转下划线

func CaptchaGet

func CaptchaGet(width, height int) map[string]string

获取图片验证码

func CaptchaVerify

func CaptchaVerify(id, code string) bool

验证图片验证码

func Case2Camel

func Case2Camel(str string) string

下划线转驼峰

func Code2Id

func Code2Id(code string) (int64, error)

func CreateSavePath

func CreateSavePath(dst string, perm os.FileMode) error

func CurrentHourStartAndEnd added in v1.0.14

func CurrentHourStartAndEnd() (int, int64, int64)

func DIR

func DIR() string

目录名称

func Date2Ts

func Date2Ts(date string) int64

func DateTime

func DateTime(format string) string

func DateTime2Ts

func DateTime2Ts(dateTime string) int64

func Exist

func Exist(path string) (bool, error)

func FILE

func FILE() string

文件名

func GBK2UTF8

func GBK2UTF8(s string) string

func GenId

func GenId() int64

func GenIdInit

func GenIdInit(adapter iGenId)

func GenIdStr

func GenIdStr() string

func GenValidateCode added in v1.0.14

func GenValidateCode(width int) string

func GetChinaTomorrowAMSeconds added in v1.0.14

func GetChinaTomorrowAMSeconds(isBeijing bool) int64

func GetDateInterval added in v1.0.14

func GetDateInterval(t1, t2 time.Time) int

func GetFileHeaderMd5Name

func GetFileHeaderMd5Name(fileHeader *multipart.FileHeader) (string, error)

func GetLocalTomorrowAMSeconds added in v1.0.14

func GetLocalTomorrowAMSeconds() int64

func GetNowDateForLocation added in v1.0.14

func GetNowDateForLocation(isBeijing bool) string

func GetTimeNow added in v1.0.14

func GetTimeNow() time.Time

GetTimeNow 获取当前时间GetTimeNow(),用于测试时的时间修改

func GetTodayZero added in v1.0.14

func GetTodayZero() time.Time

func GetZero added in v1.0.14

func GetZero(targetTime time.Time) time.Time

func HMacMd5

func HMacMd5(buf, key []byte) string

func HMacSha1

func HMacSha1(buf, key []byte) string

func HMacSha256

func HMacSha256(buf, key []byte) string

func HideEmail added in v1.0.14

func HideEmail(email string) string

func Id2Code

func Id2Code(id int64) string

func IfFloat32 added in v1.0.14

func IfFloat32(isTrue bool, a, b float32) float32

func IfFloat64 added in v1.0.14

func IfFloat64(isTrue bool, a, b float64) float64

func IfInt added in v1.0.14

func IfInt(isTrue bool, a, b int) int

func IfString added in v1.0.14

func IfString(isTrue bool, a, b string) string

func IsSameDay added in v1.0.14

func IsSameDay(t1, t2 time.Time) bool

func LINE

func LINE() int

行号

func LastHourStartAndEnd added in v1.0.14

func LastHourStartAndEnd(isBeijing bool) (int, int64, int64)

LastHourStartAndEnd 上一个小时的开始和结束时间戳

func MD5

func MD5(buf []byte) string

func MaxInt added in v1.0.14

func MaxInt(a, b int) int

func MaxInt64 added in v1.0.14

func MaxInt64(a, b int64) int64

func MinInt added in v1.0.14

func MinInt(a, b int) int

func MinInt64 added in v1.0.14

func MinInt64(a, b int64) int64

func NewIdCode

func NewIdCode(key string) *idCode

func NextDate

func NextDate(d int) string

func NonceStr

func NonceStr() string

func NonceStr8

func NonceStr8() string

func Now

func Now() string

func PadStart added in v1.0.14

func PadStart(str, pad string, length int) string

func ParseTime added in v1.0.14

func ParseTime(timeStr string) (datetime time.Time)

ParseTime 解析时间,"2021-03-17 00:00:00"

func ParseTimeString added in v1.0.14

func ParseTimeString(timeStr string) (datetime time.Time)

func PinYin

func PinYin(origin string) (string, error)

func Recovery

func Recovery()

捕获panic

func ReverseArray added in v1.0.14

func ReverseArray(arr []*interface{})

func SHA1

func SHA1(buf []byte) string

func SHA256

func SHA256(buf, key []byte) string

func SHAWithRSA

func SHAWithRSA(key, data []byte) (string, error)

func SaveFile

func SaveFile(file *multipart.FileHeader, dst string) error

func SessionId

func SessionId() string

func SinceDays added in v1.0.14

func SinceDays(dateString string) (int64, error)

SinceDays 获取过去的天数,dateString格式20060102

func Split

func Split(s string, rs ...rune) []string

多字符切割,默认支持逗号,分号,\n

func SplitArray

func SplitArray(arr []interface{}, size int) (list [][]interface{})

func SplitInt64Array

func SplitInt64Array(arr []int64, size int) (list [][]int64)

func SplitIntArray

func SplitIntArray(arr []int, size int) (list [][]int)

func SplitStringArray

func SplitStringArray(arr []string, size int) (list [][]string)

func TimeRangeDates added in v1.0.14

func TimeRangeDates(startDate string, endDate string) []string

func TimeRangeDay added in v1.0.14

func TimeRangeDay(stTime int64, endTIme int64) int

返回相差天数

func ToDate added in v1.0.14

func ToDate(ts int64, isBeijing bool) string

func ToDateTime added in v1.0.14

func ToDateTime(ts int64, isBeijing bool) string

func Today

func Today() string

func Trace

func Trace(skip int) (arr []string)

追踪信息

func Ts2Date

func Ts2Date(ts int64) string

func Ts2DateTime

func Ts2DateTime(ts int64) string

func UTF82GBK

func UTF82GBK(s string) string

func ValidPassword

func ValidPassword(str string) (msg string, matched bool)

func ValidPasswordV2

func ValidPasswordV2(str string) (msg string, matched bool)

func WriteToFile

func WriteToFile(filename string, b []byte) error

写文件,支持路径创建

Types

type Byte

type Byte []byte

func (Byte) Params

func (b Byte) Params() (p *Params, err error)

type Mode

type Mode int
const (
	WithoutTone        Mode = iota + 1 // 默认模式,例如:guo
	Tone                               // 带声调的拼音 例如:guó
	InitialsInCapitals                 // 首字母大写不带声调,例如:Guo
)

type Params

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

func NewParams

func NewParams() *Params

func (*Params) Array

func (p *Params) Array() (ps []Params)

func (*Params) ArrayData

func (p *Params) ArrayData() []interface{}

func (*Params) Bool

func (p *Params) Bool() bool

func (*Params) Data

func (p *Params) Data() interface{}

func (*Params) Float32

func (p *Params) Float32() float32

func (*Params) Float64

func (p *Params) Float64() float64

func (*Params) Get

func (p *Params) Get(key string) *Params

func (*Params) Int

func (p *Params) Int() int

func (*Params) Int32

func (p *Params) Int32() int32

func (*Params) Int64

func (p *Params) Int64() int64

func (*Params) JSON

func (p *Params) JSON() []byte

func (*Params) Map

func (p *Params) Map() (rst map[string]Params)

func (*Params) MapData

func (p *Params) MapData() map[string]interface{}

func (*Params) Set

func (p *Params) Set(key string, val interface{}) *Params

func (*Params) String

func (p *Params) String() string

type SnowFlakeId

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

雪花算法

func (*SnowFlakeId) GenId

func (sf *SnowFlakeId) GenId() int64

type StringMap

type StringMap map[string]string

func (StringMap) MarshalXML

func (m StringMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*StringMap) UnmarshalXML

func (m *StringMap) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

Jump to

Keyboard shortcuts

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