Documentation
¶
Overview ¶
Package dotenv provides a `.env` provider.
Index ¶
Examples ¶
Constants ¶
View Source
const Name = "env"
Name of the provider.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New sets up a new DotEnv provider.
Example ¶
ExampleNew creates a new dotenv instance and loads the .env file.
package main import ( "context" "fmt" "log" "os" "github.com/thalesfsp/configurer/dotenv" "github.com/thalesfsp/configurer/util" ) func main() { // Instantiate the provider of choice, in this case dotenv. de, err := dotenv.New(false, false, "testing.env") if err != nil { log.Fatalln(err) } // Load will export to the environment all the variables. if _, err := de.Load(context.Background()); err != nil { log.Fatalln(err) } // We can check it here. fmt.Println(os.Getenv("TEST_KEY")) // Additionally, we can use the config into a struct. type Config struct { TestKey string `env:"TEST_KEY" json:"testKey"` } // ExportToStruct can be called from the provider... var c1 Config if err := de.ExportToStruct(&c1); err != nil { log.Fatalln(err) } // or from the `util` package. var c2 Config if err := util.Dump(&c2); err != nil { log.Fatalln(err) } // We can check it here. fmt.Println(c1.TestKey) fmt.Println(c2.TestKey) }
Output: TEST_VALUE TEST_VALUE TEST_VALUE
Types ¶
type DotEnv ¶
type DotEnv struct { *provider.Provider `json:"-" validate:"required"` // FilePaths is the list of file paths to load. FilePaths []string `json:"filePaths" validate:"required,gte=1"` }
DotEnv provider definition.
Click to show internal directories.
Click to hide internal directories.