Plugin Packages

Packages

Since the JS doesn’t have all the useful functions to perform operations like on file manipulation or http request (see otto docs for more info), driplane maps and export to the JS environment some Go functions as packages.

File

This package contains functions for manipulating files.

Return

The return value will be a JS object containing 2 fields:

NameTypeDescription
StatusBOOLif true the operation was successful
ErrorSTRINGif status is false it contains the reason of the failure

Functions

PrototypeDescription
file.Move(src string, dest string)Move the file src to the new position dest
file.Copy(src string, dest string)Copy the file src to the position dest
file.Truncate(filename string, size int)set or adjust the file called filename by size bytes
file.Delete(filename string)Remove the file called filename
file.Exists(filename string)Return Status = true if filename exists on disk
file.AppendString(filename string, text string)Append the string text to the file filename

Log

This package contains functions for writing strings on the logs.

Return

It doesn’t have a return value.

Functions

PrototypeDescription
log.Info(format string, …)Write an Info line on the log
log.Error(src string, …)Write an Error line on the log
log.Debug(src string, …)Write a Debug line on the log

Strings

This package contains functions for manipulating strings.

Return

The return value will be a JS object containing 2 fields:

NameTypeDescription
StatusBOOLif true the operation was successful
ErrorSTRINGif status is false it contains the reason of the failure

Functions

PrototypeDescription
strings.StartsWith(str string, substr string)Status = true if str start with substr

Util

This package contains miscellaneous functions.

Return

The return value will be a JS object containing 2 fields:

NameTypeDescription
StatusBOOLif true the operation was successful
ErrorSTRINGif status is false it contains the reason of the failure
ValueSTRINGthis string contains the returned value

Functions

PrototypeDescription
util.Sleep(seconds int)wait for seconds seconds
util.Getenv(name string)get the value of the name environment variables, if it exists, and return it on the Value field of the returned value
util.Md5File(filename string)calculate the MD5 hash of the filename and return it on the Value field
util.Sha1File(filename string)calculate the SHA1 hash of the filename and return it on the Value field
util.Sha256File(filename string)calculate the SHA256 hash of the filename and return it on the Value field
util.Sha512File(filename string)calculate the SHA512 hash of the filename and return it on the Value field

Http

This package contains functions to perform HTTP requests.

Return

The return value will be a JS object containing 4 fields:

NameTypeDescription
StatusBOOLif true the operation was successful
ErrorSTRINGif status is false it contains the reason of the failure
ResponseOBJECTit returns the http.Response object
BodySTRINGit contains the body of the response converted in string

Functions

PrototypeDescription
http.Request(method string, uri string, headers interface{}, data interface{})
http.Get(url string, headers map[string]string)
http.Post(url string, headers map[string]string, data interface{})
http.DownloadFile(filepath string, method string, uri string, headers interface{}, data interface{})
http.UploadFile(filename string, fieldname string, method string, uri string, headers interface{}, data interface{})

Cache

This package contains functions for add and get values from the global cache.

Return

The return value will be a JS object containing the following fields:

NameTypeDescription
StatusBOOLif true the operation was successful
ErrorSTRINGif status is false it contains the reason of the failure
ValueSTRINGif status is true it contains the resulting value

Functions

PrototypeDescription
cache.Put(key string, value string, ttl int64)add the value in the cache using the key key and it will be deleted after ttl seconds
cache.Get(key string)get the value stored in the cache with the key key