Skip to content

DBoroujerdi/env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Env

Environment lookup and caching utility, primarily aimed at apps deployed with docker.

What is it?

Often when building and using Docker containers we like to override internal config via environment variables. In practice this requires juggling the use of both the application and os modules which have different API's.

What is it like?

    %% os
    string()|boolean() = os:getenv("REMOTE_NAME"),
    string()|boolean() = os:getenv("REMOTE_PORT"),

    %% application
    {ok, any()}|undefined = application:get_env(app_name, 'REMOTE_HOST'),
    {ok, any()}|undefined = application:get_env(app_name, 'REMOTE_PORT'),

This can be replace with the following.

    string()|undefined = env:get_string(app_name, 'REMOTE_HOST'),
    integer()|undefined = env:get_integer(app_name, 'REMOTE_PORT'),

Caching

Once a variable has been successfully obtained from either source it is cached in ETS, then for any subsequent calls it is obtained from ETS. So there isn't really any need to store the variables outside in your application. If an application or processs that requires a variable dies, it can simply read it again when it restarts.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published