Thanks to visit codestin.com
Credit goes to github.com

Skip to content

kohkimakimoto/gluaenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gluaenv

Utility package for manipulating environment variables for gopher-lua

Installation

go get github.com/kohkimakimoto/gluaenv

API

env.set(key, value)

Same os.setenv

env.get(key)

Same os.getenv

env.loadfile(file)

Loads environment variables from a file. The file is as the following:

AAA=BBB
CCC=DDD

If this function fails, it returns nil, plus a string describing the error.

Usage

package main

import (
    "github.com/yuin/gopher-lua"
    "github.com/kohkimakimoto/gluaenv"
)

func main() {
    L := lua.NewState()
    defer L.Close()

    L.PreloadModule("env", gluaenv.Loader)
    if err := L.DoString(`
local env = require("env")

-- set a environment variable
env.set("HOGE_KEY", "HOGE_VALUE")

-- get a environment variable
local v = env.get("HOGE_KEY")

-- load envrironment variables from a file.
env.loadfile("path/to/.env")

-- file example
-- AAA=BBB
-- CCC=DDD

`); err != nil {
        panic(err)
    }
}

Author

Kohki Makimoto [email protected]

License

MIT license.

About

Utility package for manipulating environment variables for gopher-lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages