Main API Reference

In the call main function, there is a parameter, which we usually define as the variable “input”, which provides the following members and methods. Because the bottom layer of Lockval Engine is implemented in Go, we directly show the Go code

UID      string         // Which user called (call,login,watch)
KSUID    string         // system call ID (system call)
Info     string         // login Info(login)
WATCHUID string         // Which ID to observe (watch)
Requ     map[string]any // User Request Parameters (call)

Json any // Json object

GetResp *GetAndLockResp // Data returned from GetAndLock

Throw            func(Code int, Error string)                    // Throw throw an error to the client
Log              func(v any)                                     // Log Output an arbitrary data to the console
Sleep            func(ms int64, ksuid, cmd string, obj any)      // Sleep Call cmd("xxx/xxx", obj) after timing ms, ksuid:must have value
GetSubValAll     func(id, key string) *GetOpt                    // GetSubValAll Get all the data of the key
GetAndLock       func()                                          // GetAndLock Acquire and lock (can only be called once)
DiscardAndUnlock func() (resp *PutAndUnlockResp)                 // DiscardAndUnlock discard all edits (can only be called once)
PutAndUnlock     func() (resp *PutAndUnlockResp)                 // PutAndUnlock change and unlock (can only be called once)
GetSubVal        func(id, key string, subkeys ...string) *GetOpt // GetSubVal Get some data, when the subkeys are empty, it is to get all
PutSubVal        func(id, key string, kvs ...string) *PutOpt     // PutSubVal set key value

The code can be viewed here:

How to use, let’s give a simple example:

import { Dict, DBOperate } from "../libs/lockvalserver"

export function main(input: DBOperate<any>) {
  input.GetSubVal(input.UID, "mBase", "Count")

  let c = input.GetResp.IDKey[input.UID]?.KeySub["mBase"]?.SubVal["Count"]

  let ci = Number(c)
  c = ci.toString()

  input.PutSubVal(input.UID, "mBase", "Count", c)

  return { Hello: "JS" }
return require("umd").define({
}, function(exports, helper)

    function exports.main(input)

        input.GetSubVal(input.UID, "mBase", "Count")

        local c = helper.GetResp(input, input.UID, "mBase", "Count")
        if c == "" then
            c = "0"
        local ci = tonumber(c)
        ci = ci + 1
        c = tostring(ci)

        input.PutSubVal(input.UID, "mBase", "Count", c)

        local retval = {}
        retval.Hello = "Lua"
        return retval

def main(input):
  input.GetSubVal(input.UID, "mBase", "Count")

  c = input.GetResp.IDKey[input.UID].KeySub["mBase"].SubVal["Count"]

  if c=="":
  ci = int(c)
  c = str(ci)

  input.PutSubVal(input.UID, "mBase", "Count", c)

  return {"Hello":"Starlark"}
package usr

import (


func (e export) Export_testBaseCount(input *go2plugin.Input) map[string]any {
	input.GetSubVal(input.UID, "mBase", "Count")

	c := helper.GetResp(input, input.UID, "mBase", "Count")

	ci, _ := strconv.Atoi(c)
	c = strconv.Itoa(ci)

	input.PutSubVal(input.UID, "mBase", "Count", c)

	return map[string]any{"Hello": "Go"}

Last modified September 9, 2023: update demos (59bb385)