kayac / go-config Goto Github PK
View Code? Open in Web Editor NEWConfiguration file loader for Go
License: MIT License
Configuration file loader for Go
License: MIT License
https://github.com/Masterminds/sprig
自分はライブラリ利用しかしないのでどっちでも良いのですが、のっぴきならない理由で環境ごとにリストの数が異なるようなケースのときFOO=hoge,fuga,foo
みたいな環境設定にして下記のようなことをしたいというケースが合ったのですが、Funcs
の存在間がだいぶ薄いので入れちゃっても良いのでは?と思いました。
items: {{ range splitList "," (env "FOO") }}
- {{ . }}
{{ end }}
Masterminds/sprig入れるとなんでも出来る過ぎる...という説もありますが
参考: 自分で入れる場合
import (
"github.com/Masterminds/sprig/v3"
"github.com/kayac/go-config"
)
var conf = MyConfig{}
func Load() {
config.Funcs(sprig.HermeticTxtFuncMap())
paths = strings.Split(os.Getenv("CONFIG_PATH"), ",")
if err := config.LoadWithEnv(&conf, paths...); err != nil {
}
}
Dependabot couldn't find a go.mod for this project.
Dependabot requires a go.mod to evaluate your project's current Go dependencies. It had expected to find one at the path: /tfstate/go.mod
.
If this isn't a Go project, or if it is a library, you may wish to disable updates for it from within Dependabot.
空の値で定義される環境変数 FOO を x{{ env "FOO" "DEFAULT" }}x
で展開した場合、xx
とは出力されず、FOO が未定義の場合と同様に xDEFAULTx
となるようです。
env
による環境変数の取得には os.Getenv が使用されており、
Line 184 in cec4875
空の値で定義される場合と未定義の場合とで区別なく扱われるためだと認識していますが、 こちらは go-config の意図通りの挙動でしょうか。
以下再現コードになります。
https://play.golang.org/p/XUjO2XkD8pS
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.