Skip to content

Commit a79fa1e

Browse files
authored
Merge pull request #41 from alexquick/document-write-dotenv
Document Marshal, Unmarshal, and Write
2 parents 144189c + e6264cf commit a79fa1e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ reader := getRemoteFile()
103103
myEnv, err := godotenv.Parse(reader)
104104
```
105105

106+
... or from a `string` if you so desire
107+
108+
```go
109+
content := getRemoteFileContent()
110+
myEnv, err := godotenv.Unmarshal(content)
111+
```
112+
106113
### Command Mode
107114

108115
Assuming you've installed the command as above and you've got `$GOPATH/bin` in your `$PATH`
@@ -113,6 +120,22 @@ godotenv -f /some/path/to/.env some_command with some args
113120

114121
If you don't specify `-f` it will fall back on the default of loading `.env` in `PWD`
115122

123+
### Writing Env Files
124+
125+
Godotenv can also write a map representing the environment to a correctly-formatted and escaped file
126+
127+
```go
128+
env, err := godotenv.Unmarshal("KEY=value")
129+
err := godotenv.Write(env, "./.env")
130+
```
131+
132+
... or to a string
133+
134+
```go
135+
env, err := godotenv.Unmarshal("KEY=value")
136+
content, err := godotenv.Marshal(env)
137+
```
138+
116139
## Contributing
117140

118141
Contributions are most welcome! The parser itself is pretty stupidly naive and I wouldn't be surprised if it breaks with edge cases.

0 commit comments

Comments
 (0)