Skip to content
/ envir Public

Helps with obtainig the shell env values or values from .env file or other sources (i.e. yaml) in certain priority.

License

Notifications You must be signed in to change notification settings

rogozhka/envir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envir is a tiny library inspired by Viper. Focused on declarative OOP composition. You can setup desired priority and extend processing logic by adding your own variable expander or even different sources.

Example:

import (
    "github.com/rogozhka/envir"
    "github.com/rogozhka/envir/decoders"
)

const envPrefix = "APPNAME"

func main() {
	env := envir.New(
		envir.WithPrefix(envPrefix),
		envir.WithEnvSubst(), // use "github.com/a8m/envsubst" as a custom vars processing 
		envir.WithLookup(
			envir.NewLookupComposition(
				envir.NewLookupFile(
					"app.yaml", // first priority, unprefixed vars inside env: section
					envir.WithCutPrefix(envPrefix),
					envir.WithDecoder(
						decoders.NewYaml(
							decoders.WithEntriesPath("env"),
						),
					),
				),
				envir.WithOptional( // second priority, prefixed vars in the document root
					envir.NewLookupFile(
						"dev.yaml",
						envir.WithDecoder(decoders.NewYaml()),
					),
				),
				envir.WithOptional( // third priority, shell env w/ prefix
					envir.NewLookupOs(),
				),
			),
		),
	)
	const (
		envPgHost = "DB_SERVER"
		envPgPort = "DB_PORT"
		envHome   = "HOME"
	)

	pgHost := env.String(envPgHost, "localhost")
	pgPort := env.Int(envPgPort, 5432)
	// ...

	home := env.MustString(envHome)
 
  // ...
}

About

Helps with obtainig the shell env values or values from .env file or other sources (i.e. yaml) in certain priority.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages