config

package
v1.3.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ApolloCfg      *apolloConfig.AppConfig
	ApolloCfg *apollo.Config
	// ApolloListener 存储需要监听的 Apollo 配置项名称
	ApolloListener []string
	// Item2Obj 存储配置项名称和对应的加载器对象的映射
	Item2Obj = map[string]Load{}
)

Functions

This section is empty.

Types

type Cfg

type Cfg struct {
	// Lock 用于保证并发安全的互斥锁
	Lock sync.Mutex
}

Cfg 结构体包含配置操作的相关方法

func NewV1

func NewV1() *Cfg

NewV1 创建一个新的 Cfg 实例

func (*Cfg) GetApollo

func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error)

GetApollo 从 Apollo 配置中心获取指定名称的配置 参数:

name - 配置文件的名称
obj  - 实现了 Load 接口的加载器对象

返回值:

*gjson.Json - 解析后的 JSON 对象
error       - 操作过程中遇到的错误

func (*Cfg) GetDbFile

func (c *Cfg) GetDbFile(name string) (res *g.Var, err error)

GetDbFile 从数据库中获取指定名称的配置文件 参数:

name - 配置文件的名称

返回值:

*g.Var - 存储配置数据的变量
error  - 操作过程中遇到的错误

func (*Cfg) GetFile

func (c *Cfg) GetFile(filename string, _pathStr ...string) (jsonObj *gjson.Json, err error)

GetFile 从文件系统或资源文件中加载 JSON 配置 参数:

filename   - 需要加载的配置文件名(不带扩展名)
_pathStr   - 可选参数,指定配置文件目录路径,默认"manifest/game/"

返回值:

*gjson.Json - 解析后的 JSON 对象
error       - 文件加载或解析过程中遇到的错误

func (*Cfg) GetUrlFile

func (c *Cfg) GetUrlFile(name string) (jsonObj *gjson.Json, err error)

GetUrlFile 获取远程配置 参数:

name - 配置文件的名称

返回值:

*gjson.Json - 解析后的 JSON 对象
error       - 请求或解析过程中遇到的错误

type CustomChangeListener

type CustomChangeListener struct {
	// contains filtered or unexported fields
}

CustomChangeListener 是 Apollo 配置变化的自定义监听器

func (*CustomChangeListener) OnChange

func (c *CustomChangeListener) OnChange(changeEvent *storage.ChangeEvent)

OnChange 当 Apollo 配置发生变化时触发

func (*CustomChangeListener) OnNewestChange

func (c *CustomChangeListener) OnNewestChange(event *storage.FullChangeEvent)

OnNewestChange 当获取到最新配置时触发,当前为空实现

type Load

type Load interface {
	// Load 方法用于加载配置数据,支持传入可选的配置参数
	Load(cfg ...string)
}

Load 接口定义了 Load 方法,用于加载数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL