Documentation ¶
Index ¶
- Variables
- func BcryptCheck(password, hash string) bool
- func BcryptEncrypt(password string) string
- func Build[T any](s *SqlBuilder, v *T) (int64, int64, error)
- func BuildNotPage[T any](s *SqlBuilder, v *T) error
- func BytesToInt64(b []byte) (tmp int64)
- func BytesTouInt64(b []byte) (tmp uint64)
- func BytesTouInt8(b []byte) (tmp uint8)
- func Contains(slice []string, element string) bool
- func DataSlice[T any](v []T, size int) [][]T
- func ExtractTime(id int64) time.Time
- func FileExists(file string) bool
- func FileIsDir(file string) bool
- func GenerateRandomString(n int) string
- func GetBody[T any](url string, headers M) (*T, error)
- func GetPost[T any](url string, headers M, body interface{}) (*T, error)
- func GrepFile(patten string, filename string) (lines []string, err error)
- func GuidID() string
- func Int64ToBytes(n int64) (b []byte)
- func IsRegularFile(fi os.FileInfo) bool
- func IsValidTime(t time.Time) bool
- func Md5(str string) string
- func MonthStart() time.Time
- func NextId() int64
- func Now() string
- func NowDate() string
- func NowDateTime() string
- func NowUnix() int64
- func PKCS5Padding(data []byte, blockSize int) []byte
- func PKCS5UnPadding(data []byte) []byte
- func ParseDate(dt string) (time.Time, error)
- func ParseDateTime(dt string) (time.Time, error)
- func ParseStringTime(tm, lc string) (time.Time, error)
- func RGetFieldsValues(obj interface{}) map[string]interface{}
- func RGetTypeName(value interface{}) string
- func RIsEmpty(value interface{}) bool
- func RIsPointer(value interface{}) bool
- func ReadFile(filename string) (string, error)
- func SearchFile(filename string, paths ...string) (fullpath string, err error)
- func SecureAESDecrypt(key, ciphertext []byte) ([]byte, error)
- func SecureAESEncrypt(key, text []byte) ([]byte, error)
- func SecureDESDecrypt(ciphertext, key []byte) ([]byte, error)
- func SecureDESEncrypt(plaintext, key []byte) ([]byte, error)
- func SelfDir() string
- func SelfPath() string
- func SetIdGenerator(options *IdGeneratorOptions)
- func SinceForHuman(t time.Time) string
- func SnowInit(workerId uint16)
- func StringGetHash(s string) string
- func StringIsEmpty(v string) bool
- func StringRandom(n int) string
- func Tar(src, dest string) (err error)
- func TarRecursive(src, dest string) (err error)
- func ToSqlCondition(tableName string, v interface{}) map[string]interface{}
- func ToUnifiedTime(v time.Time) string
- func TodayEnd() time.Time
- func TodayStart() time.Time
- func Uint64ToBytes(n uint64) (b []byte)
- func UnTar(src, dest string) (err error)
- func UnZip(dst, src string) (err error)
- func Zip(src, dest string) (err error)
- func ZipRecursive(src, dest string) (err error)
- type DefaultIdGenerator
- type FileChunk
- type HeapTimeout
- type HttpClient
- func (c *HttpClient) GetBody(url string, headers M, data interface{}) error
- func (c *HttpClient) GetBodyN(url string, data interface{}) error
- func (c *HttpClient) GetString(url string, headers M) (string, error)
- func (c *HttpClient) GetStringN(url string) (string, error)
- func (c *HttpClient) PostBody(url string, headers M, body interface{}, data interface{}) error
- func (c *HttpClient) PostBodyN(url string, body interface{}, data interface{}) error
- func (c *HttpClient) PostString(url string, headers M, body interface{}) (string, error)
- func (c *HttpClient) PostStringN(url string, body interface{}) (string, error)
- type ISnowWorker
- type IdGeneratorOptions
- type M
- type Node
- type ObjectId
- type OrmBuilder
- type Ring
- type SnowWorkerDefault
- func (m1 *SnowWorkerDefault) CalcId(useTimeTick int64) int64
- func (m1 *SnowWorkerDefault) CalcTurnBackId(useTimeTick int64) int64
- func (m1 *SnowWorkerDefault) GetCurrentTimeTick() int64
- func (m1 *SnowWorkerDefault) GetNextTimeTick() int64
- func (m1 *SnowWorkerDefault) NextId() int64
- func (m1 *SnowWorkerDefault) NextNormalId() int64
- func (m1 *SnowWorkerDefault) NextOverCostId() int64
- type SqlBuilder
- func (s *SqlBuilder) Count() int64
- func (s *SqlBuilder) Form(tableName string) *SqlBuilder
- func (s *SqlBuilder) LeftJoin(v string) *SqlBuilder
- func (s *SqlBuilder) Limit(pageNum, pageSize int) *SqlBuilder
- func (s *SqlBuilder) LimitNotPage(pageNum, pageSize int) *SqlBuilder
- func (s *SqlBuilder) Order(v string) *SqlBuilder
- func (s *SqlBuilder) OrderBy(v string) *SqlBuilder
- func (s *SqlBuilder) OrderDesc(v string) *SqlBuilder
- func (s *SqlBuilder) ToSql() (string, map[string]interface{})
- func (s *SqlBuilder) Where(w, k string, v interface{}) *SqlBuilder
- type T
Constants ¶
This section is empty.
Variables ¶
var ( TimeLayoutDate = "2006-01-02" TimeLayoutDateTime = "2006-01-02 15:04:05" )
Functions ¶
func BcryptCheck ¶
BcryptCheck Bcrypt解密 @params password : 被解密对象
func BcryptEncrypt ¶
BcryptEncrypt Bcrypt加密 @params password : 被加密对象
func Build ¶
func Build[T any](s *SqlBuilder, v *T) (int64, int64, error)
Build 构建 r1 总页数 r2 总数据量 r3 恐慌
func BuildNotPage ¶
func BuildNotPage[T any](s *SqlBuilder, v *T) error
BuildNotPage 构建无需page信息 @returns 恐慌
func ExtractTime ¶ added in v0.7.6
func FileExists ¶
func GrepFile ¶
GrepFile like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read
func IsRegularFile ¶
func IsValidTime ¶
func MonthStart ¶
func NowDateTime ¶
func NowDateTime() string
func PKCS5Padding ¶ added in v0.7.2
PKCS5Padding 对数据进行填充
func RGetFieldsValues ¶
func RGetFieldsValues(obj interface{}) map[string]interface{}
RGetFieldsValues 获取给定结构体的所有字段名和字段值
func SearchFile ¶
SearchFile Search a file in paths. this is often used in search config file in /etc ~/
func SecureAESDecrypt ¶ added in v0.7.2
SecureAESDecrypt ASE解密
func SecureAESEncrypt ¶ added in v0.7.2
SecureAESEncrypt ASE加密
func SecureDESDecrypt ¶ added in v0.7.2
SecureDESDecrypt DES解密
func SecureDESEncrypt ¶ added in v0.7.2
SecureDESEncrypt DES加密
func SetIdGenerator ¶ added in v0.7.6
func SetIdGenerator(options *IdGeneratorOptions)
SetIdGenerator .
func TarRecursive ¶
func ToSqlCondition ¶ added in v0.7.3
ToSqlCondition 转换为SQL条件
func TodayStart ¶
func UnTar ¶
UnTar 解压文件. src is the abbreviation of source, which is a directory of files to be decompressed. dst is the abbreviation of destination, which is the decompressed file directory.
func ZipRecursive ¶
ZipRecursive Zip Compressed file.
Types ¶
type DefaultIdGenerator ¶ added in v0.7.6
type DefaultIdGenerator struct { Options *IdGeneratorOptions // ID 生成器的选项 SnowWorker ISnowWorker // Snowflake 算法的工作器 }
DefaultIdGenerator 是默认的 ID 生成器实现。
func NewDefaultIdGenerator ¶ added in v0.7.6
func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator
NewDefaultIdGenerator 创建一个新的默认 ID 生成器。
func (DefaultIdGenerator) ExtractTime ¶ added in v0.7.6
func (dig DefaultIdGenerator) ExtractTime(id int64) time.Time
ExtractTime 从 ID 中提取时间信息。
func (DefaultIdGenerator) NewLong ¶ added in v0.7.6
func (dig DefaultIdGenerator) NewLong() int64
NewLong 生成一个长整型的 ID。
type FileChunk ¶
type FileChunk struct { Number int // Chunk number Offset int64 // Chunk offset Size int64 // Chunk size. }
func SplitFileByPartNum ¶
SplitFileByPartNum 按分块数分块
type HeapTimeout ¶ added in v0.7.6
func (HeapTimeout) Len ¶ added in v0.7.6
func (ht HeapTimeout) Len() int
func (HeapTimeout) Less ¶ added in v0.7.6
func (ht HeapTimeout) Less(i, j int) bool
func (HeapTimeout) Push ¶ added in v0.7.6
func (ht HeapTimeout) Push(x any)
func (HeapTimeout) Swap ¶ added in v0.7.6
func (ht HeapTimeout) Swap(i, j int)
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func (*HttpClient) GetBody ¶
func (c *HttpClient) GetBody(url string, headers M, data interface{}) error
GetBody 发送get请求并完成数据获取
func (*HttpClient) GetBodyN ¶
func (c *HttpClient) GetBodyN(url string, data interface{}) error
GetBodyN 发送get请求并完成数据获取
func (*HttpClient) GetString ¶
func (c *HttpClient) GetString(url string, headers M) (string, error)
GetString 发送get请求且包含请求头
func (*HttpClient) GetStringN ¶
func (c *HttpClient) GetStringN(url string) (string, error)
GetStringN 发送get请求且不包含请求头
func (*HttpClient) PostBody ¶
func (c *HttpClient) PostBody(url string, headers M, body interface{}, data interface{}) error
PostBody 发送post请求并完成数据获取
func (*HttpClient) PostBodyN ¶
func (c *HttpClient) PostBodyN(url string, body interface{}, data interface{}) error
PostBodyN 发送post请求并不包含请求头且完成数据获取
func (*HttpClient) PostString ¶
func (c *HttpClient) PostString(url string, headers M, body interface{}) (string, error)
PostString 发送post请求返回string
func (*HttpClient) PostStringN ¶
func (c *HttpClient) PostStringN(url string, body interface{}) (string, error)
PostStringN 发送post请求且不包含请求头
type ISnowWorker ¶ added in v0.7.6
type ISnowWorker interface {
NextId() int64
}
func NewSnowWorkerDefault ¶ added in v0.7.6
func NewSnowWorkerDefault(options *IdGeneratorOptions) ISnowWorker
NewSnowWorkerDefault 创建一个新的 Snowflake 算法的工作器。
type IdGeneratorOptions ¶ added in v0.7.6
type IdGeneratorOptions struct { BaseTime int64 // 基础时间(ms单位),不能超过当前系统时间 WorkerId uint16 // 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1 WorkerIdBitLength byte // 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22) SeqBitLength byte // 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22) MaxSeqNumber uint32 // 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1]) MinSeqNumber uint32 // 最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位 TopOverCostCount uint32 // 最大漂移次数(含),默认2000,推荐范围500-10000(与计算能力有关) }
func NewIdGeneratorOptions ¶ added in v0.7.6
func NewIdGeneratorOptions(workerId uint16) *IdGeneratorOptions
type OrmBuilder ¶ added in v0.7.3
type OrmBuilder struct { TableName string // contains filtered or unexported fields }
func (*OrmBuilder) Find ¶ added in v0.7.3
func (o *OrmBuilder) Find(v interface{}) error
Find 查询同Gorm的Find
func (*OrmBuilder) Fusion ¶ added in v0.7.3
func (o *OrmBuilder) Fusion(v interface{}) *OrmBuilder
Fusion 将条件和DB融合为Orm操作实例
type Ring ¶ added in v0.7.6
type Ring[T any] struct { Value T // for use by client; untouched by this library // contains filtered or unexported fields }
func (*Ring[T]) Len ¶ added in v0.7.6
Len computes the number of elements in ring r. It executes in time proportional to the number of elements.
func (*Ring[T]) Link ¶ added in v0.7.6
Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty.
If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to that subring (if no elements were removed, the result is still the original value for r.Next(), and not nil).
If r and s point to different rings, linking them creates a single ring with the elements of s inserted after r. The result points to the element following the last element of s after insertion.
func (*Ring[T]) Move ¶ added in v0.7.6
Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.
type SnowWorkerDefault ¶ added in v0.7.6
type SnowWorkerDefault struct { BaseTime int64 // 基础时间 WorkerId uint16 // 机器码 WorkerIdBitLength byte // 机器码位长 SeqBitLength byte // 自增序列数位长 MaxSeqNumber uint32 // 最大序列数(含) MinSeqNumber uint32 // 最小序列数(含) TopOverCostCount uint32 // 最大漂移次数 sync.Mutex // contains filtered or unexported fields }
SnowWorkerDefault 实现了基于 Snowflake 算法的工作器。
func (*SnowWorkerDefault) CalcId ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) CalcId(useTimeTick int64) int64
CalcId 计算给定时间戳的 ID。
func (*SnowWorkerDefault) CalcTurnBackId ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) CalcTurnBackId(useTimeTick int64) int64
CalcTurnBackId 计算时间回拨时的 ID。
func (*SnowWorkerDefault) GetCurrentTimeTick ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) GetCurrentTimeTick() int64
GetCurrentTimeTick .
func (*SnowWorkerDefault) GetNextTimeTick ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) GetNextTimeTick() int64
GetNextTimeTick .
func (*SnowWorkerDefault) NextId ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) NextId() int64
NextId .
func (*SnowWorkerDefault) NextNormalId ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) NextNormalId() int64
NextNormalId 生成下一个正常的 ID。
func (*SnowWorkerDefault) NextOverCostId ¶ added in v0.7.6
func (m1 *SnowWorkerDefault) NextOverCostId() int64
NextOverCostId 生成下一个超出成本的 ID。
type SqlBuilder ¶
type SqlBuilder struct { BaseSql string Temp string Condition map[string]interface{} Total int64 DB *gorm.DB // contains filtered or unexported fields }
func (*SqlBuilder) Count ¶
func (s *SqlBuilder) Count() int64
func (*SqlBuilder) Form ¶
func (s *SqlBuilder) Form(tableName string) *SqlBuilder
func (*SqlBuilder) LeftJoin ¶
func (s *SqlBuilder) LeftJoin(v string) *SqlBuilder
func (*SqlBuilder) Limit ¶
func (s *SqlBuilder) Limit(pageNum, pageSize int) *SqlBuilder
func (*SqlBuilder) LimitNotPage ¶
func (s *SqlBuilder) LimitNotPage(pageNum, pageSize int) *SqlBuilder
func (*SqlBuilder) ToSql ¶
func (s *SqlBuilder) ToSql() (string, map[string]interface{})
ToSql 转换为sql
func (*SqlBuilder) Where ¶
func (s *SqlBuilder) Where(w, k string, v interface{}) *SqlBuilder
Where 首次拼接