├── .gitignore ├── LICENSE ├── README.md ├── conf.go ├── conf_test.go ├── go.mod ├── go.sum └── options.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | .vscode/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 影浅 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go_conf 2 | 3 | Packaging viper for daily multi-environment configuration 4 | -------------------------------------------------------------------------------- /conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "reflect" 5 | "strings" 6 | 7 | "github.com/fsnotify/fsnotify" 8 | "github.com/sohaha/zlsgo/zfile" 9 | "github.com/sohaha/zlsgo/zreflect" 10 | "github.com/sohaha/zlsgo/ztype" 11 | "github.com/spf13/viper" 12 | ) 13 | 14 | type Confhub struct { 15 | Core *viper.Viper 16 | filename string 17 | filepath string 18 | filesuffix string 19 | fullpath string 20 | option Options 21 | primary *Confhub 22 | data ztype.Map 23 | } 24 | 25 | func New(file string, opt ...func(o Options) Options) *Confhub { 26 | if file == "" { 27 | file = "zconf" 28 | } 29 | o := Options{ 30 | FileName: file, 31 | } 32 | for _, f := range opt { 33 | o = f(o) 34 | } 35 | 36 | var ( 37 | tmp []string 38 | suffix string 39 | tmpLen int 40 | core = viper.New() 41 | name = o.FileName 42 | path = "./" 43 | ) 44 | 45 | if o.AutomaticEnv { 46 | core.AutomaticEnv() 47 | } 48 | 49 | if o.EnvPrefix != "" { 50 | core.SetEnvPrefix(o.EnvPrefix) 51 | } 52 | 53 | if strings.Contains(name, "/") { 54 | tmp := strings.Split(name, "/") 55 | tmpLen = len(tmp) - 1 56 | path = strings.Join(tmp[0:tmpLen], "/") 57 | name = tmp[tmpLen] 58 | } 59 | 60 | tmp = strings.SplitN(name, ".", 2) 61 | tmpLen = len(tmp) - 1 62 | if tmpLen >= 1 { 63 | name = strings.Join(tmp[0:tmpLen], ".") 64 | suffix = tmp[tmpLen] 65 | } 66 | if suffix == "" { 67 | suffix = "toml" 68 | } 69 | 70 | path = zfile.RealPath(path, true) 71 | core.SetConfigName(name) 72 | core.AddConfigPath(path) 73 | 74 | var p *Confhub 75 | if o.PrimaryAliss != "" { 76 | p = New(name + "-" + o.PrimaryAliss) 77 | _ = p.Read() 78 | } 79 | 80 | return &Confhub{ 81 | primary: p, 82 | Core: core, 83 | filename: name, 84 | filepath: path, 85 | filesuffix: suffix, 86 | fullpath: path + name + "." + suffix, 87 | option: o, 88 | } 89 | } 90 | 91 | func (c *Confhub) Read() (err error) { 92 | err = c.Core.ReadInConfig() 93 | if err != nil { 94 | _, ok := err.(viper.ConfigFileNotFoundError) 95 | if ok { 96 | if c.option.AutoCreate || c.primary != nil { 97 | err = nil 98 | } 99 | data := c.Core.AllKeys() 100 | 101 | if !zfile.DirExist(c.filepath) { 102 | zfile.RealPathMkdir(c.filepath) 103 | } 104 | 105 | if len(data) > 0 && c.option.AutoCreate { 106 | err = c.Write() 107 | } 108 | } 109 | } 110 | if c.primary != nil { 111 | _ = c.Core.MergeConfigMap(c.primary.GetAll()) 112 | } 113 | return 114 | } 115 | 116 | func (c *Confhub) Exist() bool { 117 | return zfile.FileExist(c.fullpath) 118 | } 119 | 120 | func (c *Confhub) SetDefault(key string, value interface{}) { 121 | vof := reflect.Indirect(zreflect.ValueOf(value)) 122 | switch vof.Kind() { 123 | case reflect.Slice, reflect.Array: 124 | switch vof.Type().Elem().Kind() { 125 | case reflect.Struct: 126 | c.Core.SetDefault(key, ztype.ToMaps(value)) 127 | return 128 | } 129 | case reflect.Struct: 130 | c.Core.SetDefault(key, ztype.ToMap(value)) 131 | return 132 | } 133 | 134 | c.Core.SetDefault(key, value) 135 | } 136 | 137 | func (c *Confhub) Set(key string, value interface{}) { 138 | c.Core.Set(key, value) 139 | _ = c.GetAll(true) 140 | } 141 | 142 | func (c *Confhub) Get(key string) (value ztype.Type) { 143 | return ztype.New(c.Core.Get(key)) 144 | } 145 | 146 | func (c *Confhub) ConfigChange(fn func(e fsnotify.Event)) (err error) { 147 | watcher, err := fsnotify.NewWatcher() 148 | if err != nil { 149 | return err 150 | } 151 | 152 | _ = watcher.Close() 153 | c.Core.WatchConfig() 154 | c.Core.OnConfigChange(func(in fsnotify.Event) { 155 | _ = c.GetAll(true) 156 | fn(in) 157 | }) 158 | 159 | return nil 160 | } 161 | 162 | func (c *Confhub) GetAll(force ...bool) ztype.Map { 163 | if c.data == nil || (len(force) > 0 && force[0]) { 164 | c.data = c.Core.AllSettings() 165 | } 166 | return c.data 167 | } 168 | 169 | func (c *Confhub) AllKeys() []string { 170 | return c.Core.AllKeys() 171 | } 172 | 173 | func (c *Confhub) Write(filepath ...string) error { 174 | f := c.fullpath 175 | if len(filepath) > 0 { 176 | f = filepath[0] 177 | } 178 | return c.Core.WriteConfigAs(f) 179 | } 180 | 181 | func (c *Confhub) Path() string { 182 | return c.fullpath 183 | } 184 | 185 | func (c *Confhub) UnmarshalKey(key string, rawVal interface{}, force ...bool) error { 186 | return ztype.To(c.GetAll(force...).Get(key).Value(), rawVal) 187 | } 188 | 189 | func (c *Confhub) Unmarshal(rawVal interface{}, force ...bool) error { 190 | return ztype.To(c.GetAll(force...), rawVal) 191 | } 192 | -------------------------------------------------------------------------------- /conf_test.go: -------------------------------------------------------------------------------- 1 | package conf_test 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | "time" 7 | 8 | "github.com/fsnotify/fsnotify" 9 | "github.com/sohaha/zlsgo" 10 | "github.com/sohaha/zlsgo/zfile" 11 | "github.com/zlsgo/conf" 12 | ) 13 | 14 | type ( 15 | appString string 16 | Info struct { 17 | Age int `z:"a"` 18 | Name string `z:"name"` 19 | } 20 | ) 21 | 22 | type Demo struct { 23 | Name string `z:"zls"` 24 | App appString `json:"app"` 25 | Info Info 26 | } 27 | 28 | func TestDev(t *testing.T) { 29 | tt := zlsgo.NewTest(t) 30 | 31 | _ = zfile.WriteFile("test-dev.toml", []byte(`zls = "dev"`)) 32 | defer zfile.Remove("test-dev.toml") 33 | 34 | c := conf.New("test", func(o conf.Options) conf.Options { 35 | o.PrimaryAliss = "dev" 36 | return o 37 | }) 38 | 39 | c.SetDefault("info", map[string]interface{}{"a": "18", "name": "is name"}) 40 | c.SetDefault("info2", Demo{Name: "main2", App: "test2"}) 41 | c.SetDefault("infos", []Demo{{Name: "mains", App: "sss", Info: Info{Age: 18, Name: "is name"}}}) 42 | c.SetDefault("zls", "main") 43 | c.SetDefault("app", "test") 44 | tt.NoError(c.Read(), true) 45 | 46 | tt.Equal("dev", c.Get("zls").String()) 47 | tt.Equal("test", c.Get("app").String()) 48 | 49 | t.Log(c.GetAll()) 50 | 51 | var d Demo 52 | tt.NoError(c.Unmarshal(&d)) 53 | tt.Equal(c.Get("zls").String(), d.Name) 54 | tt.Equal(c.Get("app").String(), string(d.App)) 55 | 56 | var a appString 57 | tt.NoError(c.UnmarshalKey("app", &a)) 58 | tt.Equal(c.Get("app").String(), string(a)) 59 | 60 | var i *Info 61 | tt.NoError(c.UnmarshalKey("info", &i)) 62 | tt.Equal(c.Get("info.a").Int(), i.Age) 63 | tt.Equal(c.Get("info").Get("name").String(), i.Name) 64 | 65 | tt.Equal("test2", c.Get("info2").Get("app").String()) 66 | tt.Equal("18", c.Get("infos").Slice().Index(0).Get("Info").Get("a").String()) 67 | } 68 | 69 | func TestEnv(t *testing.T) { 70 | tt := zlsgo.NewTest(t) 71 | 72 | _ = os.Setenv("Z_ZLSGO", "YES") 73 | 74 | c := conf.New("env", func(o conf.Options) conf.Options { 75 | o.AutomaticEnv = true 76 | o.AutoCreate = true 77 | o.EnvPrefix = "Z" 78 | return o 79 | }) 80 | 81 | defer zfile.Remove(c.Path()) 82 | 83 | c.SetDefault("ZLSGO", "123") 84 | c.SetDefault("ZLS", "sohaha") 85 | 86 | tt.NoError(c.Read()) 87 | 88 | tt.Equal(os.Getenv("Z_ZLSGO"), c.Get("ZLSGO").String()) 89 | tt.EqualTrue(c.Get("ZLSGO").String() != "123") 90 | 91 | tt.Equal("sohaha", c.Get("zls").String()) 92 | tt.Equal("sohaha", c.Get("ZLS").String()) 93 | 94 | // defer os.Remove("env.toml") 95 | 96 | tt.Log(c.GetAll()) 97 | } 98 | 99 | func TestDef(t *testing.T) { 100 | tt := zlsgo.NewTest(t) 101 | 102 | c := conf.New("def", func(o conf.Options) conf.Options { 103 | o.AutoCreate = true 104 | return o 105 | }) 106 | defer os.Remove(c.Path()) 107 | 108 | c.SetDefault("def", 1) 109 | c.Set("project.name", "DemoApp") 110 | c.Set("arr", []struct{ Name string }{{"1"}, {"2"}, {"go"}}) 111 | c.Set("arr", []struct{ Name string }{{"1"}, {"2"}, {"go"}}) 112 | t.Log(c.Path()) 113 | c.Read() 114 | t.Log(c.GetAll()) 115 | 116 | c2 := conf.New("def.toml") 117 | c2.Read() 118 | t.Log(c2.GetAll()) 119 | 120 | tt.Equal(c.Get("project.name").String(), c2.Get("project.name").String()) 121 | tt.Equal(c.Get("def").Int(), c2.Get("def").Int()) 122 | 123 | tt.NoError(c.Write()) 124 | tt.Equal(c.Path(), c2.Path()) 125 | } 126 | 127 | func TestFileName(t *testing.T) { 128 | tt := zlsgo.NewTest(t) 129 | 130 | c := conf.New("zls", func(o conf.Options) conf.Options { 131 | o.AutoCreate = true 132 | o.FileName = "tmp/data/zls" 133 | return o 134 | }) 135 | 136 | c.SetDefault("test", true) 137 | defer zfile.Rmdir("tmp/") 138 | tt.NoError(c.Read()) 139 | } 140 | 141 | func TestConfigChange(t *testing.T) { 142 | tt := zlsgo.NewTest(t) 143 | path := "change.toml" 144 | zfile.WriteFile(path, []byte(` 145 | [info] 146 | name = 'DemoApp' 147 | `)) 148 | defer zfile.Remove(path) 149 | 150 | c := conf.New("change") 151 | 152 | c.ConfigChange(func(e fsnotify.Event) { 153 | t.Log(e) 154 | }) 155 | c.Read() 156 | 157 | tt.Equal("DemoApp", c.GetAll().Get("info.name").String()) 158 | zfile.WriteFile(path, []byte(` 159 | [info] 160 | name = 'NewApp' 161 | key = 'test' 162 | `)) 163 | 164 | time.Sleep(time.Millisecond * 500) 165 | tt.Equal("NewApp", c.GetAll().Get("info.name").String()) 166 | 167 | c.Set("info.name", "NewApp2") 168 | 169 | tt.Equal("NewApp2", c.GetAll().Get("info.name").String()) 170 | } 171 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/zlsgo/conf 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/fsnotify/fsnotify v1.9.0 7 | github.com/sohaha/zlsgo v1.7.18 8 | github.com/spf13/viper v1.18.2-0.20240325123913-8b5a9ae6203d 9 | ) 10 | 11 | require ( 12 | github.com/hashicorp/hcl v1.0.0 // indirect 13 | github.com/magiconair/properties v1.8.7 // indirect 14 | github.com/mitchellh/mapstructure v1.5.0 // indirect 15 | github.com/pelletier/go-toml/v2 v2.1.1 // indirect 16 | github.com/sagikazarmark/locafero v0.4.0 // indirect 17 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 18 | github.com/sourcegraph/conc v0.3.0 // indirect 19 | github.com/spf13/afero v1.11.0 // indirect 20 | github.com/spf13/cast v1.6.0 // indirect 21 | github.com/spf13/pflag v1.0.5 // indirect 22 | github.com/subosito/gotenv v1.6.0 // indirect 23 | go.uber.org/atomic v1.9.0 // indirect 24 | go.uber.org/multierr v1.9.0 // indirect 25 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 26 | golang.org/x/sys v0.18.0 // indirect 27 | golang.org/x/text v0.14.0 // indirect 28 | gopkg.in/ini.v1 v1.67.0 // indirect 29 | gopkg.in/yaml.v3 v3.0.1 // indirect 30 | ) 31 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 4 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 5 | github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= 6 | github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= 7 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 8 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 9 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 10 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 11 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 12 | github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= 13 | github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= 14 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 15 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 16 | github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= 17 | github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= 18 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 19 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 20 | github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= 21 | github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= 22 | github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= 23 | github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= 24 | github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= 25 | github.com/sohaha/zlsgo v1.7.18 h1:ajue06xEGeX8FKxCAYqvGS58uPYThGVkYRWhNqLb9t0= 26 | github.com/sohaha/zlsgo v1.7.18/go.mod h1:7LViqB5ll09RnlU5V5AW0oBnqFg260/q+B/SGDNNdmQ= 27 | github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 28 | github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 29 | github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= 30 | github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= 31 | github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= 32 | github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 33 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 34 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 35 | github.com/spf13/viper v1.18.2-0.20240325123913-8b5a9ae6203d h1:iL1NKZnt5Nt0hP8d7MuXRGS8Z6G3/DYuUvQNfoMERtE= 36 | github.com/spf13/viper v1.18.2-0.20240325123913-8b5a9ae6203d/go.mod h1:Di7GbQTOUNRxOxNH6qJ252mcCN2M6gJhGrfARoumrYo= 37 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 38 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 39 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 40 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 41 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 42 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 43 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 44 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 45 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 46 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 47 | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= 48 | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 49 | go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= 50 | go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= 51 | golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= 52 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= 53 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= 54 | golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= 55 | golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= 56 | golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 57 | golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 58 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 59 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 60 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= 61 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 62 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 63 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 64 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 65 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 66 | -------------------------------------------------------------------------------- /options.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | type Options struct { 4 | FileName string 5 | AutomaticEnv bool 6 | EnvPrefix string 7 | AutoCreate bool 8 | PrimaryAliss string 9 | } 10 | --------------------------------------------------------------------------------