codecamp

GoFrame 配置管理-接口化设计

gcfg​组件采用了接口化设计,以实现高扩展性。通过接口化设计的方式,使用者可以自定义对接的配置获取方式,例如​etcd​, ​zookeeper​, ​consule​, ​kubernetes ​​configmap​, ​apollo​等等。

接口定义

https://github.com/gogf/gf/v2/blob/master/os/gcfg/gcfg_adaper.go

// Adapter is the interface for configuration retrieving.
type Adapter interface {
	// Available checks and returns the configuration service is available.
	// The optional parameter `resource` specifies certain configuration resource.
	//
	// It returns true if configuration file is present in default AdapterFile, or else false.
	// Note that this function does not return error as it just does simply check for backend configuration service.
	Available(ctx context.Context, resource ...string) (ok bool)

	// Get retrieves and returns value by specified `pattern`.
	Get(ctx context.Context, pattern string) (value interface{}, err error)

	// Data retrieves and returns all configuration data as map type.
	// Note that this function may lead lots of memory usage if configuration data is too large,
	// you can implement this function if necessary.
	Data(ctx context.Context) (data map[string]interface{}, err error)
}

设置接口实现

// SetAdapter sets the adapter of current Config object.
func (c *Config) SetAdapter(adapter Adapter)

获取接口实现

// GetAdapter returns the adapter of current Config object.
func (c *Config) GetAdapter() Adapter


GoFrame 配置管理-常用方法
GoFrame 配置管理-YAML格式
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

GoFrame 核心组件

GoFrame 核心组件-数据库ORM

GoFrame 模块列表

GoFrame 模块列表-单元测试

GoFrame 模块列表-功能调试

GoFrame WEB服务开发

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }