base

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INTERVAL_DAY     = iota //当前时间的第二天
	INTERVAL_WEEK    = iota //当前时间的下周一
	INTERVAL_MONTH   = iota //当前时间的下一月第一天)
	INTERVAL_YEAR    = iota //当前时间的下一年第一天)
	TIME_SET_MAX_VAL = iota //类型最大值
)
View Source
const (
	HOUR_NAME     = "HOUR"
	HOUR_INTERVAL = 60 * 60 * 1e3
	HOUR_SCALES   = 12

	MINUTE_NAME     = "MINUTE"
	MINUTE_INTERVAL = 60 * 1e3
	MINUTE_SCALES   = 60

	SECOND_NAME     = "SECOND"
	SECOND_INTERVAL = 1e3
	SECOND_SCALES   = 60

	TIMERS_MAX_CAP = 2048
)
View Source
const (
	MAX_CHAN_BUFF  = 2048
	MAX_TIME_DELAY = 100
)
View Source
const (
	WorkeridMax = workeridMax //集群自增量
)

Snowflake 算法

Variables

View Source
var LogLevelNameMap = map[string]LogLevel{
	"debug": LogLevelDebug,
	"info":  LogLevelInfo,
	"warn":  LogLevelWarn,
	"error": LogLevelError,
	"fatal": LogLevelFatal,
	"off":   LogLevelAllOff,
}
View Source
var NowTick int64
View Source
var StartTick int64
View Source
var Timestamp int64

Functions

func After

func After(ms int) <-chan time.Time

func Atof

func Atof(str string) float32

func Atof64

func Atof64(str string) float64

func Atoi

func Atoi(str string) int

func Atoi64

func Atoi64(str string) int64

func FromByteJSON

func FromByteJSON(data []byte, obj interface{}) error

FromByteJSON 返回序列化对象

func FromJSON

func FromJSON(data string, obj interface{}) error

FromJSON 返回序列化为对象

func GetDate

func GetDate() string

func GetHour

func GetHour(timestamp int64) int

func GetHour24

func GetHour24(timestamp int64) int

func GetMaxMsgChanLen

func GetMaxMsgChanLen() uint32

func GetMsgSessionId

func GetMsgSessionId() uint64

func GetNextHourIntervalS

func GetNextHourIntervalS(timestamp int64) int

func GetNextTime

func GetNextTime(intervalType int) time.Time

func GetNowTime

func GetNowTime() time.Time

func GetTimestamp

func GetTimestamp() int64

func GetUnixMs

func GetUnixMs() int64

func GetUnixNano

func GetUnixNano() int64

func GetUnixTime

func GetUnixTime(sec, nsec int64) time.Time

func GetYearMonthDay

func GetYearMonthDay(timestamp int64) (int32, int32, int32)

func Go

func Go(fn func())

func InitJsonConfigFile

func InitJsonConfigFile(configFilePath string, out interface{}) error

InitConfigFile 初始化配置文件信息

func IsDiffDay

func IsDiffDay(now, old int64) int

func Itoa

func Itoa(num interface{}) string

func LogDebug

func LogDebug(v ...interface{})

func LogError

func LogError(v ...interface{})

func LogFatal

func LogFatal(v ...interface{})

func LogInfo

func LogInfo(v ...interface{})

func LogSimpleStack

func LogSimpleStack() string

func LogStack

func LogStack()

func LogWarn

func LogWarn(v ...interface{})

func MD5Bytes

func MD5Bytes(s []byte) string

func MD5Str

func MD5Str(s string) string

func MD5WithSalt

func MD5WithSalt(s string) string

func NewTicker

func NewTicker(ms int) *time.Ticker

func NewTimer

func NewTimer(ms int) *time.Timer

func ParseBool

func ParseBool(s string) bool

func ParseInt32

func ParseInt32(s string) int32

func ParseInt64

func ParseInt64(s string) int64

func ParseTime

func ParseTime(str string) (time.Time, error)

func ParseUint32

func ParseUint32(s string) uint32

func ParseUint64

func ParseUint64(s string) uint64

func Print

func Print(a ...interface{}) (int, error)

func Printf

func Printf(format string, a ...interface{}) (int, error)

func Println

func Println(a ...interface{}) (int, error)

func SetFileLog

func SetFileLog(filepath string, maxsize int)

func Sleep

func Sleep(ms int)

func Sprintf

func Sprintf(format string, a ...interface{}) string

func Tick

func Tick(ms int) <-chan time.Time

func ToJson

func ToJson(obj interface{}) string

ToJson JSON化字符串

func Try

func Try(fun func(), handler func(interface{}))

Types

type ConsoleLogger

type ConsoleLogger struct {
	Pln bool
}

func (*ConsoleLogger) Write

func (l *ConsoleLogger) Write(msg string)

type DelayFunc

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

func NewDelayFunc

func NewDelayFunc(f func(v ...interface{}), args []interface{}) *DelayFunc

func (*DelayFunc) Call

func (df *DelayFunc) Call()

func (*DelayFunc) String

