enve

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 7 Imported by: 0

README

ENVE

An extended, too simple, zero-dependencies library to parse environment variables into structs

Go Reference Go Report Card

About

An extended, too simple, zero-dependencies library to parse environment variables into structs.
Library provides interfaces for implementing and using environment variable sources, allowing you to use multiple environment variable sources at once.
Enve based on encoding/json lib

Installation

go get github.com/rejchev/enve

Usage

type config struct {
    AppName string  `json:"APP_NAME"`
    IsDebug bool    `json:"IS_DEBUG,string"`    
}

c := config{}

// Using os.Environ() as envs source
err := enve.Parse(&c, new(enve.EnvironSource))

// Using io.Reader as envs source
envs := "APP_NAME=testname\n" +
        "IS_DEBUG=true"

reader := strings.Reader(envs)

err := enve.Parse(&c, enve.NewReaderSource(reader))

// Using combines of sources
err := enve.Parse(&c, enve.NewReaderSource(reader), new(enve.EnvironSource))

// Using custom source
var _ enve.IEnveSource = (*CustomEnveSource)(nil)

type CustomEnveSource byte

func (e *EnvironSource) GetEnvs() (map[string]string, error) {
    m := make(map[string]string)

    // some logic
    
    return m, nil
}

err := enve.Parse(&c, new(CustomEnveSource))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnvs

func GetEnvs(i []IEnveSource) ([]byte, error)

func Parse

func Parse(v any, s ...IEnveSource) error

Types

type EnvironSource

type EnvironSource byte

func (*EnvironSource) GetEnvs

func (e *EnvironSource) GetEnvs() (map[string]string, error)

type IEnveSource

type IEnveSource interface {
	GetEnvs() (map[string]string, error)
}

type ReaderSource

type ReaderSource struct {
	// contains filtered or unexported fields
}

func NewReaderSource

func NewReaderSource(ior io.Reader) *ReaderSource

func NewReaderSourceE added in v1.1.0

func NewReaderSourceE(ior io.Reader, delim byte) *ReaderSource

func (*ReaderSource) GetEnvs

func (r *ReaderSource) GetEnvs() (map[string]string, error)

Jump to

Keyboard shortcuts

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