server_embedded

command
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 8 Imported by: 0

README

Embedded ChronosOS server

Run the ChronosOS control plane as a library inside your own Go binary, instead of via the chronos serve CLI.

main.go builds a chronosos.Server with:

  • API-key auth (WithAPIKeyAuth) on /api/* routes — health, metrics, and Swagger stay public.
  • RBAC (WithRBAC) — method-based roles once authenticated.
  • Swagger UI (WithSwagger) at /swagger/.

It starts the server and shuts it down gracefully on SIGINT/SIGTERM.

Run

go run ./examples/server_embedded/          # serves on :8420 until Ctrl-C

curl http://localhost:8420/health/ready                         # 200, public
curl -i http://localhost:8420/api/sessions                      # 401, no key
curl -H "X-Api-Key: dev-secret-key" http://localhost:8420/api/sessions  # 200
open  http://localhost:8420/swagger/                            # OpenAPI UI

Test

The test exercises the exact server the example builds in-process via net/http/httptest — no port is bound, so it is CI- and network-safe:

go test ./examples/server_embedded/

Documentation

Overview

Example: server_embedded — running the ChronosOS control plane as a library.

What you'll learn:

  • How to construct a chronosos.Server with chronosos.NewWithOptions
  • How to enable API-key authentication, RBAC, and the Swagger UI
  • How to start the server and shut it down gracefully on SIGINT/SIGTERM

ChronosOS is the HTTP control plane (sessions, traces, events, approvals, metrics). Instead of running the `chronos serve` CLI you can embed the same server inside your own Go binary, wiring it to your storage backend.

This example compiles with no credentials. The Handler() it builds is what the accompanying test exercises in-process with net/http/httptest, so CI never binds a port.

Run:

go run ./examples/server_embedded/          # serves on :8420 until Ctrl-C
curl http://localhost:8420/health/ready
curl -H "X-Api-Key: dev-secret-key" http://localhost:8420/api/sessions
open  http://localhost:8420/swagger/

Jump to

Keyboard shortcuts

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