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 Filter[T any](objs []T, filter func(obj T) bool) []T
- func First[T any](objs []T) (T, bool)
- 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 Map[T any, K any](objs []T, mapper func(obj T) ([]K, bool)) []K
- func MaxNumber[T Numbers](n ...T) T
- func MinNumber[T Numbers](n ...T) T
- func NewGmailAuth(username, password string) smtp.Auth
- func NewGrpcServer(ctx context.Context, port string, server *grpc.Server)
- func NewLumberjackLogger(fileName string, opts ...LumberjackOption) io.Writer
- func NextStringId() string
- func NotIn[T comparable](e T, s []T) bool
- func Pageination[T any](page, pageSize int, s []T) []T
- 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 (
ErrInvalidTransition = errors.New("invalid transition")
)
var (
Logger *zerolog.Logger = &zerolog.Logger{}
)
Functions ¶
func BCryptCompareHashAndPassword ¶
BCryptCompareHashAndPassword true or false
func BCryptGenerateFromPassword ¶
BCryptGenerateFromPassword generate hash from password
func BetweenDays ¶
BetweenDays 两个时间之间隔了多少天 startTime >= endTime
func BytesNewBufferString ¶
BytesNewBufferString []byte to string
func CheckPassword ¶
func DeleteStruct ¶
func DeleteStructByPrefix ¶
func FullPassword ¶
func GetHostname ¶
func GetHostname() string
func HGetStruct ¶
func HSetStruct ¶
func LoggerInit ¶
func LoggerInit(level, path string)
func MaxNumber ¶
func MaxNumber[T Numbers](n ...T) T
MaxNumber booleans, numbers, strings, pointers, channels, arrays
func NewGmailAuth ¶
func NewGrpcServer ¶
NewGrpcServer -.
func NewLumberjackLogger ¶
func NewLumberjackLogger(fileName string, opts ...LumberjackOption) io.Writer
func NextStringId ¶
func NextStringId() string
func RemoveDuplicatesInPlace ¶
RemoveDuplicatesInPlace slice 就地去重
func SliceDifference ¶
func SliceDifference[T comparable](a, b []T) []T
SliceDifference 取 a 中有,而 b 中没有的
func SliceDifferenceBoth ¶
func SliceDifferenceBoth[T comparable](slice1, slice2 []T) []T
SliceDifferenceBoth 取 slice1, slice2 的差集
func SliceIntersection ¶
func SliceIntersection[T comparable](s1, s2 []T) (inter []T)
SliceIntersection 两个 slice 的交集
func SlicePtrToSlice ¶
func SlicePtrToSlice[T any](s []*T) []T
func SliceRemoveIndex ¶
SliceRemoveIndex 移除 slice 中的一个元素
func SliceRemoveIndexUnOrder ¶
SliceRemoveIndexUnOrder 移除 slice 中的一个元素(无序,但效率高)
func SliceToSlicePtr ¶
func SliceToSlicePtr[T any](s []T) []*T
func StrconvFormatInt ¶
StrconvFormatInt 1645270804 to "1645270804"
func StrconvParseFloat ¶
StrconvParseFloat int/100 to float64 保留 2 位小数点 example: 2333 -> 23.33
func StrconvParseInt ¶
StrconvParseInt "1645270804" to 1645270804
func TickerRunContext ¶
TickerRunContext 立即开始以 ticker 的方式执行 task
func TickerRunWithStartTimeContext ¶
func TickerRunWithStartTimeContext(ctx context.Context, wg *sync.WaitGroup, tm time.Time, d time.Duration, task ...TaskContext) error
TickerRunWithStartTimeContext 到达 tm 时间之后,开始以 tikcer 的方式执行 task
func TimeCompare ¶
TimeCompare 如果 t1>t2, return true, 如果 t1 <= t2, return false
func TimeExistIntersection ¶
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 TimeParseDate ¶
TimeParseDate string date to time date
func TimeUnixFormatDate ¶
TimeUnixFormatDate timestamp to date
func TimeUnixFormatDatetime ¶
TimeUnixFormatDatetime time to datetime
func TimestampExistIntersection ¶
func TimestampExistIntersection(startTime, endTime int64, anotherStartTime, anotherEndTime int64) bool
TimestampExistIntersection 两个时间段是否有交集 false 没有交集,true 有交集
func TodayZeroTime ¶
func TodayZeroTimestamp ¶
func TodayZeroTimestamp() int64
func ZeroTimestamp ¶
Types ¶
type AESCrypter ¶
type AESCrypter interface { Encrypt(keyString, plainString string) (string, error) Decrypt(keyString, cipherString string) (string, error) }
func NewCTRCrypt ¶
func NewCTRCrypt() AESCrypter
type ApiWrapper ¶
type AsyncError ¶
type AsyncError struct {
Err error
}
AsyncError is returned by FSM.Event() when a callback have initiated an asynchronous state transition.
func (AsyncError) Error ¶
func (e AsyncError) Error() string
type CallbackKey ¶
type CallbackKey struct {
// contains filtered or unexported fields
}
type CallbackType ¶
type CallbackType int
const ( None CallbackType = iota BeforeEvent LeaveState EnterState AfterEvent )
type CanceledError ¶
type CanceledError struct {
Err error
}
CanceledError is returned by FSM.Event() when a callback have canceled a transition.
func (CanceledError) Error ¶
func (e CanceledError) Error() string
type Event ¶
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 ¶
type FSM struct {
// contains filtered or unexported fields
}
func NewFSM ¶
func NewFSM(initState StateType, events []EventDesc, callbacks map[CallbackKey]Callback) *FSM
func (*FSM) Transition ¶
type FileStorage ¶
func NewFileStorage ¶
func NewFileStorage(basePath, date string) *FileStorage
type FullPasswordConf ¶
type FullPasswordConf struct { Length int NumLowerLetters int NumUpperLetters int NumDigits int NumSymbols int }
func SetLevel ¶
func SetLevel(level, length int) FullPasswordConf
type InTransitionError ¶
type InTransitionError struct {
Event string
}
InTransitionError is returned by FSM.Event() when an asynchronous transition is already in progress.
func (InTransitionError) Error ¶
func (e InTransitionError) Error() string
type InternalError ¶
type InternalError struct{}
InternalError is returned by FSM.Event() and should never occur. It is a probably because of a bug.
func (InternalError) Error ¶
func (e InternalError) Error() string
type InvalidEventError ¶
InvalidEventError is returned by FSM.Event() when the event cannot be called in the current state.
func (InvalidEventError) Error ¶
func (e InvalidEventError) Error() string
type JsonUnmarshal ¶
type JsonUnmarshal struct{}
func (*JsonUnmarshal) ReadConfig ¶
func (j *JsonUnmarshal) ReadConfig(p []byte, v any) error
func (*JsonUnmarshal) ReadConfigFromFile ¶
func (j *JsonUnmarshal) ReadConfigFromFile(path string, v any) error
type LumberjackOption ¶
type LumberjackOption func(*lumberjack.Logger)
func Compress ¶
func Compress(b bool) LumberjackOption
func LocalTime ¶
func LocalTime(b bool) LumberjackOption
func MaxAge ¶
func MaxAge(i int) LumberjackOption
func MaxBackups ¶
func MaxBackups(i int) LumberjackOption
func MaxSize ¶
func MaxSize(i int) LumberjackOption
type NoTransitionError ¶
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 ¶
func (e NoTransitionError) Error() string
type NotInTransitionError ¶
type NotInTransitionError struct{}
NotInTransitionError is returned by FSM.Transition() when an asynchronous transition is not in progress.
func (NotInTransitionError) Error ¶
func (e NotInTransitionError) Error() string
type Pretty ¶
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 ¶
type PrettyDB interface { Pretty BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) Begin() (*sql.Tx, error) }
func NewMariaDB ¶
func NewMariaDB() PrettyDB
func NewPostgresDB ¶
func NewPostgresDB() PrettyDB
type PrettyTx ¶
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 ¶
func NewPostgresTx ¶
type RedisOption ¶
type RedisOption func(*redis.Options)
func RedisAddr ¶
func RedisAddr(addr string) RedisOption
func RedisDB ¶
func RedisDB(db int) RedisOption
func RedisPassword ¶
func RedisPassword(pwd string) RedisOption
func RedisPoolSize ¶
func RedisPoolSize(poolSize int) RedisOption
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server -.
func NewHttpServer ¶
func NewHttpServer(handler http.Handler, opts ...ServerOption) *Server
NewHttpServer -.
type Signer ¶
type Signer interface { Sign(data []byte) ([]byte, error) Verify(data []byte, signature []byte) error }
func NewRSASignFromBytes ¶
func NewRSASignFromFile ¶
type TaskContext ¶
type TomlUnmarshal ¶
type TomlUnmarshal struct{}
func (*TomlUnmarshal) ReadConfig ¶
func (t *TomlUnmarshal) ReadConfig(p []byte, v any) error
func (*TomlUnmarshal) ReadConfigFromFile ¶
func (t *TomlUnmarshal) ReadConfigFromFile(path string, v any) error
type Transition ¶
type Transition int
type UnknownEventError ¶
type UnknownEventError struct {
Event string
}
UnknownEventError is returned by FSM.Event() when the event is not defined.
func (UnknownEventError) Error ¶
func (e UnknownEventError) Error() string
type UnmarshalConfiger ¶
type UnmarshalConfiger interface { ReadConfig(p []byte, v any) error ReadConfigFromFile(path string, v any) error }
func NewJsonUnmarshal ¶
func NewJsonUnmarshal() UnmarshalConfiger
func NewTomlUnmarshal ¶
func NewTomlUnmarshal() UnmarshalConfiger
func NewYamlUnmarshal ¶
func NewYamlUnmarshal() UnmarshalConfiger
type YamlUnmarshal ¶
type YamlUnmarshal struct{}
func (*YamlUnmarshal) ReadConfig ¶
func (y *YamlUnmarshal) ReadConfig(p []byte, v any) error
func (*YamlUnmarshal) ReadConfigFromFile ¶
func (y *YamlUnmarshal) ReadConfigFromFile(path string, v any) error