import
— no go get
needed.
When you write Go code on Pipedream, you can share data between steps and access environment variables. However, you can’t connect accounts, return HTTP responses, or take advantage of other features available in the Node.js environment at this time.
If you have any feedback on the Go runtime, please let us know in our community.
Adding a Go code step
- Click the + icon to add a new step
- Click “Custom Code”
- In the new step, select the
golang
language runtime in language dropdown
Logging and debugging
You can usefmt.Println
at any time to log information as the script is running.
The output for the fmt.Println
Logs will appear in the Results
section just beneath the code editor.
Don’t forget to import the
fmt
package in order to run fmt.Println
.Copy
Ask AI
Using third party packages
You can use any packages from Go package registry. This includes popular choices such as:net/http
for making HTTP requestsencoding/json
for encoding and decoding JSONdatabase/sql
for reading and writing to SQL databases
import
it in your step’s code:
Copy
Ask AI
Sending files
You can send files stored in the/tmp
directory in an HTTP request:
Copy
Ask AI
Sharing data between steps
A step can accept data from other steps in the same workflow, or pass data downstream to others. This makes your steps even more powerful, you can compose new workflows and reuse steps.Using data from another step
Data from the initial workflow trigger and other steps are available in thepipedream-go
package.
In this example, we’ll pretend this data is coming into our HTTP trigger via POST request.
Copy
Ask AI
Steps
variable from the pd
package. Specifically, this data from the POST request into our workflow is available in the trigger
map.
Copy
Ask AI
Sending data downstream to other steps
To share data for future steps to use, call the Export function from pd package:Copy
Ask AI
pokemon
data is accessible to downstream steps within pd.Steps["code"]["pokemon"]
Not all data types can be stored in the
Steps
data shared between workflow steps.For the best experience, we recommend only exporting structs that can be marshalled into JSON.Using environment variables
You can leverage any environment variables defined in your Pipedream account in a Go step. This is useful for keeping your secrets out of code as well as keeping them flexible to swap API keys without having to update each step individually. To access them, use theos
package.
Copy
Ask AI
Using API key authentication
If a particular service requires you to use an API key, you can pass it via the HTTP request. This proves your identity to the service so you can interact with it:Copy
Ask AI
Making a GET
request
You’ll typically use GET
requests to retrieve data from an API:
Copy
Ask AI
Making a POST
request
Copy
Ask AI
Handling errors
You may need to exit a workflow early, use theos.Exit
to exit the main
function with a specific error code.
Copy
Ask AI
os.Exit
is called. In this example, the exit code 1
will appear in the Results of the step.
File storage
You can also store and read files with Go steps. This means you can upload photos, retrieve datasets, accept files from an HTTP request and more. The/tmp
directory is accessible from your workflow steps for saving and retrieving files.
You have full access to read and write both files in /tmp
.
Writing a file to /tmp
Copy
Ask AI
/tmp/go-logo.svg
holds the official Go logo.
Reading a file from /tmp
You can also open files you have previously stored in the/tmp
directory. Let’s open the go-logo.svg
file.
Copy
Ask AI
/tmp
limitations
The /tmp
directory can store up to of storage. Also the storage may be wiped or may not exist between workflow executions.
To avoid errors, assume that the /tmp
directory is empty between workflow runs.