func (df *DelayFunc) String() string

type FileLogger

type FileLogger struct {
	FilePath string
	Pln      bool
	MaxSize  int
	// contains filtered or unexported fields
}

func (*FileLogger) Write

func (l *FileLogger) Write(msg string)

type GlobalObj

type GlobalObj struct {
	MaxMsgDataSize uint32 //都需数据包的最大值
	MaxConn        int    //当前服务器主机允许的最大链接个数
	MaxMsgChanLen  uint32 //SendBuffMsg发送消息的缓冲最大长度
	MsgSessionId   uint64 //消息队列id
}
var GlobalObject *GlobalObj

func GetGlobal

func GetGlobal() *GlobalObj

type ILogger

type ILogger interface {
	Write(msg string)
}

type ISnowflake

type ISnowflake interface {
	Init(workerid int64)
	UUID() int64
}

type Log

type Log struct {
	// contains filtered or unexported fields
}
var DefLog *Log //日志

func GetLog

func GetLog() *Log

func NewLog

func NewLog(bufsize int, logger ...ILogger) *Log

func (*Log) Debug

func (r *Log) Debug(v ...interface{})

func (*Log) Error

func (r *Log) Error(v ...interface{})

func (*Log) Fatal

func (r *Log) Fatal(v ...interface{})

func (*Log) GetLevel

func (r *Log) GetLevel() LogLevel

func (*Log) Info

func (r *Log) Info(v ...interface{})

func (*Log) IsStop

func (r *Log) IsStop() bool

func (*Log) SetLevel

func (r *Log) SetLevel(level LogLevel)

func (*Log) SetLevelByName

func (r *Log) SetLevelByName(name string) bool

func (*Log) SetLogger

func (r *Log) SetLogger(logger ILogger) bool

func (*Log) StartLoop

func (r *Log) StartLoop()

func (*Log) Stop

func (r *Log) Stop()

func (*Log) Warn

func (r *Log) Warn(v ...interface{})

func (*Log) Write

func (r *Log) Write(v ...interface{})

type LogLevel

type LogLevel int
const (
	LogLevelDebug  LogLevel = iota //调试信息
	LogLevelInfo                   //资讯讯息
	LogLevelWarn                   //警告状况发生
	LogLevelError                  //一般错误,可能导致功能不正常
	LogLevelFatal                  //严重错误,会导致进程退出
	LogLevelAllOff                 //关闭所有日志
)

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSnowflake

func NewSnowflake(workerId int64) (*Snowflake, error)

实例化一个工作节点

func (*Snowflake) Init

func (this *Snowflake) Init(workerid int64)

func (*Snowflake) UUID

func (s *Snowflake) UUID() int64

Generate creates and returns a unique snowflake ID

type TimeWheel

type TimeWheel struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTimeWheel

func NewTimeWheel(name string, interval int64, scales int, maxCap int) *TimeWheel

func (*TimeWheel) AddTimeWheel

func (tw *TimeWheel) AddTimeWheel(next *TimeWheel)

func (*TimeWheel) AddTimer

func (tw *TimeWheel) AddTimer(tid uint32, t *Timer) error

func (*TimeWheel) GetTimerWithIn

func (tw *TimeWheel) GetTimerWithIn(duration time.Duration) map[uint32]Timer

func (*TimeWheel) RemoveTimer

func (tw *TimeWheel) RemoveTimer(tid uint32)

func (*TimeWheel) Run

func (tw *TimeWheel) Run()

type Timer

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

func NewTimerAfter

func NewTimerAfter(duration time.Duration, f func(v ...interface{}), args []interface{}) *Timer

func NewTimerAt

func NewTimerAt(unixNano int64, f func(v ...interface{}), args []interface{}) *Timer

func NewTimerInterval

func NewTimerInterval(duration time.Duration, times int, f func(v ...interface{}), args []interface{}) *Timer

func (*Timer) Run

func (t *Timer) Run()

type TimerScheduler

type TimerScheduler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewAutoExecTimerScheduler

func NewAutoExecTimerScheduler() *TimerScheduler

func NewTimerScheduler

func NewTimerScheduler() *TimerScheduler

func (*TimerScheduler) CancelTimer

func (this *TimerScheduler) CancelTimer(tid uint32)

func (*TimerScheduler) CreateTimerAt

func (this *TimerScheduler) CreateTimerAt(unixNano int64, f func(v ...interface{}), args []interface{}) (uint32, error)

func (*TimerScheduler) GetTriggerChan

func (this *TimerScheduler) GetTriggerChan() chan *DelayFunc

func (*TimerScheduler) NewTimerAfter

func (this *TimerScheduler) NewTimerAfter(duration time.Duration, f func(v ...interface{}), args []interface{}) (uint32, error)

func (*TimerScheduler) NewTimerInterval

func (this *TimerScheduler) NewTimerInterval(duration time.Duration, times int, f func(v ...interface{}), args []interface{}) (uint32, error)

func (*TimerScheduler) Start

func (this *TimerScheduler) Start()

Jump to

Keyboard shortcuts

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