1. Create .env-File
  2. Init .env-File with: godotenv.Load() → otherwise the env-vars will not be found

.go-File

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

func main() {
	port, err := getEnv("PORT")
	if err != nil {
		fmt.Println("[GET-ENV]: Get Port was failed \\t\\t -> \\t" + err.Error())
	}
	_ = port
}

func getEnv(key string) (string, error) {
	env, err := os.LookupEnv(key) // GetEnv() does not work
	if !err || env == "" {
		fmt.Println("Env: " + env)
		return env, errors.New("getenv: environment variable empty")
	}
	return env, nil
}

func init() {
	log.Println("[INIT MAIN]: Status -> Main-init is loaded")
	godotenv.Load()
}

.env-File

PORT="8080"
DOCFILENAME="./doc.md"