diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
commit | b5234413611ce5984292f85a01de1f56c045b490 (patch) | |
tree | e6e0c6f7fe8358a2dc63cdea11ac66b4f59397f5 /ethutil/config.go | |
parent | 0b8f66ed9ef177dc72442dd7ba337c6733e30344 (diff) | |
download | dexon-b5234413611ce5984292f85a01de1f56c045b490.tar dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.gz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.bz2 dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.lz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.xz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.zst dexon-b5234413611ce5984292f85a01de1f56c045b490.zip |
Moved ethutil => common
Diffstat (limited to 'ethutil/config.go')
-rw-r--r-- | ethutil/config.go | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/ethutil/config.go b/ethutil/config.go deleted file mode 100644 index c45c310ce..000000000 --- a/ethutil/config.go +++ /dev/null @@ -1,67 +0,0 @@ -package ethutil - -import ( - "flag" - "fmt" - "os" - - "github.com/rakyll/globalconf" -) - -// Config struct -type ConfigManager struct { - ExecPath string - Debug bool - Diff bool - DiffType string - Paranoia bool - VmType int - - conf *globalconf.GlobalConf -} - -// Read config -// -// Initialize Config from Config File -func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager { - if !FileExist(ConfigFile) { - // create ConfigFile if it does not exist, otherwise - // globalconf will panic when trying to persist flags. - fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile) - os.Create(ConfigFile) - } - g, err := globalconf.NewWithOptions(&globalconf.Options{ - Filename: ConfigFile, - EnvPrefix: EnvPrefix, - }) - if err != nil { - fmt.Println(err) - } else { - g.ParseAll() - } - cfg := &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true} - return cfg -} - -// provides persistence for flags -func (c *ConfigManager) Save(key string, value interface{}) { - f := &flag.Flag{Name: key, Value: newConfValue(value)} - c.conf.Set("", f) -} - -func (c *ConfigManager) Delete(key string) { - c.conf.Delete("", key) -} - -// private type implementing flag.Value -type confValue struct { - value string -} - -// generic constructor to allow persising non-string values directly -func newConfValue(value interface{}) *confValue { - return &confValue{fmt.Sprintf("%v", value)} -} - -func (self confValue) String() string { return self.value } -func (self confValue) Set(s string) error { self.value = s; return nil } |