Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AndresGT/GoKit/llms.txt

Use this file to discover all available pages before exploring further.

GoKit is a modular Go toolkit designed to eliminate boilerplate when building APIs with Gin. It packages a structured logger with multiple output targets, JWT access/refresh token management, bcrypt and Argon2id password hashing, and a set of production-ready middlewares — all configurable and ready to drop into your project.

Installation

Add GoKit to your Go module and start using its packages in minutes.

Quickstart

Stand up a secure Gin API with logging, JWT auth, and CORS in under 50 lines.

Logger

Structured logging with console, file, and database writers. Full Gin integration.

Security

Generate and validate JWT access and refresh tokens. Hash passwords with bcrypt or Argon2id.

Middleware

Auth, CORS, Recovery, and Request ID middleware with sensible defaults and full configurability.

Full Setup Guide

See all GoKit modules working together in a complete Gin application.

What’s included

Logger

Seven log levels, colored console output, JSON file writing, async database persistence via GORM, and seamless Gin middleware.

Hash

bcrypt (default) and Argon2id password hashing with automatic algorithm detection on verify and rehash detection.

JWT

HS256-signed access and refresh tokens with configurable expiry, issuer validation, and a full token-pair refresh flow.

Auth Middleware

Per-request JWT validation, configurable skip paths, role-based access control, and custom error handlers.

CORS Middleware

Development (*) and production (origin allowlist) presets, wildcard subdomain matching, and preflight handling.

Recovery Middleware

Panic recovery with stack-trace logging, dev and production presets, and custom recovery handlers.

Getting started

1

Install GoKit

go get github.com/AndresGT/GoKit
2

Configure JWT and the logger

Call jwt.Configure and logger.InitGlobal once at application startup before your router is created.
3

Add middlewares to your Gin router

Attach middleware.DefaultRequestID(), logger.GinMiddleware(), middleware.DefaultCORS(), and middleware.DefaultRecovery() in order.
4

Protect routes and read token data

Use middleware.Auth on protected route groups and middleware.GetUserID / middleware.GetUserRole inside handlers.

Build docs developers (and LLMs) love