REST framework + OpenAPI SDK generation for the Lethean Go ecosystem
Find a file
Snider d760e77e49 feat(authentik): add header extraction middleware and WithAuthentik option
Add permissive forward-auth middleware that extracts user identity from
X-authentik-* headers when TrustedProxy is enabled. Headers are ignored
when TrustedProxy is false to prevent spoofing from untrusted sources.

- GetUser(c) helper retrieves AuthentikUser from Gin context
- authentikMiddleware splits groups/entitlements on pipe delimiter
- /health and /swagger bypass header extraction
- WithAuthentik option wires middleware into the Engine

Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-20 16:38:13 +00:00
api.go feat: add Swagger UI endpoint with runtime spec serving 2026-02-20 15:56:29 +00:00
api_test.go feat: add Engine with Register, Handler, Serve, and graceful shutdown 2026-02-20 15:46:11 +00:00
authentik.go feat(authentik): add header extraction middleware and WithAuthentik option 2026-02-20 16:38:13 +00:00
authentik_test.go feat(authentik): add header extraction middleware and WithAuthentik option 2026-02-20 16:38:13 +00:00
CLAUDE.md docs: add CLAUDE.md and README.md 2026-02-20 15:57:44 +00:00
go.mod feat: add Swagger UI endpoint with runtime spec serving 2026-02-20 15:56:29 +00:00
go.sum feat: add Swagger UI endpoint with runtime spec serving 2026-02-20 15:56:29 +00:00
group.go feat: add RouteGroup and StreamGroup interfaces 2026-02-20 15:44:58 +00:00
group_test.go feat: add RouteGroup and StreamGroup interfaces 2026-02-20 15:44:58 +00:00
LICENCE chore: scaffold go-api module 2026-02-20 15:42:16 +00:00
middleware.go feat: add bearer auth, request ID, and CORS middleware 2026-02-20 15:49:35 +00:00
middleware_test.go feat: add bearer auth, request ID, and CORS middleware 2026-02-20 15:49:35 +00:00
options.go feat(authentik): add header extraction middleware and WithAuthentik option 2026-02-20 16:38:13 +00:00
README.md docs: add CLAUDE.md and README.md 2026-02-20 15:57:44 +00:00
response.go feat: add response envelope with OK, Fail, Paginated helpers 2026-02-20 15:44:17 +00:00
response_test.go feat: add response envelope with OK, Fail, Paginated helpers 2026-02-20 15:44:17 +00:00
swagger.go feat: add Swagger UI endpoint with runtime spec serving 2026-02-20 15:56:29 +00:00
swagger_test.go feat: add Swagger UI endpoint with runtime spec serving 2026-02-20 15:56:29 +00:00
websocket.go feat: add WebSocket endpoint and channel listing from StreamGroups 2026-02-20 15:53:10 +00:00
websocket_test.go feat: add WebSocket endpoint and channel listing from StreamGroups 2026-02-20 15:53:10 +00:00

go-api

REST framework + OpenAPI SDK generation for the Lethean Go ecosystem.

Overview

go-api provides a Gin-based HTTP engine that subsystems plug into via the RouteGroup interface. Each ecosystem package (go-ml, go-rag, go-agentic, etc.) registers its own route group, and go-api handles the HTTP plumbing, middleware, response envelopes, WebSocket integration, and OpenAPI spec generation.

Quick Start

import api "forge.lthn.ai/core/go-api"

engine, _ := api.New(
    api.WithAddr(":8080"),
    api.WithBearerAuth("my-token"),
    api.WithCORS("*"),
    api.WithRequestID(),
    api.WithSwagger("My API", "Description", "0.1.0"),
)

engine.Register(myRoutes)
engine.Serve(ctx)

Implementing a RouteGroup

type Routes struct{ service *mypackage.Service }

func (r *Routes) Name() string     { return "mypackage" }
func (r *Routes) BasePath() string { return "/v1/mypackage" }

func (r *Routes) RegisterRoutes(rg *gin.RouterGroup) {
    rg.GET("/items", r.ListItems)
    rg.POST("/items", r.CreateItem)
}

func (r *Routes) ListItems(c *gin.Context) {
    items, _ := r.service.List(c.Request.Context())
    c.JSON(200, api.OK(items))
}

Features

  • Response envelopeapi.OK(), api.Fail(), api.Paginated() for consistent JSON responses
  • Middleware — Bearer auth, CORS, request ID generation, panic recovery
  • WebSocketWithWSHandler() mounts any http.Handler at /ws
  • Swagger UIWithSwagger() serves interactive API docs at /swagger/
  • Health check — Built-in GET /health endpoint

Licence

EUPL-1.2