新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFrame配置管理-接口化設(shè)計
?gcfg?組件采用了接口化設(shè)計,以實現(xiàn)高擴展性。通過接口化設(shè)計的方式,使用者可以自定義對接的配置獲取方式,例如?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)
}設(shè)置接口實現(xiàn)
// SetAdapter sets the adapter of current Config object.
func (c *Config) SetAdapter(adapter Adapter)獲取接口實現(xiàn)
// GetAdapter returns the adapter of current Config object.
func (c *Config) GetAdapter() Adapter 文章名稱:創(chuàng)新互聯(lián)GoFrame教程:GoFrame配置管理-接口化設(shè)計
地址分享:http://fisionsoft.com.cn/article/cdspdge.html


咨詢
建站咨詢
