补充项目中的注释
This commit is contained in:
parent
455f930339
commit
f0eba2a844
5
sys/cache/cache.go
vendored
5
sys/cache/cache.go
vendored
@ -2,6 +2,10 @@ package cache
|
||||
|
||||
import "go_dreamfactory/lego/sys/redis"
|
||||
|
||||
/*
|
||||
缓存系统的基础结构 包含系统的配置阐述以及 底层操作redis的 redis.ISys 对象
|
||||
*/
|
||||
|
||||
func newSys(options Options) (sys *Cache, err error) {
|
||||
sys = &Cache{options: options}
|
||||
err = sys.init()
|
||||
@ -13,6 +17,7 @@ type Cache struct {
|
||||
redis redis.ISys
|
||||
}
|
||||
|
||||
//初始化 redis 对象
|
||||
func (this *Cache) init() (err error) {
|
||||
this.redis, err = redis.NewSys(
|
||||
redis.SetRedisType(redis.Redis_Cluster),
|
||||
|
13
sys/cache/core.go
vendored
13
sys/cache/core.go
vendored
@ -1,17 +1,23 @@
|
||||
package cache
|
||||
|
||||
/*
|
||||
redis 缓存数据管理系统
|
||||
*/
|
||||
|
||||
type (
|
||||
ISys interface {
|
||||
IUser
|
||||
IPack
|
||||
IMail
|
||||
IUser //户模块的相关缓存接口
|
||||
IPack //背包模块的线管缓存接口
|
||||
IMail //邮件相关的缓存接口
|
||||
}
|
||||
)
|
||||
|
||||
const ()
|
||||
|
||||
//全局使用的系统对象
|
||||
var Defsys ISys
|
||||
|
||||
//初始化缓存系统
|
||||
func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
||||
var options Options
|
||||
if options, err = newOptions(config, option...); err != nil {
|
||||
@ -21,6 +27,7 @@ func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//系统实例化接口 每个系统默认都会提供全局以及实例化的接口
|
||||
func NewSys(option ...Option) (sys ISys, err error) {
|
||||
var options Options
|
||||
if options, err = newOptionsByOption(option...); err != nil {
|
||||
|
12
sys/cache/options.go
vendored
12
sys/cache/options.go
vendored
@ -6,23 +6,30 @@ import (
|
||||
"go_dreamfactory/lego/utils/mapstructure"
|
||||
)
|
||||
|
||||
/*
|
||||
系统启动相关的配置参数定义
|
||||
*/
|
||||
type Option func(*Options)
|
||||
type Options struct {
|
||||
Redis_Addr []string
|
||||
Redis_Password string
|
||||
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 {
|
||||
@ -37,6 +44,7 @@ func newOptions(config map[string]interface{}, opts ...Option) (Options, error)
|
||||
return options, nil
|
||||
}
|
||||
|
||||
//更具 Option 序列化 系统参数对象
|
||||
func newOptionsByOption(opts ...Option) (Options, error) {
|
||||
options := Options{}
|
||||
for _, o := range opts {
|
||||
|
Loading…
Reference in New Issue
Block a user