aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/config.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-31 01:51:19 +0800
committerobscuren <geffobscura@gmail.com>2014-05-31 01:51:19 +0800
commit9e8127accba0d926436d3c0adf65b91149a94783 (patch)
treee79840991dcd0e424830c88fdbe81961126c0d67 /ethutil/config.go
parent17c825f53a2676ffe17fd7731f8f550aebcb56b0 (diff)
downloadgo-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar.gz
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar.bz2
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar.lz
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar.xz
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.tar.zst
go-tangerine-9e8127accba0d926436d3c0adf65b91149a94783.zip
woops
Diffstat (limited to 'ethutil/config.go')
-rw-r--r--ethutil/config.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/ethutil/config.go b/ethutil/config.go
index 916b0d186..4f7820eed 100644
--- a/ethutil/config.go
+++ b/ethutil/config.go
@@ -1,7 +1,9 @@
package ethutil
import (
+ "flag"
"fmt"
+ "github.com/rakyll/globalconf"
"log"
"os"
"os/user"
@@ -20,6 +22,8 @@ type config struct {
ClientString string
Pubkey []byte
Identifier string
+
+ conf *globalconf.GlobalConf
}
const defaultConf = `
@@ -67,11 +71,12 @@ func ApplicationFolder(base string) string {
// Read config
//
// Initialize the global Config variable with default settings
-func ReadConfig(base string, logTypes LoggerType, id string) *config {
+func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id string) *config {
if Config == nil {
path := ApplicationFolder(base)
Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"}
+ Config.conf = g
Config.Identifier = id
Config.Log = NewLogger(logTypes, LogLevelDebug)
Config.SetClientString("/Ethereum(G)")
@@ -90,6 +95,16 @@ func (c *config) SetClientString(str string) {
Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, id)
}
+func (c *config) SetIdentifier(id string) {
+ c.Identifier = id
+ c.Set("id", id)
+}
+
+func (c *config) Set(key, value string) {
+ f := &flag.Flag{Name: key, Value: &confValue{value}}
+ c.conf.Set("", f)
+}
+
type LoggerType byte
const (
@@ -190,3 +205,10 @@ func (log *Logger) Fatal(v ...interface{}) {
os.Exit(1)
}
+
+type confValue struct {
+ value string
+}
+
+func (self confValue) String() string { return self.value }
+func (self confValue) Set(s string) error { self.value = s; return nil }