Merge branch 'dev' into use_containsall

This commit is contained in:
mzack9999 2024-07-15 11:00:08 +02:00
commit 8f22eb596e
2 changed files with 27 additions and 2 deletions

View File

@ -42,7 +42,11 @@ Description: getNetworkPort registers defaultPort and returns defaultPort if it
Name: isPortOpen
Signatures: "isPortOpen(host string, port string, [timeout int]) bool"
Description: isPortOpen checks if given port is open on host. timeout is optional and defaults to 5 seconds
Description: isPortOpen checks if given TCP port is open on host. timeout is optional and defaults to 5 seconds
Name: isUDPPortOpen
Signatures: "isUDPPortOpen(host string, port string, [timeout int]) bool"
Description: isUDPPortOpen checks if the given UDP port is open on the host. Timeout is optional and defaults to 5 seconds.
Name: ToBytes
Signatures: "ToBytes(...interface{}) []byte"

View File

@ -109,7 +109,7 @@ func initBuiltInFunc(runtime *goja.Runtime) {
Signatures: []string{
"isPortOpen(host string, port string, [timeout int]) bool",
},
Description: "isPortOpen checks if given port is open on host. timeout is optional and defaults to 5 seconds",
Description: "isPortOpen checks if given TCP port is open on host. timeout is optional and defaults to 5 seconds",
FuncDecl: func(host string, port string, timeout ...int) (bool, error) {
timeoutInSec := 5
if len(timeout) > 0 {
@ -124,6 +124,27 @@ func initBuiltInFunc(runtime *goja.Runtime) {
},
})
_ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{
Name: "isUDPPortOpen",
Signatures: []string{
"isUDPPortOpen(host string, port string, [timeout int]) bool",
},
Description: "isUDPPortOpen checks if the given UDP port is open on the host. Timeout is optional and defaults to 5 seconds.",
FuncDecl: func(host string, port string, timeout ...int) (bool, error) {
timeoutInSec := 5
if len(timeout) > 0 {
timeoutInSec = timeout[0]
}
conn, err := net.DialTimeout("udp", net.JoinHostPort(host, port), time.Duration(timeoutInSec)*time.Second)
if err != nil {
return false, err
}
_ = conn.Close()
return true, nil
},
})
_ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{
Name: "ToBytes",
Signatures: []string{