gowizzard / updenv

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

License:MIT License


Languages

Language:Go 95.0%Language:Makefile 5.0%