https://github.com/ikeikeikeike/goluacnf
This is a convenient configuration that's why it has a lua lang
https://github.com/ikeikeikeike/goluacnf
Last synced: 3 months ago
JSON representation
This is a convenient configuration that's why it has a lua lang
- Host: GitHub
- URL: https://github.com/ikeikeikeike/goluacnf
- Owner: ikeikeikeike
- License: mit
- Created: 2015-09-23T14:29:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-26T11:32:23.000Z (over 9 years ago)
- Last Synced: 2025-01-19T21:14:16.918Z (5 months ago)
- Language: Go
- Homepage:
- Size: 145 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-luacnf
========[](https://travis-ci.org/ikeikeikeike/goluacnf)
> ## wats go-luacnf
> Just I wanted to do that.```Go
import "github.com/ikeikeikeike/goluacnf"
```## Usage
We can use lua file as a configuration file like this.
```lua
function merge(t1, t2)
local t = {}
for k, v in pairs(t1) do t[k] = v end
for k, v in pairs(t2) do t[k] = v end
return t
endcommon = {
letter_a = "a", -- site title
letter_b = "b",
letter_c = "c",
string = "1",
int = 1,
float = 0.01,
yes = true,
no = false,
map = {{
first = "common1",
second = "common1",
third = "common1",
},{
first = "common2",
second = "common2",
third = "common2",
}}
}development = merge(common, {
name = "development",
dsn = "postgres://username:[email protected]:5432/goluacnf",
table = {{
first = "development1",
second = "development1",
third = "development1",
},{
first = "development2",
second = "development2",
third = "development2",
}}
})production = merge(common, {
name = "production",
dsn = "postgres://username:[email protected]:5432/goluacnf",
table = {{
first = "production1",
second = "production1",
third = "production1",
},{
first = "production2",
second = "production2",
third = "production2",
}}
})
```### Loading a configuration file
We can write in this way if we want to change configuration's file path.
```go
func (app *App) initConfig() {
cnf, err := goluacnf.Register(
path.Join(goluacnf.Root, "configs/config.lua"),
goluacnf.Env,
)
if err != nil {
panic(err)
}app.Conf = cnf
}
```### Change a environment on console
If we want to change our environment on console its like this.
```bash
$ GOLUACNF_ENV=production go run server.go
```### Touch a conf's data
goluacnf have a variety of methods that we can choose those methods.
```go
cnf, _ := goluacnf.Register(
path.Join(goluacnf.Root, "configs/config.lua"),
goluacnf.Env,
)cnf.String("String") // "1"
cnf.Int("Int")
cnf.Int64("Int")
cnf.Float("Float")
cnf.Float32("Float")
cnf.Bool("Yes") // true
cnf.Bool("No") // false
// cnf.Map(&c)
```That can map to struct also.
```go
type testcnf struct {
String string
Int int
Float float64
Yes bool
No bool
Tbl []struct {
First string
Second string
Third string
}
}func Doing() {
cnf, _ := goluacnf.Register(
path.Join(goluacnf.Root, "configs/config.lua"),
goluacnf.Env,
)c := testcnf{}
cnf.Map(&c)c.String // "1"
c.Int
c.Float
c.Yes // true
c.No // false
c.Tbl // []struct {First:"dev1", Second:"dev1", Third:"dev1"}, {First:"dev2", Second:"de,,,,, }
}
```