configbuilder

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 4 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

configbuilder — mustache-template config generator

import "github.com/downsized-devs/sdk-go/configbuilder"

Stability: Stable — see STABILITY.md

Renders mustache templates into runtime config files at startup. Useful when you want a single source-of-truth template that fans out into per-environment JSON/YAML files.

Features

  • BuildConfig(opts Options) — render and write
  • Mustache placeholders, optionally fed by viper or environment

Installation

go get github.com/downsized-devs/sdk-go/configbuilder

Quick Start

import "github.com/downsized-devs/sdk-go/configbuilder"

b := configbuilder.Init()
b.BuildConfig(configbuilder.Options{
    TemplatePath: "config/app.json.tmpl",
    OutputPath:   "config/app.json",
    Data:         map[string]any{ "env": "prod", "host": os.Getenv("APP_HOST") },
})

API Reference

Symbol Signature
Init func Init() Interface
Interface.BuildConfig (Options) error
Options.TemplatePath string — path to .tmpl file.
Options.OutputPath string — destination file.
Options.Data map[string]any — values for {{placeholders}}.

Examples

Generate per-environment config from CI
ENV=staging go run ./tools/build_config
b.BuildConfig(configbuilder.Options{
    TemplatePath: fmt.Sprintf("config/%s.json.tmpl", os.Getenv("ENV")),
    OutputPath:   "config/runtime.json",
    Data:         map[string]any{
        "redisAddr": os.Getenv("REDIS_ADDR"),
        "dbDSN":     os.Getenv("DB_DSN"),
    },
})

Error Handling

BuildConfig returns errors from missing templates and write failures. Surface them at process startup — failing to build config should be fatal.

Dependencies

  • Internal: files
  • External: github.com/cbroglie/mustache, github.com/spf13/viper

Testing

go test ./configbuilder/...

Two test files (unit + integration).

Contributing

See CONTRIBUTING.md.

  • configreader — the read side: parses the file configbuilder produces.
  • files — used internally for path checks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	BuildConfig()
}

func Init

func Init(opt Options) Interface

type Options

type Options struct {
	Namespace              string
	Env                    string
	Key                    string
	Secret                 string
	Region                 string
	TemplateFile           string
	ConfigFile             string
	IgnoreEmptyConfigError bool
}

Jump to

Keyboard shortcuts

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