envloader

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 7 Imported by: 0

README

EnvLoader

Version

Secret manager integration to get application environment variables. Any variable not set by the secret manager will be set by OS envs.

Jump To:

Getting Started

Installing

Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/thrcorrea/envloader.git

To update the module use go get -u to retrieve the latest version of the module.

go get -u github.com/thrcorrea/envloader.git
Go Modules

If you are using Go modules, your go get will default to the latest tagged release version of the module. To get a specific release version of the module use @<tag> in your go get command.

go get github.com/thrcorrea/envloader.git@v1.0.0

To get the latest module repository change use @latest.

go get github.com/thrcorrea/envloader.git@latest

Quick Examples

This example shows a complete working Go file which will make a struct for environment variables and initialize with this module.

Complete SDK Example

REGION is setting automatically on AWS environment, only setting if needs to be different.

SECRET_NAME=aws-secret-manager-name
REGION=aws-secret-manager-region
package main

import (
    "github.com/thrcorrea/envloader.git"
)

type Environment struct {
    DBHost          string `env:"DB_HOST"`
    DBName          string `env:"DB_NAME"`
    DBPort          string `env:"DB_PORT"`
    DBUser          string `env:"DB_USER"`
    DBPassword      string `env:"DB_PSWD"`
    RabbitHost      string `env:"AMQP_HOST"`
    RabbitUser      string `env:"AMQP_USER"`
    RabbitPassword  string `env:"AMQP_PSWD"`
    AmqpVHost       string `env:"AMQP_VHOST,optional"` // optional = disable empty validation
    AmqpProtocol    string `env:"AMQP_PROTOCOL,optional,default=AMQP"` //default, set a default value if key not setted on env and secret
}

var env Environment

func main() {
    // will run only if SECRET_NAME and REGION is setted in dotenv file
    // load environment with dotenv values and secret manager values
    // default file name is ".env" and doesn't need to be sent
    err := envloader.Load(&env, ".env.test")
    if err != nil {
        // failed to load environment variables
        panic(err)
    }
}

Documentation

Index

Constants

View Source
const (
	OptionalKey = "optional"
	DefaultKey  = "default"
)

Variables

This section is empty.

Functions

func Load

func Load(vars interface{}, filenames ...string) error

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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