config

package
v0.0.0-...-d2a29b3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 4 Imported by: 0

README

config

This package provides configuration loading and environment setup utilities.

Functions

EnvKeyReplace
func EnvKeyReplace(input string, replacements map[string]string) string

Replaces all {key} in the input string with their values from the replacements map.

EnvOverride
func EnvOverride(env map[string]string)

Sets environment variables from the provided map.

LoadToml
func LoadToml(target interface{}, configfile string) error

Loads TOML configuration from a file into the provided struct pointer.

SaveToml
func SaveToml(path string, cfg interface{}) error

Saves a struct as TOML to the given file path.

Example

import "github.com/Merith-TK/utils/pkg/config"

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

var cfg MyConfig
err := config.LoadToml(&cfg, "config.toml")
if err != nil {
    // handle error
}

cfg.Name = "test"
err = config.SaveToml("config.toml", cfg)
if err != nil {
    // handle error
}

Documentation

Overview

Package config provides configuration management utilities including environment variable manipulation, key replacement, and TOML configuration file handling.

The package offers two main areas of functionality:

  • Environment variable management with key-value replacement
  • TOML configuration file loading and saving

Key replacement allows templating in configuration strings using {KEY} syntax. Environment override provides a convenient way to set multiple environment variables.

Example usage:

// Key replacement
replacements := map[string]string{"{USER}": "john", "{HOME}": "/home/john"}
result := config.EnvKeyReplace("User: {USER}, Home: {HOME}", replacements)

// Environment override
env := map[string]string{"DEBUG": "true", "PORT": "8080"}
config.EnvOverride(env)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvKeyReplace

func EnvKeyReplace(input string, replacements map[string]string) string

EnvKeyReplace replaces all {key} in the input string with their values from the replacements map.

func EnvOverride

func EnvOverride(env map[string]string)

EnvOverride sets environment variables from the provided map.

func LoadToml

func LoadToml(target interface{}, configfile string) error

LoadToml loads and parses the config file at the given path into the provided struct pointer. The config file must be in TOML format.

func SaveToml

func SaveToml(path string, cfg interface{}) error

SaveToml saves a struct as TOML to the given file path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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