72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package modules
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/utils/mapstructure"
|
|
"time"
|
|
)
|
|
|
|
type (
|
|
IOptions interface {
|
|
core.IModuleOptions
|
|
GetDebug() bool
|
|
GetLog() log.ILogger
|
|
}
|
|
Options struct {
|
|
Debug bool //日志是否开启
|
|
Log log.ILogger
|
|
}
|
|
)
|
|
|
|
func (this *Options) GetDebug() bool {
|
|
return this.Debug
|
|
}
|
|
|
|
func (this *Options) GetLog() log.ILogger {
|
|
return this.Log
|
|
}
|
|
|
|
func (this *Options) LoadConfig(settings map[string]interface{}) (err error) {
|
|
if settings != nil {
|
|
err = mapstructure.Decode(settings, this)
|
|
}
|
|
|
|
if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 3)); this.Log == nil {
|
|
err = errors.New("log is nil")
|
|
}
|
|
return
|
|
}
|
|
|
|
type DBOption func(*DBOptions)
|
|
type DBOptions struct {
|
|
IsMgoLog bool //是否写mgolog
|
|
Expire time.Duration //过期时间
|
|
}
|
|
|
|
//设置是否写mgor日志
|
|
func SetDBMgoLog(v bool) DBOption {
|
|
return func(o *DBOptions) {
|
|
o.IsMgoLog = v
|
|
}
|
|
}
|
|
|
|
//设置过期时间
|
|
func SetDBExpire(v time.Duration) DBOption {
|
|
return func(o *DBOptions) {
|
|
o.Expire = v
|
|
}
|
|
}
|
|
|
|
//更具 Option 序列化 系统参数对象
|
|
func newDBOption(opts ...DBOption) DBOptions {
|
|
options := DBOptions{
|
|
IsMgoLog: true,
|
|
}
|
|
for _, o := range opts {
|
|
o(&options)
|
|
}
|
|
return options
|
|
}
|