config

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 0 Imported by: 0

README

config

Go Reference Go Report Card License

config provides strict, crash-safe configuration file I/O for Go projects.

It does not implement parsers or codecs. Instead, it defines a small, consistent set of rules for loading and saving configuration files using existing format libraries.

Install

go get github.com/BinGo-Lab-Team/config

Packages

config/
├── jsonio/   # JSON configuration I/O
├── tomlio/   # TOML configuration I/O (strict, unknown keys rejected)
├── yamlio/   # YAML configuration I/O
├── xmlio/    # XML configuration I/O

Each package is format-specific and self-contained.

API

All *io packages expose the same minimal API:

func Load[T any](path string, cfg *T) error
func Save[T any](path string, cfg T) error
Load
  • Loads configuration from a file path
  • Decodes exactly one document
  • Returns errors on:
    • file not found
    • syntax errors
    • format-specific violations
Save
  • Writes configuration atomically:
    • temporary file
    • fsync
    • atomic rename
  • Never leaves a partially written file
  • Does not synchronize concurrent writes

Usage

TOML
package main

import (
	"log"
	"errors"
	
	"github.com/BinGo-Lab-Team/config/tomlio"
)

type Config struct {
    Name string `toml:"name"`
    Port int    `toml:"port"`
}

func main() {
	var cfg Config
	if err := tomlio.Load("config.toml", &cfg); err != nil {
		if errors.Is(err, tomlio.ErrUnknownKeys) {
			// handle unknown keys
		}
		log.Fatal(err)
	}

	cfg.Port = 8081
	_ = tomlio.Save("config.toml", cfg)
}

Notes

  • File-level APIs only (no io.Reader / io.Writer wrappers)
  • No schema, defaults, or hot-reload logic
  • Intended for application configuration, not generic serialization

License

This project released under MIT License

Documentation

Overview

Package config provides strict, crash-safe configuration file I/O.

This package does not implement parsers or codecs. Instead, it defines a consistent, file-level contract for loading and saving configuration files using established format libraries.

Subpackages under config/*io provide format-specific implementations (JSON, TOML, YAML, XML), all exposing the same minimal API:

Load[T any](path string, cfg *T) error
Save[T any](path string, cfg T) error

Design principles:

  • Configuration files are treated as critical inputs. Errors must be explicit and observable.
  • Writes are crash-safe and never leave partially written files.
  • Behavior is format-explicit; no automatic format detection is performed.
  • The API operates at the file level; io.Reader/io.Writer are intentionally not abstracted.

This package is intended for application configuration, not for general-purpose data serialization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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