0
1

More than 3 years have passed since last update.

godotenvを使って.envから環境変数を読み込む

Posted at

リポジトリ

envファイルを用意

AZURECLIENTID=f81b5350-09dc-480e-8c03-1xxxxxxxxxxxxxxxxx

package main

import (
    "fmt"
    "os"
    "github.com/joho/godotenv"
)

func main() {
    err := godotenv.Load(fmt.Sprintf("%s.env", os.Getenv("GO_ENV")))
    if err != nil {
    }

    ID := os.Getenv("AZURECLIENTID")
    fmt.Println(ID)
}

使い方

yuta:~/go-env $ go run main.go
f81b5350-09dc-480e-8c03-xxxxxxxxxxxxxxx
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1