add Available function for Adapter of package gcfg

This commit is contained in:
John Guo
2021-11-27 01:36:21 +08:00
parent c33378540a
commit 817c3ce698
2 changed files with 11 additions and 2 deletions

View File

@ -92,6 +92,15 @@ func (c *Config) GetAdapter() Adapter {
return c.adapter
}
// Available checks and returns the configuration service is available.
// The optional parameter `pattern` 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.
func (c *Config) Available(ctx context.Context, resource ...string) (ok bool) {
return c.adapter.Available(ctx, resource...)
}
// Set sets value with specified `pattern`.
// It supports hierarchical data access by char separator, which is '.' in default.
// It is commonly used for updates certain configuration value in runtime.

View File

@ -11,11 +11,11 @@ import "context"
// Adapter is the interface for configuration retrieving.
type Adapter interface {
// Available checks and returns the configuration service is available.
// The optional parameter `pattern` specifies certain configuration resource.
// 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, pattern ...string) (ok bool)
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)