项目作者: kjj6198

项目描述 :
simple util to inject variable into env variable
高级语言: Go
项目地址: git://github.com/kjj6198/configo.git
创建时间: 2018-08-19T03:34:33Z
项目社区:https://github.com/kjj6198/configo

开源协议:

下载


Config

A very simple util to inject variable into env variable, convenient when developing in local environment. You can define variable in yml file, it’ll inject it into env variable.

warning: still in development, use it carefully

Getting Started

  1. func main() {
  2. ok := config.Load("./config/env.yml") // your config file path, return true if successfully load file, return false if can not find file.
  3. if os.Getenv("ENV") == "development" {
  4. fmt.Println("my debug info, don't show it in production.")
  5. }
  6. // or use config.Get
  7. if val, ok := config.Get("ENV"); !ok {
  8. fmt.Println("ENV doesn't exist in")
  9. }
  10. // or use config.MustGet
  11. // panics if can not find env
  12. if val := config.MustGet("ENV") {
  13. }
  14. }

API

config.Load(filename string) (ok bool)

Load a file and inject it into env, only .yml format is supported

TODO: error handling if wrong format

config.Get(key string) (val string, exist bool)

Get global env from os

config.MustGet(key string) (val string)

Get global env from os, panics if env doesn’t exist.

TODO

  • bettor error handling

License

MIT