route/internal/gluaroute/route.go

50 lines
736 B
Go

package gluaroute
import (
"net/http"
"git.xeserv.us/xena/route/proto"
"git.xeserv.us/xena/route/proto/route"
lua "github.com/yuin/gopher-lua"
luar "layeh.com/gopher-luar"
)
var exports = map[string]lua.LGFunction{
"new": newClient,
}
func newClient(L *lua.LState) int {
routedURL := L.ToString(1)
token := L.ToString(2)
L.Push(luar.New(L, route.New(routedURL, token, &http.Client{})))
return 1
}
type client struct {
*route.Client
}
type backends struct {
proto.Backends
}
type routes struct {
proto.Routes
}
type tokens struct {
proto.Tokens
}
func Preload(L *lua.LState) {
L.PreloadModule("svc", Loader)
}
func Loader(L *lua.LState) int {
mod := L.SetFuncs(L.NewTable(), exports)
L.Push(mod)
return 1
}