补充项目中的注释

This commit is contained in:
liwei1dao 2022-06-08 18:08:22 +08:00
parent 455f930339
commit f0eba2a844
3 changed files with 25 additions and 5 deletions

5
sys/cache/cache.go vendored
View File

@ -2,6 +2,10 @@ package cache
import "go_dreamfactory/lego/sys/redis" import "go_dreamfactory/lego/sys/redis"
/*
缓存系统的基础结构 包含系统的配置阐述以及 底层操作redis的 redis.ISys 对象
*/
func newSys(options Options) (sys *Cache, err error) { func newSys(options Options) (sys *Cache, err error) {
sys = &Cache{options: options} sys = &Cache{options: options}
err = sys.init() err = sys.init()
@ -13,6 +17,7 @@ type Cache struct {
redis redis.ISys redis redis.ISys
} }
//初始化 redis 对象
func (this *Cache) init() (err error) { func (this *Cache) init() (err error) {
this.redis, err = redis.NewSys( this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Cluster), redis.SetRedisType(redis.Redis_Cluster),

13
sys/cache/core.go vendored
View File

@ -1,17 +1,23 @@
package cache package cache
/*
redis 缓存数据管理系统
*/
type ( type (
ISys interface { ISys interface {
IUser IUser //户模块的相关缓存接口
IPack IPack //背包模块的线管缓存接口
IMail IMail //邮件相关的缓存接口
} }
) )
const () const ()
//全局使用的系统对象
var Defsys ISys var Defsys ISys
//初始化缓存系统
func OnInit(config map[string]interface{}, option ...Option) (err error) { func OnInit(config map[string]interface{}, option ...Option) (err error) {
var options Options var options Options
if options, err = newOptions(config, option...); err != nil { if options, err = newOptions(config, option...); err != nil {
@ -21,6 +27,7 @@ func OnInit(config map[string]interface{}, option ...Option) (err error) {
return return
} }
//系统实例化接口 每个系统默认都会提供全局以及实例化的接口
func NewSys(option ...Option) (sys ISys, err error) { func NewSys(option ...Option) (sys ISys, err error) {
var options Options var options Options
if options, err = newOptionsByOption(option...); err != nil { if options, err = newOptionsByOption(option...); err != nil {

12
sys/cache/options.go vendored
View File

@ -6,23 +6,30 @@ import (
"go_dreamfactory/lego/utils/mapstructure" "go_dreamfactory/lego/utils/mapstructure"
) )
/*
系统启动相关的配置参数定义
*/
type Option func(*Options) type Option func(*Options)
type Options struct { type Options struct {
Redis_Addr []string Redis_Addr []string //redis 的集群地址
Redis_Password string Redis_Password string //redis的密码
} }
//设置系统的集群地址
func Set_Redis_Addr(v []string) Option { func Set_Redis_Addr(v []string) Option {
return func(o *Options) { return func(o *Options) {
o.Redis_Addr = v o.Redis_Addr = v
} }
} }
//设置系统的密码配置
func Set_Redis_Password(v string) Option { func Set_Redis_Password(v string) Option {
return func(o *Options) { return func(o *Options) {
o.Redis_Password = v o.Redis_Password = v
} }
} }
//更具 map对象或者Option 序列化 系统参数对象
func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { func newOptions(config map[string]interface{}, opts ...Option) (Options, error) {
options := Options{} options := Options{}
if config != nil { if config != nil {
@ -37,6 +44,7 @@ func newOptions(config map[string]interface{}, opts ...Option) (Options, error)
return options, nil return options, nil
} }
//更具 Option 序列化 系统参数对象
func newOptionsByOption(opts ...Option) (Options, error) { func newOptionsByOption(opts ...Option) (Options, error) {
options := Options{} options := Options{}
for _, o := range opts { for _, o := range opts {