Be more like a library to support mobile (#247)
This commit is contained in:
20
config.go
20
config.go
@ -1,6 +1,7 @@
|
||||
package nebula
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -56,6 +57,13 @@ func (c *Config) Load(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) LoadString(raw string) error {
|
||||
if raw == "" {
|
||||
return errors.New("Empty configuration")
|
||||
}
|
||||
return c.parseRaw([]byte(raw))
|
||||
}
|
||||
|
||||
// RegisterReloadCallback stores a function to be called when a config reload is triggered. The functions registered
|
||||
// here should decide if they need to make a change to the current process before making the change. HasChanged can be
|
||||
// used to help decide if a change is necessary.
|
||||
@ -407,6 +415,18 @@ func (c *Config) addFile(path string, direct bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) parseRaw(b []byte) error {
|
||||
var m map[interface{}]interface{}
|
||||
|
||||
err := yaml.Unmarshal(b, &m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Settings = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) parse() error {
|
||||
var m map[interface{}]interface{}
|
||||
|
||||
|
Reference in New Issue
Block a user