Categorygithub.com/mitz-it/golang-config
modulepackage
0.0.3
Repository: https://github.com/mitz-it/golang-config.git
Documentation: pkg.go.dev

# README

Golang - Config

Quality Gate Status Coverage

Abstraction over Viper to read environment variables.

Environment variables from .env files are also supported.

Installation

  go get -u github.com/mitz-it/golang-config

Usage 1

package main

import "github.com/mitz-it/golang-config"

func main() {
  prefix := "mtz" // all environment variables starting with MTZ_ will be loaded
  start := config.StartConfig{
    ConfigPath: "../config/.env",
    Prefix: prefix,
  }

  cfg := config.NewConfig(start)

  connStr := cfg.Standard.GetString("connection_string") // MTZ_CONNECTION_STRING

  // ...
}

Usage 2

package main

import "github.com/mitz-it/golang-config"

func init() {
  prefix := "mtz" // all environment variables starting with MTZ_ will be loaded
  path := "../config/.env"
  config.LoadEnv(prefix, path)
}

func main() {
  connStr := config.Env.GetString("connection_string") // MTZ_CONNECTION_STRING

  // ...
}

Scopes

package main

import "github.com/mitz-it/golang-config"

func init() {
  config.LoadScopedEnv("scope1", "sc1", "../config/.env")
  config.LoadScopedEnv("scope1", "sc2", "../config/.env")
}

func main() {
  connStr1 := config.Scope("scope1").Env.GetString("connection_string") // SC1_CONNECTION_STRING
  connStr2 := config.Scope("scope2").Env.GetString("connection_string") // SC2_CONNECTION_STRING

  // ...
}

# Functions

Loads the .env file with the given path.
Creates a new environment variables scope and loads the .env file with the given path into the new scope.
Creates a new `Config` instance, given a `StartConfig` Loads the .env file with the given path.
Retrives the environment scope with the given key.

# Variables

Instance to read environment variables.

# Structs

Defines the instance type to be used to retrieve environment variables.
Defines the environment variables reader.
No description provided by the author
Defines all the necessary input to load environment variables.