0. Prerequisites
- flyctl - The fly.io CLI
1. Create a new project
Let’s create a new folder calledflyio-go
and initialize a new project.
2. Creating the main function
In this example we will show how to receive a webhook from QStash and verify the signature using the popular golang-jwt/jwt library. First, let’s import everything we need:main.go
. Ignore the verify
function for now. We will add that
next. In the handler we will prepare all necessary variables that we need for
verification. This includes the signature and the signing keys. Then we try to
verify the request using the current signing key and if that fails we will try
the next one. If the signature could be verified, we can start processing the
request.
verify
function will handle verification of the JWT,
that includes claims about the request. See
here.
3. Create app on fly.io
Login withflyctl
and
then flyctl launch
the new app. This will create the necessary fly.toml
for
us. It will ask you a bunch of questions. I chose all defaults here except for
the last question. We do not want to deploy just yet.
4. Set Environment Variables
Get your current and next signing key from the Upstash Console Then set them usingflyctl secrets set ...
5. Deploy the app
Fly.io made this step really simple. Justflyctl deploy
and enjoy.