Skip to content

Not reading my .env file #181

@tausyy

Description

@tausyy

I have my .env file with 2 properties

BOT_TOKEN=rightHereIsWhereMyTokenIs
TEST=1234

when I go run main.go with this code this is my output

env: environment variable "BOT_TOKEN" should not be empty
{BotToken: Test:0}

What am I doing wrong?

package main

import (
	"fmt"

	"github.com/caarlos0/env/v6"
)

type config struct {
	BotToken string `env:"BOT_TOKEN,notEmpty"`
	Test     int32  `env:"TEST"`
}

func main() {
	cfg := config{}
	if err := env.Parse(&cfg); err != nil {
		fmt.Printf("%+v\n", err)
	}

	fmt.Printf("%+v\n", cfg)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions