gomfig

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 4 Imported by: 0

README

gomfig Version

Current stable: v0.2.2 (JSON, YAML, TOML)

Light-weight, extensible Go library to load and merge configuration from multiple sources.

gomfig is released under semantic versioning. Version v0.2.2 supports JSON, YAML, and TOML configuration files. Upcoming minor versions will introduce ENV and remote back-ends. Upcoming branches will add YAML, TOML, ENV, and remote back-ends (Consul, etcd, …).

Features (current branch)

  • Decode JSON, YAML, and TOML files/streams into arbitrary Go structs or maps.
  • Strict mode for all loaders: unknown fields are rejected early.
  • Minimal API:
// root package convenience helpers
type JSONLoader = gomfig.JSONLoader

var cfg struct {
    DB struct {
        Host string `json:"host"`
        Port int    `json:"port"`
    } `json:"db"`
}

if err := gomfig.LoadJSONFile("config.json", &cfg); err != nil {
    log.Fatalf("load config: %v", err)
}

Installation

go get github.com/octahori/gomfig@v0.2.2

Roadmap

Stage Description
✓ JSON Basic loader implementation + unit tests
✓ YAML YAML loader (yamlcfg, strict mode)
✓ TOML TOML loader (tomlcfg)
☐ ENV Map environment variables into struct with tags
☐ Remote Consul / etcd loaders

Contributing

  1. Fork and create a feature branch.
  2. Ensure go test ./... and go vet ./... pass.
  3. Open a pull request.

Licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadJSON

func LoadJSON(r io.Reader, out interface{}) error

LoadJSON calls jsoncfg.Load.

func LoadJSONFile

func LoadJSONFile(path string, out interface{}) error

LoadJSONFile calls jsoncfg.LoadFile.

func LoadTOML added in v0.2.0

func LoadTOML(r io.Reader, out interface{}) error

func LoadTOMLFile added in v0.2.0

func LoadTOMLFile(path string, out interface{}) error

func LoadYAML

func LoadYAML(r io.Reader, out interface{}) error

LoadYAML decodes YAML read from r into out.

func LoadYAMLFile

func LoadYAMLFile(path string, out interface{}) error

LoadYAMLFile decodes YAML file into out.

func MustLoadJSONFile

func MustLoadJSONFile(path string, out interface{})

MustLoadJSONFile calls jsoncfg.MustLoadFile.

func MustLoadTOMLFile added in v0.2.0

func MustLoadTOMLFile(path string, out interface{})

func MustLoadYAMLFile

func MustLoadYAMLFile(path string, out interface{})

MustLoadYAMLFile is like LoadYAMLFile but panics on error.

Types

type JSONLoader

type JSONLoader = jsoncfg.Loader

JSONLoader is kept for backwards-compatibility. It aliases jsoncfg.Loader.

type Loader

type Loader interface {
	// Load decodes configuration data read from r into the value pointed to by
	// out.
	Load(r io.Reader, out interface{}) error

	// LoadFile opens the file located at path and delegates to Load.
	LoadFile(path string, out interface{}) error
}

Loader defines the common behaviour for all configuration loaders (JSON, YAML, TOML, ENV, etc.). Implementations should be stateless so that they are safe for concurrent use.

Callers typically use the convenience helpers in each format sub-package rather than interact with Loader directly.

type TOMLLoader added in v0.2.0

type TOMLLoader = tomlcfg.Loader

type YAMLLoader

type YAMLLoader = yamlcfg.Loader

YAMLLoader aliases yamlcfg.Loader for convenience.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL