Skip to content

Conversation

@DanInSpace104
Copy link

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.

@DeanPDX
Copy link
Owner

DeanPDX commented Dec 10, 2025

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 .env file but still want to leverage this package strictly as a struct unmarshaller, you can just pass an empty string to FromReader:

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)
}

@DanInSpace104
Copy link
Author

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 dotconfig.FromReader[AppConfig](strings.NewReader("")) is very unintuitive and requires knowing implementation details to use it. The main "selling" feature of your package, in my opinion, is marhsalling into config, not loading files, which other libs already do.

@DeanPDX
Copy link
Owner

DeanPDX commented Dec 23, 2025

Alright - that makes sense and I'll think about implementation/docs/naming on this more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants