{"repo":"subosito/gotenv","free":true,"listed":false,"github":"https://github.com/subosito/gotenv","clone":"git clone https://github.com/subosito/gotenv.git","description":"Load environment variables from `.env` or `io.Reader` in Go.","language":"Go","stars":310,"topics":["environment-variables","golang","golang-library"],"license":"MIT","category":"dev-tools","readme_excerpt":"gotenv Load environment variables from .env or io.Reader in Go. Usage Put the gotenv package on your import statement: To modify your app environment variables, gotenv expose 2 main functions: - gotenv.Load - gotenv.Apply By default, gotenv.Load will look for a file called .env in the current working directory. Behind the scene, it will then load .env file and export the valid variables to the environment variables. Make sure you call the method as soon as possible to ensure it loads all variables, say, put it on init() function. Once loaded you can use os.Getenv() to get the value of the variable. Let's say you have .env file: Here's the example of your app: You can also load other than .env file if you wish. Just supply filenames when calling Load() . It will load them in order and the first value set for a variable will win.: While gotenv.Load loads entries from .env file, gotenv.Apply allows you to use any io.Reader : Both gotenv.Load and gotenv.Apply DO NOT overrides existing environment variables. If you want to override existing ones, you can see section below. Environment Overrides Besides above functions, gotenv also provides another functions that overrides existing: - gotenv.OverLoad - gotenv.OverApply Here's the example of this overrides behavior: Throw a Panic Both gotenv.Load and gotenv.OverLoad returns an error on something wrong occurred, like your env file is not exist, and so on. To make it easier to use, gotenv also provides gotenv.Must helper, to let it pa","default_branch":null,"files":null,"tree":[],"storefront":"/r/subosito","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/subosito/gotenv/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}