feat: call function without argument

This commit is contained in:
debugtalk
2021-10-03 12:30:53 +08:00
parent 2780ad9f67
commit 92b2b18b9e
3 changed files with 24 additions and 10 deletions

View File

@@ -1,15 +1,23 @@
package builtin
import (
"crypto/md5"
"encoding/hex"
"math"
"math/rand"
"time"
)
var Functions = map[string]interface{}{
"get_timestamp": getTimestamp, // call without arguments
"sleep": sleep, // call with one argument
"gen_random_string": genRandomString, // call with one argument
"max": math.Max, // call with two arguments
"md5": MD5,
}
func getTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
func sleep(nSecs int) {
@@ -26,3 +34,9 @@ func genRandomString(n int) string {
}
return string(b)
}
func MD5(str string) string {
hasher := md5.New()
hasher.Write([]byte(str))
return hex.EncodeToString(hasher.Sum(nil))
}