From c0a06609919d09fbcb6326ff69cc455dd13506ef Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 14 Sep 2013 22:37:06 +0200 Subject: Reduced duplicate code for config reading. --- confhelper/confhelper.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 confhelper/confhelper.go (limited to 'confhelper/confhelper.go') diff --git a/confhelper/confhelper.go b/confhelper/confhelper.go new file mode 100644 index 0000000..607f50f --- /dev/null +++ b/confhelper/confhelper.go @@ -0,0 +1,22 @@ +package confhelper + +import ( + "github.com/kch42/simpleconf" + "log" +) + +func ConfStringOrFatal(conf simpleconf.Config, section, key string) string { + s, err := conf.GetString(section, key) + if err != nil { + log.Fatalf("Could not read config value %s.%s: %s", section, key, err) + } + return s +} + +func ConfIntOrFatal(conf simpleconf.Config, section, key string) int64 { + i, err := conf.GetInt(section, key) + if err != nil { + log.Fatalf("Could not read config value %s.%s: %s", section, key, err) + } + return i +} -- cgit v1.2.3-54-g00ecf