Skip to content

Commit f92811e

Browse files
committed
Updated documentation
1 parent 529f1dd commit f92811e

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

.godocdown.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105
var a, b config
106106

107107
// Update the environment.
108-
if err := env.Update("./cmd/.env"); err != nil {
108+
if err := env.Update(".env"); err != nil {
109109
log.Fatal(err)
110110
}
111111

@@ -194,7 +194,7 @@ func main() {
194194
// Note: We use the Load (but not Update) method for as not to overwrite
195195
// the data in the environment because on the production server this
196196
// data can be set forcibly.
197-
env.Load("./cmd/.env")
197+
env.Load(".env")
198198
env.Unmarshal("", &config)
199199

200200
// Make routing.

README.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func main() {
106106
var a, b config
107107

108108
// Update the environment.
109-
if err := env.Update("./cmd/.env"); err != nil {
109+
if err := env.Update(".env"); err != nil {
110110
log.Fatal(err)
111111
}
112112

@@ -195,7 +195,7 @@ func main() {
195195
// Note: We use the Load (but not Update) method for as not to overwrite
196196
// the data in the environment because on the production server this
197197
// data can be set forcibly.
198-
env.Load("./cmd/.env")
198+
env.Load(".env")
199199
env.Unmarshal("", &config)
200200

201201
// Make routing.
@@ -472,6 +472,39 @@ marshaling.
472472
// Port: 80
473473
// AllowedHosts: 192.168.0.1
474474

475+
#### func Save
476+
477+
func Save(filename, prefix string, obj interface{}) error
478+
479+
Save saves the object to a file without changing the environment.
480+
481+
482+
Example
483+
484+
There is some configuration structure:
485+
486+
// Config it's struct of the server configuration.
487+
type Config struct {
488+
Host string `env:"HOST"`
489+
Port int `env:"PORT"`
490+
AllowedHosts []string `env:"ALLOWED_HOSTS" sep:":"` // parse by `:`.
491+
}
492+
493+
...
494+
495+
var config = Config{
496+
Host: "localhost",
497+
Port: 8080,
498+
AllowedHosts: []string{"localhost", "127.0.0.1"},
499+
}
500+
env.Save("/tmp/.env", "", config)
501+
502+
The result in the file /tmp/.env
503+
504+
HOST=localhost
505+
PORT=8080
506+
ALLOWED_HOSTS=localhost:127.0.0.1
507+
475508
#### func Set
476509

477510
func Set(key, value string) error

0 commit comments

Comments
 (0)