Kasper Juul Hermansen 1191a6d559
All checks were successful
continuous-integration/drone/tag Build is passing
chore(release): v0.0.1 (#1)
chore(release): 0.0.1

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/yourconfig/pulls/1
2025-07-21 21:13:49 +02:00
2025-07-21 17:09:45 +02:00
2025-07-21 17:09:45 +02:00
2025-07-21 21:13:49 +02:00
2025-07-21 16:35:38 +02:00
2025-07-21 16:35:38 +02:00
2025-07-21 17:04:53 +02:00
2025-07-21 16:35:38 +02:00
2025-07-21 16:35:38 +02:00
2025-07-21 16:47:10 +02:00

yourconfig

A dead-simple Go library for loading config structs from environment variables — with optional tagging and required enforcement.

📦 Install

go get github.com/kjuulh/yourconfig

🧪 Basic Usage

package main

import (
	"fmt"
	"github.com/kjuulh/yourconfig"
)

type Config struct {
	// Uses SNAKE_CASE: SOME_ITEM
	SomeItem string `conf:"required:true"`

	// Custom name
	OtherItem string `conf:"MY_ITEM"`

	// Loads YET_ANOTHER optionally from env
	YetAnother string `conf:""`

	// ignored field
	Ignored string
}

func main() {
	cfg := yourconfig.MustLoad[Config]()
	fmt.Println(cfg.SomeItem, cfg.OtherItem, cfg.YetAnother)
}

🏷️ Tag Syntax

You configure fields using the conf struct tag:

  • Custom env name: First item (e.g. conf:"MY_ENV")
  • Options: key:value or flags (e.g. required:true, or just required)

Examples:

// infers env var SOME_ITEM
SomeItem string `conf:""`

// uses DIFFERENT_NAME
SomeItem string `conf:"DIFFERENT_NAME"`

// requires the env var to be present
SomeItem string `conf:"required"`

// equivalent to above
SomeItem string `conf:"required:true"`

// combine name and required
SomeItem string `conf:"DIFFERENT_NAME,required"`

// combine name and required (option)
SomeItem string `conf:"DIFFERENT_NAME,required:true"`

Required Fields

If a field is marked required and the environment variable is not set, loading will return an error. Use MustLoad[T]() to panic on error, or Load[T]() (T, error) to handle it gracefully.

Private (unexported) fields are ignored unless tagged — in which case they produce a not settable error, avoid setting conf on private items.

License

MIT

Contributing

go test ./...

Release

Releases are handled through cuddle-please a pr based release tool, simply merge the pr and a release will be cut

Description
No description provided
Readme 74 KiB
v0.0.3 Latest
2025-07-23 11:15:16 +02:00
Languages
Go 100%