examples: update methods signatures
Update methods signatures in order to generate correct manifest files with full description of available methods.
This commit is contained in:
parent
53ff02f1ad
commit
db8cb752e3
4 changed files with 144 additions and 64 deletions
|
@ -7,51 +7,72 @@ import (
|
|||
|
||||
// Main is a very useful function.
|
||||
func Main(operation string, args []interface{}) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
// Puts value at key
|
||||
if operation == "put" {
|
||||
if checkArgs(args, 2) {
|
||||
key := args[0].([]byte)
|
||||
value := args[1].([]byte)
|
||||
storage.Put(ctx, key, value)
|
||||
return key
|
||||
}
|
||||
return Put(args)
|
||||
}
|
||||
|
||||
// Returns the value at passed key
|
||||
if operation == "get" {
|
||||
if checkArgs(args, 1) {
|
||||
key := args[0].([]byte)
|
||||
return storage.Get(ctx, key)
|
||||
}
|
||||
return Get(args)
|
||||
}
|
||||
|
||||
// Deletes the value at passed key
|
||||
if operation == "delete" {
|
||||
key := args[0].([]byte)
|
||||
storage.Delete(ctx, key)
|
||||
return true
|
||||
return Delete(args)
|
||||
}
|
||||
|
||||
// Returns an array of key-value pairs with key that matched the passed value
|
||||
if operation == "find" {
|
||||
if checkArgs(args, 1) {
|
||||
value := args[0].([]byte)
|
||||
iter := storage.Find(ctx, value)
|
||||
result := []string{}
|
||||
for iterator.Next(iter) {
|
||||
val := iterator.Value(iter)
|
||||
key := iterator.Key(iter)
|
||||
result = append(result, key.(string)+":"+val.(string))
|
||||
}
|
||||
return result
|
||||
}
|
||||
return Find(args)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Put puts value at key.
|
||||
func Put(args []interface{}) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
if checkArgs(args, 2) {
|
||||
key := args[0].([]byte)
|
||||
value := args[1].([]byte)
|
||||
storage.Put(ctx, key, value)
|
||||
return key
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Get returns the value at passed key.
|
||||
func Get(args []interface{}) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
if checkArgs(args, 1) {
|
||||
key := args[0].([]byte)
|
||||
return storage.Get(ctx, key)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Delete deletes the value at passed key.
|
||||
func Delete(args []interface{}) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
key := args[0].([]byte)
|
||||
storage.Delete(ctx, key)
|
||||
return true
|
||||
}
|
||||
|
||||
// Find returns an array of key-value pairs with key that matched the passed value.
|
||||
func Find(args []interface{}) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
if checkArgs(args, 1) {
|
||||
value := args[0].([]byte)
|
||||
iter := storage.Find(ctx, value)
|
||||
result := []string{}
|
||||
for iterator.Next(iter) {
|
||||
val := iterator.Value(iter)
|
||||
key := iterator.Key(iter)
|
||||
result = append(result, key.(string)+":"+val.(string))
|
||||
}
|
||||
return result
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func checkArgs(args []interface{}, length int) bool {
|
||||
if len(args) == length {
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue