Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not load .env file content #1

Open
anerg2046 opened this issue Sep 14, 2023 · 2 comments
Open

Can not load .env file content #1

anerg2046 opened this issue Sep 14, 2023 · 2 comments

Comments

@anerg2046
Copy link

anerg2046 commented Sep 14, 2023

package main

import (
	_ "github.com/sakirsensoy/genv/dotenv/autoload"

	"fmt"
	"os"
	"test-genv/config"
)

func main() {
	val, ok := os.LookupEnv("APP_HOST")
	fmt.Println(ok)  // output: true
	fmt.Println(val) // output: localhost

	fmt.Println(config.App.Host)  // output: ""
	fmt.Println(config.App.Port)  // output: 8080
	fmt.Println(config.App.Debug) // output: false
}

golang ver: 1.21.1

@anerg2046
Copy link
Author

@anerg2046
Copy link
Author

The current solution is to add an init.go file in the config package

package config

import "fmt"

func init() {
	fmt.Println("load env")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant