Issue getting .env vars golang
xepobopa
HOBBYOP

8 months ago

All my code on GoLang works well, but i cannot get .env vars in code.
I do it like this

func GetDotenv(names ...string) ([]string, error) {
    if err := godotenv.Load(); err != nil {
        return []string{}, fmt.Errorf("error trying to get .env var: %w", err)
    }

    var vars []string
    for idx, name := range names {
        vars[idx] = os.Getenv(name)
    }

    return vars, nil
}

and i do not get anything. I also tried to specify .env path , but it also didnt work. But error error trying to get .env var: do not fire, it just return me empty list

Solved

0 Replies

xepobopa
HOBBYOP

8 months ago

37b514d7-42c5-4dd1-baf6-ff6cd324227b


mikexie360
PRO

8 months ago

I used a different go library

    endpointSecret := os.Getenv("STRIPE_WEBHOOK_SIGNING_SECRET") // Set this in .env
    event, err := webhook.ConstructEvent(body, sigHeader, endpointSecret)

xepobopa
HOBBYOP

8 months ago

Thank you, i will try it tomorrow


brody
EMPLOYEE

8 months ago

you dont need to use any libray, only os.Getenv


brody
EMPLOYEE

8 months ago

we do not inject variables as a .env file, they are injected directly into the environment


xepobopa
HOBBYOP

8 months ago

Ok, i understood, thank you a lot


brody
EMPLOYEE

8 months ago

!s


Status changed to Solved brody 8 months ago


Loading...