MCPcopy Create free account
hub / github.com/caarlos0/env / ExampleParse_fromFile

Function ExampleParse_fromFile

example_test.go:400–415  ·  view source on GitHub ↗

The `env` tag option `file` (e.g., `env:"tagKey,file"`) can be added in order to indicate that the value of the variable shall be loaded from a file. The path of that file is given by the environment variable associated with it.

()

Source from the content-addressed store, hash-verified

398// The path of that file is given by the environment variable associated with
399// it.
400func ExampleParse_fromFile() {
401 f, _ := os.CreateTemp("", "")
402 _, _ = f.WriteString("super secret")
403 _ = f.Close()
404
405 type Config struct {
406 Secret string `env:"SECRET,file"`
407 }
408 os.Setenv("SECRET", f.Name())
409 var cfg Config
410 if err := Parse(&cfg); err != nil {
411 fmt.Println(err)
412 }
413 fmt.Printf("%+v", cfg)
414 // Output: {Secret:super secret}
415}
416
417// TODO: envSeperator
418//

Callers

nothing calls this directly

Calls 1

ParseFunction · 0.85

Tested by

no test coverage detected