创新互联GoFrame教程: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配置管理-接口化设计
文章网址:http://www.hantingmc.com/qtweb/news8/361658.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联