From 817c3ce698904bdb8beaffb6e782b94a28eed9ec Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 27 Nov 2021 01:36:21 +0800 Subject: [PATCH] add Available function for Adapter of package gcfg --- os/gcfg/gcfg.go | 9 +++++++++ os/gcfg/gcfg_adaper.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/os/gcfg/gcfg.go b/os/gcfg/gcfg.go index f21bb8013..4bf0f5f68 100644 --- a/os/gcfg/gcfg.go +++ b/os/gcfg/gcfg.go @@ -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. diff --git a/os/gcfg/gcfg_adaper.go b/os/gcfg/gcfg_adaper.go index 4c354e62c..e45c5cd5c 100644 --- a/os/gcfg/gcfg_adaper.go +++ b/os/gcfg/gcfg_adaper.go @@ -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)