OpenResty ENV cache
Lua Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
bin
rockspecs
spec/resty
src/resty
.codeclimate.yml
.gitignore
.luacheckrc
LICENSE
Makefile
README.md
dist.ini

README.md

Name

lua-resty-env - Lua cache for calls to os.getenv.

Table of Contents

Status

This library is considered production ready.

Description

This Lua library is a cache for calls to os.getenv.

This library acts as a mediator between other libraries and the environment variables. Variables can not only be get but also set.

Synopsis

env SOME_VARIABLE;

http {
    server {
        location /test {
            content_by_lua_block {
                local resty_env = require 'resty.env'

                ngx.say("SOME_VARIABLE: ", resty_env.get('SOME_VARIABLE'))
            }
        }
    }

Back to TOC

Methods

All the methods are expected to be called on the module without self.

Back to TOC

get

syntax: val = env.get(name)

Returns environment value from the cache or uses os.getenv to get it.

Back to TOC

set

syntax: prev = env.set(name, value)

Sets the the value to the cache and returns the previous value in the cache.

Back to TOC

value

syntax: val = env.value(name)

Same as get, but returns nil for envs whose value is an empty string.

Back to TOC

list

syntax: table = env.list()

Returns a table with all environment variables. Names are keys and values are values.

Back to TOC

enabled

syntax: ok = env.enabled(name)

Returns true if the environment variable has truthy value (1, true), false (0, false) or nil.

Back to TOC

reset

syntax: env = env.reset()

Resets the internal cache.

Back to TOC

Installation

If you are using the OpenResty bundle (http://openresty.org ), then you can use opm to install this package.

opm get 3scale/lua-resty-env

Back to TOC

Bugs and Patches

Please report bugs or submit patches by

  1. creating a ticket on the GitHub Issue Tracker,

Back to TOC

Author

Michal "mikz" Cichra mcichra@redhat.com, Red Hat Inc.

Back to TOC

Copyright and License

This module is licensed under the Apache License Version 2.0.

Copyright (C) 2016-2017, Red Hat Inc.

All rights reserved.

See LICENSE for the full license.

Back to TOC

See Also

Back to TOC