gconfig

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

Gconfig

Build Status Go Report Card Go Reference Coverage

GConfig is a go library to handle configuration file and environment variables.

It uses viper and koanf to handle env vars and configuration file.

Install

go get -u github.com/platform-horizon/gconfig

Usage

Read Environment variables
type EnvironmentVariables struct {
    LogLevel string
    HTTPPort string
}

var envVariablesConfig = []gconfig.EnvConfig{
    {
        Key:      "LOG_LEVEL",
        Variable: "LogLevel",
        Required: true
    },
    {
        Key:      "HTTP_PORT",
        Variable: "HTTPPort",
    },
}

var env EnvironmentVariables

if err := gconfig.GetEnvVariables(envVariablesConfig, &env); err != nil {
    panic(err.Error())
}
Read from file
type ConfigurationFileVariables struct {
    LogLevel string
    HTTPPort string
}

var configuration ConfigurationFileVariables

if err := gconfig.GetConfigFromFile("config.test", ".", &configuration); err != nil {
    panic(err.Error())
}
    

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigFromFile

func GetConfigFromFile(configName string, configPath string, output interface{}) error

GetConfigFromFile func read configuration from file and save in output interface.

func GetEnvVariables

func GetEnvVariables(envVariablesConfig []EnvConfig, output interface{}) error

GetEnvVariables extracts configured environment variables and unmarshals them in provided `output` interface.

Types

type EnvConfig

type EnvConfig struct {
	Key          string
	Variable     string
	DefaultValue string
	Required     bool
}

EnvConfig struct to access env variables

Jump to

Keyboard shortcuts

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