cleanenv icon indicating copy to clipboard operation
cleanenv copied to clipboard

bug: Cleanenv ignore environment variable when using pointer

Open afifurrohman-id opened this issue 6 months ago • 0 comments

Reproduceable steps:

  • config.yaml

foo: hello
  • main.go
package main

import (
	"fmt"

	"github.com/ilyakaznacheev/cleanenv"
)

type (
	Config struct {
		Foo *string `env-required:"true" yaml:"foo" env:"FOO"`
	}

)

func main() {
	cfg := new(Config)
	_ = cleanenv.ReadConfig("config.yaml", cfg)
	cleanenv.ReadEnv(cfg)

	fmt.Println(*cfg.Foo)
}
export FOO=bar

it will print "hello" instead of bar

is this limitation of reflection??

afifurrohman-id avatar Aug 20 '24 09:08 afifurrohman-id