58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package cache
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"go_dreamfactory/lego/utils/mapstructure"
|
|
)
|
|
|
|
/*
|
|
系统启动相关的配置参数定义
|
|
*/
|
|
type Option func(*Options)
|
|
type Options struct {
|
|
Redis_Addr []string //redis 的集群地址
|
|
Redis_Password string //redis的密码
|
|
}
|
|
|
|
//设置系统的集群地址
|
|
func Set_Redis_Addr(v []string) Option {
|
|
return func(o *Options) {
|
|
o.Redis_Addr = v
|
|
}
|
|
}
|
|
|
|
//设置系统的密码配置
|
|
func Set_Redis_Password(v string) Option {
|
|
return func(o *Options) {
|
|
o.Redis_Password = v
|
|
}
|
|
}
|
|
|
|
//更具 map对象或者Option 序列化 系统参数对象
|
|
func newOptions(config map[string]interface{}, opts ...Option) (Options, error) {
|
|
options := Options{}
|
|
if config != nil {
|
|
mapstructure.Decode(config, &options)
|
|
}
|
|
for _, o := range opts {
|
|
o(&options)
|
|
}
|
|
if options.Redis_Addr == nil || len(options.Redis_Addr) == 0 {
|
|
return options, errors.New("Redis_Addr is null")
|
|
}
|
|
return options, nil
|
|
}
|
|
|
|
//更具 Option 序列化 系统参数对象
|
|
func newOptionsByOption(opts ...Option) (Options, error) {
|
|
options := Options{}
|
|
for _, o := range opts {
|
|
o(&options)
|
|
}
|
|
if options.Redis_Addr == nil || len(options.Redis_Addr) == 0 {
|
|
return options, errors.New("Redis_Addr is null")
|
|
}
|
|
return options, nil
|
|
}
|