Awesome
Hatchet: Go SDK Quickstart
This repository contains a simple application which showcases how to use the Hatchet Go SDK to create events and workflows. In ./cmd/server, you'll find a simple echo
server which pushes an event to Hatchet every time it receives a request on /test
. In ./cmd/worker, we create a worker which runs a simple workflow called event-test
whenever the test-called
event is seen.
Getting Started
Prerequisites
This quickstart example requires the following tools to work:
go 1.18+
docker
Get up and running
-
Run
go mod download
to fetch all packages. -
Run
docker compose up
to start the Hatchet instance. This will take a few minutes, as the docker compose services set up the database and generate the required certificates to connect to the Hatchet instance. You can also rundocker compose up -d
to start this in the background. Once you start to see output from theengine
andapi
services, you can move on to the next step. -
You should be able to navigate to localhost:8020 and use the following credentials to log in:
Email: admin@example.com Password: Admin123!!
-
Create a token. You can do this from the dashboard or from the CLI:
From the CLI:
export HATCHET_CLIENT_TOKEN="$(docker compose run --no-deps setup-config /hatchet/hatchet-admin token create --config /hatchet/config --tenant-id 707d0855-80ab-4e1f-a156-f1c4546cbf52 | xargs)"
echo "HATCHET_CLIENT_TOKEN=$HATCHET_CLIENT_TOKEN" > .env
From the dashboard:
- Navigate to the token page and create a token.
- Click the copy to clipboard button and paste into a new file called
.env
in the root of this repository.
- Start the server and worker:
go run ./cmd/server & go run ./cmd/worker
- Run
curl http://localhost:1323/test
to test the endpoint.
You will see events and workflows populated in the Hatchet dashboard:
<img width="1728" alt="image" src="https://github.com/hatchet-dev/hatchet-go-quickstart/assets/25448214/376e4ee8-7233-4a84-85b8-f71ad9e7402e">