Pulse Helper Libraries
Orcasio Pulse provides a set of helper libraries that can be used in the go lambda snippets. The helper libraries can be used without a need to import them.
Note
While we showcase these functions in examples using transformer: |, please note that all of these functions are also applicable within Rule definitions.
Pulse HTTP
The "pulsehttp" library simplifies making HTTP calls from Go Lambda snippets and is built upon the standard Go http library.
Function Signatures
pulsehttp.Get
pulsehttp.Get(url string, header http.Header, body io.Reader, tlsVerify bool) (string, int, error)url: URL for the HTTP GET request.header: HTTP headers to include in the request.body: HTTP body to send with the request.tlsVerify: Indicates whether to verify the TLS certificate.- Returns:
string: HTTP response body.int: HTTP response status code.error: Error object.
-
Example:
transformer: | # golang url := "https://api.example.com/data" headers := make(http.Header) headers.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN") response, statusCode, err := pulsehttp.Get(url, headers, nil, true) if err != nil { pulselog.Error("Error while making GET request: %v", err) } else { pulselog.Info("GET request successful. Status code: %d", statusCode) pulselog.Debug("Response body: %s", response) }
pulsehttp.Post
pulsehttp.Post(url string, header http.Header, body io.Reader, tlsVerify bool) (string, int, error)url: URL for the HTTP POST request.header: HTTP headers to include in the request.body: HTTP body to send with the request.tlsVerify: Indicates whether to verify the TLS certificate.- Returns:
string: HTTP response body.int: HTTP response status code.error: Error object.
-
Example:
transformer: | # golang url := "https://api.example.com/create" headers := make(http.Header) headers.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN") requestBody := []byte(`{"name": "John", "age": 30}`) bodyReader := bytes.NewReader(requestBody) response, statusCode, err := pulsehttp.Post(url, headers, bodyReader, true) if err != nil { pulselog.Error("Error while making POST request: %v", err) } else { pulselog.Info("POST request successful. Status code: %d", statusCode) pulselog.Debug("Response body: %s", response) }
Pulse JSON
The "pulsejson" library provides utilities to parse JSON strings within Go Lambda snippets.
Function Signatures
pulsejson.Get
pulsejson.Get(path string, input any) anypath: JSON path used to retrieve a specific value within the JSON data. The path should begin with one of the supported separator characters:$,.,#, or_, and subsequent keys or indices should also use the same separator.input: JSON data from which to retrieve the value.- Returns:
any: value underpath. If it does not find any value it will return an empty string""
- Example:
pulsejson.Delete
pulsejson.Delete(path string, input any)path: JSON path used to delete a specific value within the JSON data. The path should start with one of the supported separator characters:$,.,#, or_, and subsequent keys or indices should follow the same separator.input: JSON data from which to delete the value.- Example:
pulsejson.Transcode
pulsejson.Transcode(in any, out any)in: JSON to transcode.out: Pointer to the transcoded Map object.- Example:
pulsejson.Print
pulsejson.Print(data any)data: JSON Transcoded Map object to be printed.- Example:
Pulse Log
The "pulselog" library facilitates logging messages from Go Lambda snippets. It provides utilities to interact with the Pulse engine and sensor logger objects, allowing you to write log messages with appropriate log levels.
Function Signatures
pulselog.Trace
pulselog.Trace(format string, v ...interface{})format: Format string for the log message.v: Arguments for the format string.- Example:
pulselog.Debug
pulselog.Debug(format string, v ...interface{})format: Format string for the log message.v: Arguments for the format string.- Example:
pulselog.Info
pulselog.Info(format string, v ...interface{})format: Format string for the log message.v: Arguments for the format string.- Example:
pulselog.Warn
pulselog.Warn(format string, v ...interface{})format: Format string for the log message.v: Arguments for the format string.- Example:
pulselog.Error
pulselog.Error(format string, v ...interface{})format: Format string for the log message.v: Arguments for the format string.- Example:
Pulse Number
The "pulsenum" library facilitates number casting operations from Go Lambda snippets.
Function Signatures
pulsenum.ToInt
pulsenum.ToInt(in any) (int, bool)in: Input object to be casted to an integer.- Returns:
int: Casted integer value.bool: Flag indicating the success of the cast.
- Example:
pulsenum.ToFloat
pulsenum.ToFloat(in any) (float64, bool)in: Input object to be casted to a float64.- Returns:
float64: Casted float64 value.bool: Flag indicating the success of the cast.
- Example:
Pulse String
The "pulsestr" library assists in performing string operations within Go Lambda snippets.
Function Signatures
pulsestr.HasString
pulsestr.HasString(list []string, str string) boollist: List of strings to search within.str: String to search for within the list.- Returns:
bool: Flag indicating whether the string was found in the list.
- Example:
Specific Helper Functions
The are some helper functions that are specific to either transformer or rules.
Transforemer Functions
appendSignals
appendSignals(signals ...(map[string]any))str: New signals that want to be sent to the stream.- Example:
transformer: | #! golang out1 := make(map[string]any) pulsejson.Transcode(signal, &out1) out1["apiVersion"] = "xyz" out2 := make(map[string]any) pulsejson.Transcode(signal, &out2) out2["apiVersion"] = "a123" pulsejson.Delete("spec", signal) // Append signals to the existing signal appendSignals(out1, out2, signal)