Exemple #1
0
func (kvs *KvStoreModule) getjson(L *lua.LState) int {
	kv, err := kvs.kvStore.Get(L.ToString(1), L.ToInt(2))
	if err != nil {
		panic(err)
	}
	table := kvToTable(L, kv)
	L.RawSet(table, lua.LString("value"), luautil.FromJSON(L, []byte(kv.Value)))
	L.Push(table)
	return 1
}
Exemple #2
0
func (kvs *KvStoreModule) keysjson(L *lua.LState) int {
	luaTable := L.NewTable()
	kvResp, err := kvs.kvStore.Keys(L.ToString(1), L.ToString(2), L.ToInt(3))
	if err != nil {
		panic(err)
	}
	for index, kv := range kvResp {
		kvTable := kvToTable(L, kv)
		L.RawSet(kvTable, lua.LString("value"), luautil.FromJSON(L, []byte(kv.Value)))
		L.RawSetInt(luaTable, index+1, kvTable)
	}
	L.Push(luaTable)
	return 1
}
Exemple #3
0
// Return the HTTP request body parsed as JSON
func (req *RequestModule) json(L *lua.LState) int {
	var body []byte
	if req.cached {
		body = req.cache
	} else {
		resp, err := ioutil.ReadAll(req.request.Body)
		if err != nil {
			panic(err)
		}
		body = resp
		req.cache = resp
		req.cached = true
	}
	L.Push(luautil.FromJSON(L, body))
	return 1
}