boost

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

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 18 Imported by: 0

README

Boost

godoc

Scripted Lua configuration for Go!

boosters

Boost is a simple configuration engine driven by Lua scripts.

Install

This package is go get-able so I'm sure you know what to do... (but just in case you don't ↲)

go get github.com/cosmotek/boost

Example

In addition to the example below, I've included an much more detailed example in the examples folder.

example.conf

-- some global values
random = {
  one = 1,
  two = 2,
  strawberries = "red"
}

-- configuration function
MyApp.configure = function(config)
  config.favorites.fruits = {
    "apple",
    "orange"
  }

  config.favorites.color = "red"
  config.favorites.animals = true
end

main.go

package main

import (
	"fmt"

	"github.com/cosmotek/boost"
	"github.com/cosmotek/boost/types"
)

type Configuration struct {
	Favorites struct {
    Color string
    Animals bool
    Fruits []string
  }
}

func main() {
	conf, err := boost.NewAppConfig(
		"MyApp",
		"example.conf",
    		// enabled debug logging
		true,
		types.NewString("name", "seth"),
	)

	defer conf.Cleanup()
	if err != nil {
		panic(err)
	}

	config := &Configuration{}
	err = conf.ParseFunction("configure", config)
	if err != nil {
		panic(err)
	}

	fmt.Println(config)
}

API Coverage

At the moment all Lua stdlib packages appear to be fully functional (os, io, file, math etc..) as well as a few Gopher-Lua modules for serialization, http and utility. Native/Pure Lua libraries and C-Wrapping modules are yet to be tested. Most pure Lua code should work, anything interfacing with C should not be expected to work.

Included Gopher-Lua Modules:

  • http (http client wrapping net/http)
  • re (regex)
  • json
  • yaml
  • xmlpath
  • url (parser)
  • lfs (Lua Filesystem, not complete)

Shout-outs

Special Thanks to the creator of https://github.com/yuin/gopher-lua which this library is almost fully dependent on.

Contribution and maintenance

While Boost has been tested in small apps, be careful when using this library for anything in sensitive environments. If you would like to make a suggestion or report a bug, please feel free to submit a PR or issue. I really hope you enjoy using Boost! Thanks!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App is used to maintain the underlying state for the lua vm

func NewAppConfig

func NewAppConfig(name, filename string, enableLogging bool, globals ...Global) (*App, error)

NewAppConfig creates a lua vm session and app config using an application name (used to create the root table), filename/path and some globals (optional). The passed file may have any extension as long as it is a valid lua script. You may prefer to use a .lua extension for automatic syntax highlighting in editors.

func (*App) Cleanup

func (a *App) Cleanup()

Cleanup closes and cleans up the lua VM, this must be called when all interaction with the config app is complete

func (*App) GetGlobal

func (a *App) GetGlobal(key string, mapping interface{}) error

GetGlobal retrieves a global object from the lua vm and maps it to the provided mapping pointer. This seems to only work when the object matching the provided key is a table.

func (*App) ParseFunction

func (a *App) ParseFunction(method string, mapping interface{}) error

ParseFunction runs the method by provided method name, app name and maps the result to the provided 'mapping' pointer. The mapping must be a ptr of a struct or map type.

type Global

type Global interface {
	GetKey() string
	GetValue() lua.LValue
}

Global is a simple object used to create a lua object (const, table etc) that can be injected into the app config for use within the lua script

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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