Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(format string, args ...interface{})
- func DeepCopy(src interface{}, dst interface{}) error
- func EnsureDir(path string) error
- func Error(format string, args ...interface{})
- func Fatal(format string, args ...interface{})
- func FormatFileSize(size int64) string
- func GetCurrentDirectory() string
- func GetExecutablePath() (string, error)
- func Info(format string, args ...interface{})
- func IsValidEmail(email string) bool
- func MD5(str string) string
- func PathExists(path string) (bool, error)
- func RandomString(length int) string
- func Retry(attempts int, sleep time.Duration, fn func() error) error
- func SHA256(str string) string
- func TruncateString(str string, length int) string
- func Warn(format string, args ...interface{})
- type AsyncRunner
- type ConfigFormat
- type ConfigOption
- type ConfigWatcher
- type DaoConfig
- func (dc *DaoConfig) AddWatcher(watcher ConfigWatcher)
- func (dc *DaoConfig) Close() error
- func (dc *DaoConfig) Delete(key string)
- func (dc *DaoConfig) Get(key string) (interface{}, bool)
- func (dc *DaoConfig) Load() error
- func (dc *DaoConfig) Save() error
- func (dc *DaoConfig) Set(key string, value interface{})
- type DaoLogger
- func (dl *DaoLogger) Debug(format string, args ...interface{})
- func (dl *DaoLogger) Error(format string, args ...interface{})
- func (dl *DaoLogger) Fatal(format string, args ...interface{})
- func (dl *DaoLogger) Info(format string, args ...interface{})
- func (dl *DaoLogger) Rotate() error
- func (dl *DaoLogger) Warn(format string, args ...interface{})
- type DaoScheduler
- func (ds *DaoScheduler) AddScheduledTask(id string, name string, fn TaskFunc, interval time.Duration) error
- func (ds *DaoScheduler) AddTask(id string, name string, fn TaskFunc, priority TaskPriority) error
- func (ds *DaoScheduler) GetTaskStatus(id string) (TaskStatus, error)
- func (ds *DaoScheduler) IsRunning() bool
- func (ds *DaoScheduler) RemoveTask(id string) error
- func (ds *DaoScheduler) Start()
- func (ds *DaoScheduler) Stop()
- type LogLevel
- type LoggerOption
- type MemoryCache
- type RuntimeStats
- type Task
- type TaskFunc
- type TaskPriority
- type TaskStatus
Constants ¶
View Source
const ( TimeFormatFull = "2006-01-02 15:04:05.000" TimeFormatStandard = "2006-01-02 15:04:05" TimeFormatDate = "2006-01-02" TimeFormatTime = "15:04:05" )
TimeFormat 常用时间格式
View Source
const ( KB = 1024 MB = 1024 * KB GB = 1024 * MB TB = 1024 * GB )
ByteSize 字节大小单位
Variables ¶
View Source
var ( ErrTaskExists = errors.New("任务已存在") ErrTaskNotFound = errors.New("任务不存在") ErrSchedulerStopped = errors.New("调度器已停止") )
View Source
var DefaultLogger = NewDaoLogger()
全局默认日志器
Functions ¶
Types ¶
type AsyncRunner ¶
type AsyncRunner struct {
// contains filtered or unexported fields
}
AsyncRunner 异步任务运行器
type ConfigFormat ¶
type ConfigFormat string
ConfigFormat 配置文件格式
const ( FormatJSON ConfigFormat = "json" FormatXML ConfigFormat = "xml" FormatYAML ConfigFormat = "yaml" )
type ConfigOption ¶
type ConfigOption struct { AutoReload bool // 自动重载 ReloadInterval time.Duration // 重载间隔 BackupCount int // 备份数量 Format ConfigFormat // 配置格式 }
ConfigOption 配置选项
type ConfigWatcher ¶
type ConfigWatcher interface {
OnConfigChange(oldConfig, newConfig map[string]interface{})
}
ConfigWatcher 配置变更观察者
type DaoConfig ¶
type DaoConfig struct {
// contains filtered or unexported fields
}
DaoConfig 配置管理器
func NewDaoConfig ¶
func NewDaoConfig(filepath string, opt ConfigOption) (*DaoConfig, error)
NewDaoConfig 创建新的配置管理器
func (*DaoConfig) AddWatcher ¶
func (dc *DaoConfig) AddWatcher(watcher ConfigWatcher)
AddWatcher 添加配置观察者
type DaoLogger ¶
type DaoLogger struct {
// contains filtered or unexported fields
}
DaoLogger 道家风格的日志器
type DaoScheduler ¶
type DaoScheduler struct {
// contains filtered or unexported fields
}
DaoScheduler 调度器
func (*DaoScheduler) AddScheduledTask ¶
func (ds *DaoScheduler) AddScheduledTask(id string, name string, fn TaskFunc, interval time.Duration) error
AddScheduledTask 添加定时任务
func (*DaoScheduler) AddTask ¶
func (ds *DaoScheduler) AddTask(id string, name string, fn TaskFunc, priority TaskPriority) error
AddTask 添加任务
func (*DaoScheduler) GetTaskStatus ¶
func (ds *DaoScheduler) GetTaskStatus(id string) (TaskStatus, error)
GetTaskStatus 获取任务状态
func (*DaoScheduler) RemoveTask ¶
func (ds *DaoScheduler) RemoveTask(id string) error
RemoveTask 移除任务
type MemoryCache ¶
MemoryCache 简单的内存缓存实现
type RuntimeStats ¶
type RuntimeStats struct { GoVersion string GOOS string GOARCH string NumCPU int NumGoroutine int MemStats runtime.MemStats }
RuntimeStats 运行时统计信息
type Task ¶
type Task struct { ID string Name string Func TaskFunc Priority TaskPriority Status TaskStatus Interval time.Duration // 定时任务间隔 NextRun time.Time LastRun time.Time Error error Context context.Context Cancel context.CancelFunc }
Task 任务结构
type TaskPriority ¶
type TaskPriority int
TaskPriority 任务优先级
const ( PriorityLow TaskPriority = iota PriorityNormal PriorityHigh PriorityCritical )
type TaskStatus ¶
type TaskStatus int
TaskStatus 任务状态
const ( StatusPending TaskStatus = iota StatusRunning StatusCompleted StatusFailed StatusCancelled )
Directories
¶
Path | Synopsis |
---|---|
tools/async/pool.go
|
tools/async/pool.go |
tools/cache/cache.go
|
tools/cache/cache.go |
tools/common/types.go
|
tools/common/types.go |
tools/config/config.go
|
tools/config/config.go |
tools/logger/logger.go
|
tools/logger/logger.go |
tools/scheduler/scheduler.go
|
tools/scheduler/scheduler.go |
Click to show internal directories.
Click to hide internal directories.