aboutsummaryrefslogtreecommitdiff
path: root/envcfg.go
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-02-14 11:24:17 +0100
committerPacien TRAN-GIRARD2015-02-14 11:27:36 +0100
commit8e99baedf2c3e433750c2f51681f3c9d15d412be (patch)
tree3fa0ff3ea4823a408dadceb14fcd51ddc16c2aa8 /envcfg.go
parent8b1f88ce72ef8496879395e7f04b676e6a16e07a (diff)
downloadgo-envcfg-8e99baedf2c3e433750c2f51681f3c9d15d412be.tar.gz
First version
Diffstat (limited to 'envcfg.go')
-rw-r--r--envcfg.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/envcfg.go b/envcfg.go
new file mode 100644
index 0000000..b91ea13
--- /dev/null
+++ b/envcfg.go
@@ -0,0 +1,40 @@
1// Package envcfg provides environment variable mapping to structs.
2//
3// Can be used to read configuration parameters from the environment.
4//
5// Fields for which environment variables can be found are overwritten, otherwise they are left to their previous
6// value.
7//
8// Can be used, for example, after gcfg to override settings provided in a configuration file.
9package envcfg
10
11import (
12 "errors"
13 "reflect"
14)
15
16const (
17 TAG = "env"
18 ABS_TAG = "absenv"
19 SEP = "_"
20)
21
22type node struct {
23 parent *node
24 value *reflect.Value
25 properties *reflect.StructField
26}
27
28var ErrInvalidConfigStruct = errors.New("invalid parameter: must map to a struct")
29
30func ReadInto(cfgStruct interface{}) (interface{}, []error) {
31 s := reflect.ValueOf(cfgStruct).Elem()
32
33 if s.Kind() != reflect.Struct {
34 return nil, []error{ErrInvalidConfigStruct}
35 }
36
37 _, errs := setStructFields(node{nil, &s, nil})
38
39 return cfgStruct, errs
40}