Skip to content

Commit

Permalink
fix: readme fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 24, 2020
1 parent f3934f1 commit 9f41e9d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"fmt"
"time"

// if using go modules
"github.com/caarlos0/env/v6"
// if using go modules
"github.com/caarlos0/env/v6"

// if using dep/others
"github.com/caarlos0/env"
// if using dep/others
"github.com/caarlos0/env"
)

type config struct {
Expand Down Expand Up @@ -135,22 +135,25 @@ type config struct {
## From file

The `env` tag option `file` (e.g., `env:"tagKey,file"`) can be added
to in order to indicate that the value of the variable shall be loaded from a file. The path of that file is given
to in order to indicate that the value of the variable shall be loaded from a file. The path of that file is given
by the environment variable associated with it
Example below

```go
package main

import (
"fmt"
"time"
"github.com/caarlos0/env"
"fmt"
"time"
"github.com/caarlos0/env"
)

type config struct {
Secret string `env:"SECRET,file"`
Password string `env:"PASSWORD,file" envDefault:"/tmp/password"`
Certificate string `env:"CERTIFICATE,file" envDefault:"${CERTIFICATE_FILE}" envExpand:"true"`
Secret string `env:"SECRET,file"`
Password string `env:"PASSWORD,file" envDefault:"/tmp/password"`
Certificate string `env:"CERTIFICATE,file" envDefault:"${CERTIFICATE_FILE}" envExpand:"true"`
}

func main() {
cfg := config{}
if err := env.Parse(&cfg); err != nil {
Expand All @@ -165,10 +168,10 @@ func main() {
$ echo qwerty > /tmp/secret
$ echo dvorak > /tmp/password
$ echo coleman > /tmp/certificate

$ SECRET=/tmp/secret \
CERTIFICATE_FILE=/tmp/certificate \
go run main.go
CERTIFICATE_FILE=/tmp/certificate \
go run main.go
{Secret:qwerty Password:dvorak Certificate:coleman}
```

Expand Down

0 comments on commit 9f41e9d

Please sign in to comment.