Conversation
|
I put a lot of thought into API surface area and strive for a minimal API surface. What is the use case here? If you don't want to read anything from a package main
import (
"fmt"
"strings"
"github.com/DeanPDX/dotconfig"
)
func main() {
type AppConfig struct {
SomeValue string `env:"SOME_VALUE" default:"Hello from dotconfig!"`
}
// Don't use a .env file but use dotconfig to unmarshal our environment
// variables into a struct
config, err := dotconfig.FromReader[AppConfig](strings.NewReader(""))
if err != nil {
fmt.Printf("Didn't expect error. Got %v.", err)
}
fmt.Println("App config loaded.")
fmt.Println(config)
} |
|
My usecase is - i want to read env vars from OS and optionally from .env (if exists). I already loading it using other lib, and want to just marshall into config struct as you suggested. I think this way of using it |
|
Alright - that makes sense and I'll think about implementation/docs/naming on this more. |
This function is useful in combination with other config and env loading libs. I can copy it in my code with license, but i think it would be better if you export this function too.