Documentation
¶
Index ¶
- Constants
- Variables
- func BCryptCompareHashAndPassword(pwd, hash string) bool
- func BCryptGenerateFromPassword(pwd string) (string, error)
- func BetweenDays(startTime, endTime time.Time) int64
- func ByteString(b []byte) string
- func BytesNewBufferString(b []byte) string
- func CertInit(certPEM, keyPEM []byte) error
- func CheckPassword(pwd string) error
- func CronRun(ctx context.Context, corn string, task ...func()) error
- func CronRunM(ctx context.Context, corn string, task ...func()) error
- func DeleteStruct(key string) error
- func DeleteStructByPrefix(prefix string) error
- func ErrorWrap(w http.ResponseWriter, code int, err error, msg ...string) error
- func FullPassword(level, length int) (string, error)
- func GetHostname() string
- func GetString(key string) string
- func GetStruct[T any](key string) (T, error)
- func HGetStruct[T any](key, field string) (T, error)
- func HMCompare(h1, m1, h2, m2 int) bool
- func HSetStruct(key, field string, data any) error
- func HttpGet[T any](url string) (T, error)
- func In[T comparable](e T, s []T) bool
- func LoggerInit(level, path string)
- func MaxNumber[T Numbers](n ...T) T
- func MinNumber[T Numbers](n ...T) T
- func NewGmailAuth(username, password string) smtp.Auth
- func NewLumberjackLogger(fileName string, opts ...LumberjackOption) io.Writer
- func NextStringId() string
- func NotIn[T comparable](e T, s []T) bool
- func RandInt(max int64) (int64, error)
- func RemoveDuplicates[T comparable](s1 []T) []T
- func RemoveDuplicatesInPlace(userIDs []int64) []int64
- func SetString(key, value string, expiration ...time.Duration) error
- func SetStruct(key string, data any, expiration ...time.Duration) error
- func SliceDifference[T comparable](a, b []T) []T
- func SliceDifferenceBoth[T comparable](slice1, slice2 []T) []T
- func SliceIn[T comparable](e T, s []T) bool
- func SliceIntersection[T comparable](s1, s2 []T) (inter []T)
- func SlicePtrToSlice[T any](s []*T) []T
- func SliceRemoveIndex[T any](s []T, index int) []T
- func SliceRemoveIndexUnOrder[T any](s []T, i int) []T
- func SliceReverse[T any](slice []T)
- func SliceToSlicePtr[T any](s []T) []*T
- func StrconvFormatInt(i int64) string
- func StrconvParseFloat(i int) (float64, error)
- func StrconvParseInt(s string) (int64, error)
- func StringByte(s string) []byte
- func StringByteUnsafe(s string) []byte
- func TickerRun(ctx context.Context, d time.Duration, task ...Task) error
- func TickerRunContext(ctx context.Context, d time.Duration, task ...TaskContext) error
- func TickerRunWithStartTimeContext(ctx context.Context, wg *sync.WaitGroup, tm time.Time, d time.Duration, ...) error
- func TimeCompare(t1, t2 time.Time) bool
- func TimeExistIntersection(startTime, endTime time.Time, anotherStartTime, anotherEndTime time.Time) bool
- func TimeFormat(tm time.Time) string
- func TimeFormatDate(tm time.Time) string
- func TimeNowFormat() string
- func TimeParseDate(date string) (time.Time, error)
- func TimeParseDatetime(datetime string) (time.Time, error)
- func TimeUnixFormatDate(timestamp int64) string
- func TimeUnixFormatDatetime(timestamp int64) string
- func TimerRun(ctx context.Context, tm time.Time, task ...Task) error
- func TimestampExistIntersection(startTime, endTime int64, anotherStartTime, anotherEndTime int64) bool
- func TodayZeroTime() time.Time
- func TodayZeroTimestamp() int64
- func UnWrapBody[T any](r *http.Request) (*T, error)
- func UnWrapURL(r *http.Request) (map[string]any, error)
- func Wrap(w http.ResponseWriter, data any, msg ...string) error
- func ZeroTime(tm time.Time) time.Time
- func ZeroTimestamp(ts int64) int64
- type AESCrypter
- type ApiWrapper
- type AsyncError
- type CTRCrypt
- type Callback
- type CallbackKey
- type CallbackType
- type Callbacks
- type CanceledError
- type Event
- type EventDesc
- type EventKey
- type EventType
- type FSM
- type FSMManage
- type FileStorage
- type FullPasswordConf
- type IFSM
- type Ider
- type InTransitionError
- type InternalError
- type InvalidEventError
- type JsonUnmarshal
- type LumberjackOption
- type Mail
- type Mailer
- type MariaDB
- type NoTransitionError
- type NotInTransitionError
- type Numbers
- type Option
- type Postgres
- type Pretty
- type PrettyDB
- type PrettyTx
- type RSASign
- type Redis
- type RedisOption
- type Server
- type ServerOption
- type Signer
- type StateType
- type Storage
- type Task
- type TaskContext
- type TomlUnmarshal
- type Transition
- type UUID
- type UnknownEventError
- type UnmarshalConfiger
- type XId
- type YamlUnmarshal
- type YitId
Constants ¶
const ( // LowerLetters is the list of lowercase letters. LowerLetters = "abcdefghijklmnopqrstuvwxyz" // UpperLetters is the list of uppercase letters. UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Digits is the list of permitted digits. Digits = "0123456789" // Symbols is the list of symbols. Symbols = "~!@#$%^&*()_+`-={}|[]\\:\"<>?,./" )
const ( GmailSmtp = "smtp.gmail.com" GmailTLSPort = 587 GmailSSLPort = 465 )
Variables ¶
var ( // Cert is a self signed certificate Cert tls.Certificate // CertPool contains the self signed certificate CertPool *x509.CertPool )
var (
InvalidTransition = errors.New("invalid transition")
)
var (
Logger *zerolog.Logger = &zerolog.Logger{}
)
Functions ¶
func BCryptCompareHashAndPassword ¶ added in v0.0.9
BCryptCompareHashAndPassword true or false
func BCryptGenerateFromPassword ¶ added in v0.0.9
BCryptGenerateFromPassword generate hash from password
func BetweenDays ¶ added in v0.0.15
BetweenDays 两个时间之间隔了多少天 startTime >= endTime
func BytesNewBufferString ¶ added in v0.0.9
BytesNewBufferString []byte to string
func CheckPassword ¶ added in v0.0.15
func DeleteStruct ¶ added in v0.0.15
func DeleteStructByPrefix ¶ added in v0.0.15
func FullPassword ¶ added in v0.0.17
func GetHostname ¶ added in v0.0.15
func GetHostname() string
func HGetStruct ¶ added in v0.0.15
func HSetStruct ¶ added in v0.0.15
func LoggerInit ¶ added in v0.0.15
func LoggerInit(level, path string)
func MaxNumber ¶ added in v0.0.15
func MaxNumber[T Numbers](n ...T) T
MaxNumber booleans, numbers, strings, pointers, channels, arrays
func NewGmailAuth ¶ added in v0.0.15
func NewLumberjackLogger ¶ added in v0.0.13
func NewLumberjackLogger(fileName string, opts ...LumberjackOption) io.Writer
func NextStringId ¶ added in v0.0.15
func NextStringId() string
func NotIn ¶ added in v0.0.15
func NotIn[T comparable](e T, s []T) bool
NotIn e 不在 s 中吗? true 不在, false 在
func RemoveDuplicates ¶ added in v0.0.15
func RemoveDuplicates[T comparable](s1 []T) []T
RemoveDuplicates slice 去重
func RemoveDuplicatesInPlace ¶ added in v0.0.15
RemoveDuplicatesInPlace slice 就地去重
func SliceDifference ¶ added in v0.0.13
func SliceDifference[T comparable](a, b []T) []T
SliceDifference 取 a 中有,而 b 中没有的
func SliceDifferenceBoth ¶ added in v0.0.16
func SliceDifferenceBoth[T comparable](slice1, slice2 []T) []T
SliceDifferenceBoth 取 slice1, slice2 的差集
func SliceIntersection ¶ added in v0.0.13
func SliceIntersection[T comparable](s1, s2 []T) (inter []T)
SliceIntersection 两个 slice 的交集
func SlicePtrToSlice ¶ added in v0.0.15
func SlicePtrToSlice[T any](s []*T) []T
func SliceRemoveIndex ¶ added in v0.0.10
SliceRemoveIndex 移除 slice 中的一个元素
func SliceRemoveIndexUnOrder ¶ added in v0.0.10
SliceRemoveIndexUnOrder 移除 slice 中的一个元素(无序,但效率高)
func SliceToSlicePtr ¶ added in v0.0.15
func SliceToSlicePtr[T any](s []T) []*T
func StrconvFormatInt ¶
StrconvFormatInt 1645270804 to "1645270804"
func StrconvParseFloat ¶ added in v0.0.8
StrconvParseFloat int/100 to float64 保留 2 位小数点 example: 2333 -> 23.33
func StrconvParseInt ¶
StrconvParseInt "1645270804" to 1645270804
func StringByteUnsafe ¶ added in v0.0.13
StringByteUnsafe string to []byte
func TickerRunContext ¶ added in v0.0.15
TickerRunContext 立即开始以 ticker 的方式执行 task
func TickerRunWithStartTimeContext ¶ added in v0.0.15
func TickerRunWithStartTimeContext(ctx context.Context, wg *sync.WaitGroup, tm time.Time, d time.Duration, task ...TaskContext) error
TickerRunWithStartTimeContext 到达 tm 时间之后,开始以 tikcer 的方式执行 task
func TimeCompare ¶ added in v0.0.15
TimeCompare 如果 t1>t2, return true, 如果 t1 <= t2, return false
func TimeExistIntersection ¶ added in v0.0.13
func TimeExistIntersection(startTime, endTime time.Time, anotherStartTime, anotherEndTime time.Time) bool
TimeExistIntersection 两个时间段是否有交集 false 没有交集,true 有交集
func TimeFormat ¶
TimeFormat time.Time to "2006-01-02 15:04:05"
func TimeFormatDate ¶ added in v0.0.13
TimeFormatDate time to date
func TimeParseDate ¶ added in v0.0.13
TimeParseDate string date to time date
func TimeParseDatetime ¶ added in v0.0.15
func TimeUnixFormatDate ¶ added in v0.0.15
TimeUnixFormatDate timestamp to date
func TimeUnixFormatDatetime ¶ added in v0.0.15
TimeUnixFormatDatetime time to datetime
func TimestampExistIntersection ¶ added in v0.0.13
func TimestampExistIntersection(startTime, endTime int64, anotherStartTime, anotherEndTime int64) bool
TimestampExistIntersection 两个时间段是否有交集 false 没有交集,true 有交集
func TodayZeroTime ¶ added in v0.0.16
func TodayZeroTimestamp ¶ added in v0.0.16
func TodayZeroTimestamp() int64
func ZeroTimestamp ¶ added in v0.0.16
Types ¶
type AESCrypter ¶ added in v0.0.16
type AESCrypter interface {
Encrypt(keyString, plainString string) (string, error)
Decrypt(keyString, cipherString string) (string, error)
}
func NewCTRCrypt ¶ added in v0.0.17
func NewCTRCrypt() AESCrypter
type ApiWrapper ¶ added in v0.0.15
type AsyncError ¶ added in v0.0.15
type AsyncError struct {
Err error
}
AsyncError is returned by FSM.Event() when a callback have initiated an asynchronous state transition.
func (AsyncError) Error ¶ added in v0.0.15
func (e AsyncError) Error() string
type CallbackKey ¶ added in v0.0.15
type CallbackKey struct {
// contains filtered or unexported fields
}
type CallbackType ¶ added in v0.0.15
type CallbackType int
const ( None CallbackType = iota BeforeEvent LeaveState EnterState AfterEvent )
type CanceledError ¶ added in v0.0.15
type CanceledError struct {
Err error
}
CanceledError is returned by FSM.Event() when a callback have canceled a transition.
func (CanceledError) Error ¶ added in v0.0.15
func (e CanceledError) Error() string
type Event ¶ added in v0.0.15
type Event struct {
FSM *FSM
Event EventType
Src StateType
Dst StateType
Err error
Args []interface{}
// contains filtered or unexported fields
}
Event is the info that get passed as a reference in the callbacks.
type FSM ¶ added in v0.0.15
type FSM struct {
// contains filtered or unexported fields
}
func NewFSM ¶ added in v0.0.15
func NewFSM(initState StateType, events []EventDesc, callbacks map[CallbackKey]Callback) *FSM
func (*FSM) Transition ¶ added in v0.0.15
type FileStorage ¶ added in v0.0.15
func NewFileStorage ¶ added in v0.0.15
func NewFileStorage(basePath, date string) *FileStorage
type FullPasswordConf ¶ added in v0.0.17
type FullPasswordConf struct {
Length int
NumLowerLetters int
NumUpperLetters int
NumDigits int
NumSymbols int
}
func SetLevel ¶ added in v0.0.17
func SetLevel(level, length int) FullPasswordConf
type InTransitionError ¶ added in v0.0.15
type InTransitionError struct {
Event string
}
InTransitionError is returned by FSM.Event() when an asynchronous transition is already in progress.
func (InTransitionError) Error ¶ added in v0.0.15
func (e InTransitionError) Error() string
type InternalError ¶ added in v0.0.15
type InternalError struct{}
InternalError is returned by FSM.Event() and should never occur. It is a probably because of a bug.
func (InternalError) Error ¶ added in v0.0.15
func (e InternalError) Error() string
type InvalidEventError ¶ added in v0.0.15
InvalidEventError is returned by FSM.Event() when the event cannot be called in the current state.
func (InvalidEventError) Error ¶ added in v0.0.15
func (e InvalidEventError) Error() string
type JsonUnmarshal ¶ added in v0.0.15
type JsonUnmarshal struct{}
func (*JsonUnmarshal) ReadConfig ¶ added in v0.0.15
func (j *JsonUnmarshal) ReadConfig(p []byte, v any) error
func (*JsonUnmarshal) ReadConfigFromFile ¶ added in v0.0.15
func (j *JsonUnmarshal) ReadConfigFromFile(path string, v any) error
type LumberjackOption ¶ added in v0.0.13
type LumberjackOption func(*lumberjack.Logger)
func Compress ¶ added in v0.0.13
func Compress(b bool) LumberjackOption
func LocalTime ¶ added in v0.0.13
func LocalTime(b bool) LumberjackOption
func MaxAge ¶ added in v0.0.13
func MaxAge(i int) LumberjackOption
func MaxBackups ¶ added in v0.0.13
func MaxBackups(i int) LumberjackOption
func MaxSize ¶ added in v0.0.13
func MaxSize(i int) LumberjackOption
type NoTransitionError ¶ added in v0.0.15
type NoTransitionError struct {
Err error
}
NoTransitionError is returned by FSM.Event() when no transition have happened, for example if the source and destination states are the same.
func (NoTransitionError) Error ¶ added in v0.0.15
func (e NoTransitionError) Error() string
type NotInTransitionError ¶ added in v0.0.15
type NotInTransitionError struct{}
NotInTransitionError is returned by FSM.Transition() when an asynchronous transition is not in progress.
func (NotInTransitionError) Error ¶ added in v0.0.15
func (e NotInTransitionError) Error() string
type Option ¶ added in v0.0.12
func ConnMaxIdleTime ¶ added in v0.0.12
ConnMaxIdleTime 一个连接空闲的最大时长
func ConnMaxLifetime ¶ added in v0.0.12
ConnMaxLifetime 一个连接使用的最大时长
type Pretty ¶ added in v0.0.12
type Pretty interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
Prepare(query string) (*sql.Stmt, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
Exec(query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryRow(query string, args ...any) *sql.Row
}
type PrettyDB ¶ added in v0.0.12
type PrettyDB interface {
Pretty
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
Begin() (*sql.Tx, error)
}
func NewMariaDB ¶ added in v0.0.8
func NewMariaDB() PrettyDB
func NewPostgresDB ¶ added in v0.0.8
func NewPostgresDB() PrettyDB
type PrettyTx ¶ added in v0.0.12
type PrettyTx interface {
Pretty
Commit() error
Rollback() error
StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
Stmt(stmt *sql.Stmt) *sql.Stmt
}
func NewMariaTx ¶ added in v0.0.12
func NewMariaTxContext ¶ added in v0.0.12
func NewPostgresTx ¶ added in v0.0.12
type RSASign ¶ added in v0.0.17
type RSASign struct {
PrivateKey *rsa.PrivateKey
PublicKey *rsa.PublicKey
}
type Redis ¶ added in v0.0.8
func NewRedisDB ¶ added in v0.0.12
func NewRedisDB() *Redis
type RedisOption ¶ added in v0.0.10
func RedisAddr ¶ added in v0.0.13
func RedisAddr(addr string) RedisOption
func RedisDB ¶ added in v0.0.10
func RedisDB(db int) RedisOption
func RedisPassword ¶ added in v0.0.10
func RedisPassword(pwd string) RedisOption
func RedisPoolSize ¶ added in v0.0.10
func RedisPoolSize(poolSize int) RedisOption
type Server ¶ added in v0.0.15
type Server struct {
// contains filtered or unexported fields
}
Server -.
func NewHttpServer ¶ added in v0.0.15
func NewHttpServer(handler http.Handler, opts ...ServerOption) *Server
NewHttpServer -.
type ServerOption ¶ added in v0.0.15
type ServerOption func(*Server)
ServerOption -.
func ReadTimeout ¶ added in v0.0.15
func ReadTimeout(timeout time.Duration) ServerOption
ReadTimeout -.
func ShutdownTimeout ¶ added in v0.0.15
func ShutdownTimeout(timeout time.Duration) ServerOption
ShutdownTimeout -.
func WriteTimeout ¶ added in v0.0.15
func WriteTimeout(timeout time.Duration) ServerOption
WriteTimeout -.
type Signer ¶ added in v0.0.17
type Signer interface {
Sign(data []byte) ([]byte, error)
Verify(data []byte, signature []byte) error
}
func NewRSASignFromBytes ¶ added in v0.0.17
func NewRSASignFromFile ¶ added in v0.0.17
type TaskContext ¶ added in v0.0.15
type TomlUnmarshal ¶ added in v0.0.15
type TomlUnmarshal struct{}
func (*TomlUnmarshal) ReadConfig ¶ added in v0.0.15
func (t *TomlUnmarshal) ReadConfig(p []byte, v any) error
func (*TomlUnmarshal) ReadConfigFromFile ¶ added in v0.0.15
func (t *TomlUnmarshal) ReadConfigFromFile(path string, v any) error
type Transition ¶ added in v0.0.15
type Transition int
type UUID ¶ added in v0.0.15
type UUID struct{}
func (*UUID) NextInt64Id ¶ added in v0.0.15
func (*UUID) NextStringId ¶ added in v0.0.15
type UnknownEventError ¶ added in v0.0.15
type UnknownEventError struct {
Event string
}
UnknownEventError is returned by FSM.Event() when the event is not defined.
func (UnknownEventError) Error ¶ added in v0.0.15
func (e UnknownEventError) Error() string
type UnmarshalConfiger ¶ added in v0.0.15
type UnmarshalConfiger interface {
ReadConfig(p []byte, v any) error
ReadConfigFromFile(path string, v any) error
}
func NewJsonUnmarshal ¶ added in v0.0.15
func NewJsonUnmarshal() UnmarshalConfiger
func NewTomlUnmarshal ¶ added in v0.0.15
func NewTomlUnmarshal() UnmarshalConfiger
func NewYamlUnmarshal ¶ added in v0.0.15
func NewYamlUnmarshal() UnmarshalConfiger
type XId ¶ added in v0.0.15
type XId struct{}
func (*XId) NextInt64Id ¶ added in v0.0.15
func (*XId) NextStringId ¶ added in v0.0.15
type YamlUnmarshal ¶ added in v0.0.15
type YamlUnmarshal struct{}
func (*YamlUnmarshal) ReadConfig ¶ added in v0.0.15
func (y *YamlUnmarshal) ReadConfig(p []byte, v any) error
func (*YamlUnmarshal) ReadConfigFromFile ¶ added in v0.0.15
func (y *YamlUnmarshal) ReadConfigFromFile(path string, v any) error
type YitId ¶ added in v0.0.15
type YitId struct{}