koanflua

package module
v0.0.0-...-e28967f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 4 Imported by: 0

README

Koanf Lua

Koanf Lua allows to write dynamic configuration files for koanf configuration manager. Sometimes dynamic configuration is required.

Usage

-- config.lua
local os = require "os"

local config = {
  brokers = array({"localhost:42", "localhost:4242"}), -- Hack for Golang to detect the table as an array
  listen = "localhost",
  redis = {
    addr = "localhost:6379",
    password = "trololo",
    db = 1
  }
}

if os.getenv("MAGIC_FEATURE") == "enabled" then
  config["feature"] = "testouille"
end

luaconfig(config)
package main

import (
	"fmt"
	"log"

	"github.com/knadh/koanf"
	"github.com/knadh/koanf/providers/file"
	"github.com/mdouchement/koanflua"
)

func main() {
	konf := koanf.New(".")
	err := konf.Load(file.Provider("config.lua"), koanflua.Parser())
	if err != nil {
		log.Fatal(err)
	}

	//

	redisAddr := konf.String("redis.addr")
	fmt.Println(redisAddr)
}

Resources

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LUA

type LUA struct {
	// contains filtered or unexported fields
}

LUA implements a LUA parser for koanf.

func Parser

func Parser() *LUA

Parser returns a LUA Parser.

func (*LUA) Parse

func (p *LUA) Parse(b []byte) (map[string]interface{}, error)

Parse parses the given LUA bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL