example

command
v1.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package main demonstrates a complete vatel API server setup. It shows JWT-based auth via vatel/auth, permission-gated endpoints, struct-based controllers with carrier embedding, a WebSocket endpoint with one security context (user, organization) per connection, CORS preflight and graceful shutdown.

The listen address is taken from the ADDR environment variable (default ":8080"). Tokens are HS256 JWTs signed with the JWT_SECRET environment variable; without it a public development key is used.

"go run ./example token [org]" prints a development token for user 100 (alice) in organization org (default 1) with every permission, valid for 24 hours:

TOKEN=$(go run ./example token)
curl -H "Authorization: Bearer $TOKEN" localhost:8080/orders

The order endpoints serve only the orders of the organization of the token: an order of another organization is not found.

WebSocket clients connect to /ws, send the token within 10 seconds and then watch orders of their organization:

{"path": "updateAccessToken", "data": {"mid": "<uuid>", "at": "<token>"}}
{"path": "orders.watch", "data": {"id": 1}}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL