go-config

go-config is a module which loads a YAML configuration file from a "remote" source. It supports multiple storage backends through go-storage.
The intended usage is to load the configuration from a YAML file, for a web application written in Go. The file could be local or remote (from any source supported by go-storage).
Installation
go get github.com/rgglez/go-config
Configuration
c := config.NewConfigurator(&config.Config{
Referrer: "",
Stage: "",
File: "config.yaml",
}, s)
The configuration config.Config struct taken as the first parameter has this properties:
Referrer string, optional, the referrer as provided by the web framework you are using.
Stage string, an optional prefix for the path of the configuration. For example: "dev" or "production".
File string, required, the file name of the configuration file.
TmpDir string, optional path for a temporary directory where the remote file will be downloaded into a local temporary file.
The second parameter, s in the example, must be a types.Storager from go-storage. You can obtain one using services.NewStoragerFromString:
import (
services "github.com/rgglez/go-storage/v5/services"
_ "github.com/rgglez/go-storage/services/oss/v3" // or whichever backend you need
)
s, err := services.NewStoragerFromString(cnn)
Where cnn is a valid connection string as specified by go-storage.
For example, for a bucket named test in an ossemulator server running at localhost, the connection string would be:
cnn := "oss://test/?credential=hmac:Secret123:Secret123&endpoint=http://127.0.0.1:9090&name=test"
The configuration file path is formed by these components:
domain + "/" + stage + "/" + file
where the domain is obtained from the Referrer.
Since domain and stage are optional, the file could be in the root of the remote path. For instance, if the source is a S3 bucket, the key could:
example.com/config.yaml
or
prod/config.yaml
or even
config.yaml
Usage
The configuration file could be loaded into a struct (which should reflect the structure of your YAML file) or a map. For example:
var cfgMap map[string]interface{}
err := c.Load(&cfgMap)
var cfgStruct Configuracion
err = c.Load(&cfgStruct)
See the sample code.
Makefile
A Makefile is provided for version tagging using semver.
| Target |
Description |
make tag-current |
Prints the latest semver tag (e.g. v0.2.1). Defaults to v0.0.0 if no tags exist. |
make tag-patch |
Creates a new tag incrementing the patch component by 1 (e.g. v0.2.1 → v0.2.2). |
make tag-push |
Pushes the latest tag to the remote repository. |
Typical workflow:
make tag-next # create the new tag locally
make tag-push # push it to the remote
Or in a single step:
make tag-next tag-push
Dependencies
This module uses:
and its respective dependencies.
License
Copyright 2026 Rodolfo González González.
Licensed under Apache 2.0 license.