owenlilly / godotenv

Reading .env file and enviroment variables in golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

godotenv

Reading .env file in golang

Download

  $ go get github.com/pleycpl/godotenv    # First download repo in go directory

Usage

Example Env file (.env)
Key=Value
Mongo=20830
Token=asd123asdasd234
Usage in code
  package main
  
  import (
    "fmt"
    "github.com/pleycpl/godotenv"
  )
  
  func main() {
    env := godotenv.Godotenv(".env")        // You should write your .env file's path.
    fmt.Println(env)                        // env variable is map.
    fmt.Println(env["Key"])
    fmt.Println(env["Mongo"])
    fmt.Println(env["Token"])
  }

About

Reading .env file and enviroment variables in golang

License:GNU General Public License v3.0


Languages

Language:Go 100.0%