Skip to content

Commit

Permalink
Merge pull request #54 from ilyakaznacheev/godoc
Browse files Browse the repository at this point in the history
Better package documentation
  • Loading branch information
ilyakaznacheev committed Aug 14, 2020
2 parents 4eefa52 + abedd66 commit 79220a7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
14 changes: 0 additions & 14 deletions cleanenv.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/*
Package cleanenv gives you a single tool to read application configuration from several sources.
You can just prepare config structure and fill it from the config file and environment variables.
type Config struct {
Port string `yaml:"port" env:"PORT" env-default:"8080"`
Host string `yaml:"host" env:"HOST" env-default:"localhost"`
}
var cfg Config
ReadConfig("config.yml", &cfg)
*/
package cleanenv

import (
Expand Down
63 changes: 63 additions & 0 deletions docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Package cleanenv gives you a single tool to read application configuration from several sources with ease.
Features
- read from several file formats (YAML, JSON, TOML, ENV, EDN) and parse into the internal structure;
- read environment variables into the internal structure;
- output environment variable list with descriptions into help output;
- custom variable readers (e.g. if you want to read from remote config server, etc).
Usage
You can just prepare the config structure and fill it from the config file and environment variables.
type Config struct {
Port string `yaml:"port" env:"PORT" env-default:"8080"`
Host string `yaml:"host" env:"HOST" env-default:"localhost"`
}
var cfg Config
ReadConfig("config.yml", &cfg)
Help output
You can list all of your environment variables by means of help output:
type ConfigServer struct {
Port string `env:"PORT" env-description:"server port"`
Host string `env:"HOST" env-description:"server host"`
}
var cfg ConfigRemote
help, err := cleanenv.GetDescription(&cfg, nil)
if err != nil {
...
}
// setup help output
f := flag.NewFlagSet("Example app", 1)
fu := f.Usage
f.Usage = func() {
fu()
envHelp, _ := cleanenv.GetDescription(&cfg, nil)
fmt.Fprintln(f.Output())
fmt.Fprintln(f.Output(), envHelp)
}
f.Parse(os.Args[1:])
Then run go run main.go -h and the output will include:
Environment variables:
PORT server port
HOST server host
For more detailed information check examples and example tests.
*/
package cleanenv

0 comments on commit 79220a7

Please sign in to comment.