Skip to main content

Overview

This guide covers everything you need to protect your Go API with Unkey, including middleware for the standard library, Gin framework, and Echo framework. What you’ll learn:
  • Quick setup with the Unkey Go SDK
  • Middleware for net/http (standard library)
  • Gin framework integration
  • Echo framework integration
  • Permission-based access control
  • Production-ready patterns

Prerequisites

Quick Start

1

Install the SDK

2

Set up credentials

Get a root key from Settings → Root Keys and set it as an environment variable:
3

Create middleware

Here’s how to verify API keys with standard library net/http:
main.go
4

Run and test

Test it with a valid API key:

Standard Library (net/http)

Production-Ready Middleware

Here’s a complete middleware implementation with context, options, and error handling:
middleware/auth.go
Usage:
main.go

Gin Framework

For the Gin web framework:
main.go

Echo Framework

For the Echo web framework:
main.go

Next Steps

Add rate limiting

Protect your endpoints from abuse

Go SDK Reference

Complete Go SDK documentation

Authorization

Add roles and permissions

Cookbook

More Go recipes and examples