config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Config Package

Overview

The config package manages configurations in Go applications, ensuring compatibility between config.yaml and setup.env. setup.env is used to setup environment variables.

Note - When both environment variables and config.yaml settings are present, the package prioritizes environment variables, overriding equivalent settings in config.yaml.

Compatible configurations example

The below configurations are compatible in this project.

  • setup.env contains:

    export LOGFILE_PATH=poc-mc-net-tf.log
    
  • config.yaml has:

    logfile:
        path: ./poc-mc-net-tf.log
    

How to use it

  • Use a blank import in your package (e.g., main, logger, and so on)
  • Get a value using Viper

Note - It's just my preference. config.Init() can be used.

import (
    // other packages

    // Loads configurations from setup.env and config.yaml
    _ "github.com/cloud-barista/poc-mc-net-tf/pkg/config"
)

func main() {
    logFilePath := viper.GetString("logfile.path")
    // Application logic follows
}

Wrapping Up

This setup illustrates the package's ability to harmonize settings from both setup.env and config.yaml, showcasing its versatility and ease of use.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Types

This section is empty.

Jump to

Keyboard shortcuts

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