genv

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 8 Imported by: 0

README

genv

A simple Golang library to manage your environment variables using structs.

How to use

package main

import (
	"github.com/vdgonc/go-env-test/genv"
)

type Environments struct {
	RabbitMQ struct {
		Host string `env:"RABBITMQ_HOST"`
		Port int    `env:"RABBITMQ_PORT"`
	}
	Redis struct {
		Host string `env:"REDIS_HOST"`
		Port int    `env:"REDIS_PORT"`
	}
	Mongo struct {
		Host string `env:"MONGO_HOST"`
		Port int    `env:"MONGO_PORT"`
	}
	MySQL struct {
		Host string `env:"MYSQL_HOST,required=true"`
		Port int    `env:"MYSQL_PORT,required=true"`
	}
}

func main() {
	environment := Environments{}
	genv.LoadEnvironmentVars(&environment)
}


Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidValue    = errors.New("value must be a non-nil pointer to a struct")
	ErrUnsupportedType = errors.New("field is an unsupported type")
	ErrUnexportedField = errors.New("field must be exported")
	ErrInvalidField    = errors.New("field must be a struct, pointer to a struct, or pointer to a pointer to a struct")
	UnmarshalType      = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
)

Functions

func LoadEnvironmentVars

func LoadEnvironmentVars(v interface{})

func Unmarshal

func Unmarshal(es EnvSet, v interface{}) error

Types

type EnvSet

type EnvSet map[string]string

func Marshal

func Marshal(v interface{}) (EnvSet, error)

func UnmarshalFromEnviron

func UnmarshalFromEnviron(v interface{}) (EnvSet, error)

type ErrMissingRequiredValue

type ErrMissingRequiredValue struct {
	Value string
}

func (ErrMissingRequiredValue) Error

func (e ErrMissingRequiredValue) Error() string

type Marshaler

type Marshaler interface {
	MarshalEnvironmentValue() (string, error)
}

type Unmarshaler

type Unmarshaler interface {
	UnmarshalEnvironmentValue(data string) error
}

Jump to

Keyboard shortcuts

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