config

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

go-config

License GitHub all releases GitHub issues GitHub commit activity Go Report Card GitHub release GitHub stars GitHub forks

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.1v0.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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindByID

func FindByID[T Identifiable](slice []T, id string) (*T, error)

Types

type Config

type Config struct {
	Referrer string
	Stage    string
	File     string
}

type Configurator

type Configurator struct {
	Storage    types.Storager
	ConfigFile string
}

func NewConfigurator

func NewConfigurator(cfg *Config, store types.Storager) *Configurator

func (*Configurator) Load

func (c *Configurator) Load(config interface{}) error

type Identifiable

type Identifiable interface {
	GetID() string
}

Jump to

Keyboard shortcuts

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