summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/config
diff options
context:
space:
mode:
authorCarl Baldwin <carl@ecbaldwin.net>2019-07-24 09:01:43 -0600
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-08-28 09:06:20 +0900
commitd81023dd4d1db3b10215c21275cab75ddda9ec30 (patch)
tree12d9321d149ad12272ba1ae44d7230ce2e5790d0 /internal/pkg/config
parent1bbbc8b3b268932764dac8f50d41125f0e54fc94 (diff)
Allow simple one-shot reading of the config file
Diffstat (limited to 'internal/pkg/config')
-rw-r--r--internal/pkg/config/serve.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/internal/pkg/config/serve.go b/internal/pkg/config/serve.go
index 19b731b4..c1525525 100644
--- a/internal/pkg/config/serve.go
+++ b/internal/pkg/config/serve.go
@@ -24,27 +24,35 @@ type BgpConfigSet struct {
DynamicNeighbors []DynamicNeighbor `mapstructure:"dynamic-neighbors"`
}
+func ReadConfigfile(path, format string) (*BgpConfigSet, error) {
+ // Update config file type, if detectable
+ format = detectConfigFileType(path, format)
+
+ config := &BgpConfigSet{}
+ v := viper.New()
+ v.SetConfigFile(path)
+ v.SetConfigType(format)
+ var err error
+ if err = v.ReadInConfig(); err != nil {
+ return nil, err
+ }
+ if err = v.UnmarshalExact(config); err != nil {
+ return nil, err
+ }
+ if err = setDefaultConfigValuesWithViper(v, config); err != nil {
+ return nil, err
+ }
+ return config, nil
+}
+
func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP)
- // Update config file type, if detectable
- format = detectConfigFileType(path, format)
-
cnt := 0
for {
- c := &BgpConfigSet{}
- v := viper.New()
- v.SetConfigFile(path)
- v.SetConfigType(format)
- var err error
- if err = v.ReadInConfig(); err != nil {
- goto ERROR
- }
- if err = v.UnmarshalExact(c); err != nil {
- goto ERROR
- }
- if err = setDefaultConfigValuesWithViper(v, c); err != nil {
+ c, err := ReadConfigfile(path, format)
+ if err != nil {
goto ERROR
}
if cnt == 0 {