Update .env files in Go with code.
formicidate is a small tool for Go application. You can update the value of environment variables in a .env file with code. This can be handy in situations that you want to update the values programmatically like in unit tests.
go get github.com/papasavva/formicidae
Add your application configuration to your .env file of your project:
S3_BUCKET=myBucket
SECRET_KEY=mySecretKeyGoesHere
Then in your app you can do something like:
package main
import (
"github.com/papasavva/formicidae"
)
func main() {
updatedContent, err := formicidae.UpdateVariable(".env", "SECRET_KEY", "myNewSecretKey")
...
}
- If you wish to update multiple variables, you can call the function multiple times.
- The function will return the content of the whole file.
Contributions are welcomed.
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Added some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
The code is licensed under the permissive MIT licence. Read this for a summary.