Back to Templates

Go standard lib

Unkey with net/http

Written by
diwasrimal
Language
Golang
Unkey with net/http

Unkey Go stdlib authentication example

This simple example shows how you can use Unkey API key authentication with a Go stdlib middleware.

Setup

Clone the example and build

1git clone https://github.com/diwasrimal/unkey-go-stdlib-auth
2cd unkey-go-stdlib-auth
3go build -o server .

Get your unkey root key from https://app.unkey.com/settings/root-keys. Create a new api from https://app.unkey.com/apis and also get its api id. Then create a .env file in the root directory with these variables.

1UNKEY_API_ID=your_api_id
2UNKEY_ROOT_KEY=your_root_key

Try it out

Run the server

1./server

Create a new key for your api. Make a request to server including your api key in the Authorization header.

1curl -X GET localhost:3030 -H 'Authorization: your_api_key'

Protect your API.
Start today.

2500 verifications and 100K successful rate‑limited requests per month. No CC required.