Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
/ updenv Public archive

A little go module to update values in .env files.

License

Notifications You must be signed in to change notification settings

gowizzard/updenv

Repository files navigation

updenv

GitHub go.mod Go version of a Go module Go CodeQL CompVer Go Report Card Go Reference GitHub issues GitHub forks GitHub stars GitHub license

With this small library it should be possible to update environment variables in a dot env file. With this library it is not possible to read out the variables, because there are already very good other libraries for this.

Install

go get github.com/gowizzard/updenv

How to use?

Here is an example of how to update a dot env file. Of course, only variables that exactly match the key can be updated. New variables cannot be added.

If you prefer not to use quotes for your variables, then you can set this in the config struct by setting the quotes value to false, or omitting it directly.

c := updenv.Config{
	Path:   filepath.Join("path", "to", "your", "file", ".env"),
	Quotes: true,
}

err := c.Read()
if err != nil {
	log.Fatal(err)
}

c.Updates = make(map[string]string)
c.Updates["EXAMPLE"] = "true"
err = c.Update()
if err != nil {
	log.Fatal(err)
}

Special thanks

Thanks to JetBrains for supporting me with this and other open source projects.