go-codex

module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT

README ΒΆ

go-codex

CI pkg.go.dev Docs

A self-documenting codec library for Go inspired by Haskell's autodocodec. A single Codec[T] value simultaneously describes how to encode, decode, validate, and document a type. Write the codec once β€” derive JSON, YAML, OpenAPI, AsyncAPI, and more from the same definition.

No struct tags. No reflection. No code generation.


πŸ“š Documentation

Full docs danideer.github.io/go-codex
API reference pkg.go.dev/github.com/DaniDeer/go-codex
Examples examples/ β€” 50+ runnable demos
Get started docs/get-started.md

⭐ Flagship example: examples/sensor-service β€” everything go-codex is trying to achieve, in one runnable service: declare codecs, ports, and routes once, and get validation, typed pipelines, and OpenAPI/AsyncAPI specs from the same declarations. MQTT ingest β†’ SQL persist β†’ env-configured alerting β†’ REST time series β†’ auth-guarded file export, every IO hop a protocol-agnostic port, structured as a real project (domain / pipeline / ioports / adapters / observability). go run ./examples/sensor-service


The three layers

go-codex grows with your system. Pick the layer you need β€” each one builds on the last, but none requires the next:

Layer Packages What you declare What you get
1 β€” Codec codex/, format/, validate/, schema/ Shape + constraints Encode, decode, validate, schema β€” once, for free
2 β€” API contract api/rest, api/events, api/reqreply, api/mcp, render/* Routes, channels, tools Typed helpers + OpenAPI / AsyncAPI / MCP spec
3 β€” Application foundation ports/, app/, stream/, forge/, adapters/* IO boundaries + computation contracts Protocol-agnostic ports, supervised lifecycle, governed/signed pipelines β€” bind concrete transports only in main()

All three follow the same pattern: declare β†’ register β†’ handle.

// Layer 1 β€” define a codec once; constraints run on both encode and decode
var userCodec = codex.Struct[User](
    codex.RequiredField("name", codex.String().Refine(validate.NonEmptyString),
        func(u User) string { return u.Name },
        func(u *User, v string) { u.Name = v },
    ),
)

// Layer 2 β€” declare a typed route; same spec drives runtime + OpenAPI
var createUser = rest.NewRoute[CreateUserReq, User]("POST", "/users",
    reqCodec, userCodec,
    rest.RouteMeta{OperationID: "createUser"},
)
handle, _ := createUser.Register(builder)
req, _    := handle.Decode(body)           // validates automatically

// Layer 2 (client) β€” reuse the same route spec on the client side
user, _ := nethttp.Call(ctx, http.DefaultClient, serverURL, handle, req, nil, opts)

// Layer 3 β€” declare an IO boundary with zero transport imports in domain code;
// bind the concrete adapter only in main()
var SensorReadings = codex.Must(ports.NewSourcePort[SensorReading]("sensors", readingCodec,
    ports.PortOptions{}))
var SensorReadingsPattern = ports.EventPattern{Topic: "sensors/{sensorID}/data"}
// main.go:
handle, _ := SensorReadings.PluginEventPattern(SensorReadingsPattern)
SensorReadings.Bind(ctx, mqtt5.SubscribeAdapter(client, handle, opts))

// Layer 3 β€” governed computation with automatic input/output validation
fn := forge.NewFunction[OEEInput, OEEResult]("oee", "1.0.0",
    inputCodec, outputCodec,
    func(in OEEInput) (OEEResult, error) { ... },
    forge.FunctionMeta{Author: "engineering@example.com"},
)
result, _ := fn.Apply(input)

Quick Start

go get github.com/DaniDeer/go-codex@latest
package main

import (
    "fmt"
    "github.com/DaniDeer/go-codex/codex"
    "github.com/DaniDeer/go-codex/format"
    "github.com/DaniDeer/go-codex/validate"
)

type User struct{ Name, Email string }

var UserCodec = codex.Struct[User](
    codex.RequiredField("name",
        codex.String().Refine(validate.NonEmptyString).WithDescription("Display name."),
        func(u User) string { return u.Name },
        func(u *User, v string) { u.Name = v },
    ),
    codex.RequiredField("email",
        codex.String().Refine(validate.Email).WithDescription("Email address."),
        func(u User) string { return u.Email },
        func(u *User, v string) { u.Email = v },
    ),
)

func main() {
    json := format.JSON(UserCodec)

    // Encode
    data, _ := json.Marshal(User{Name: "Alice", Email: "alice@example.com"})
    fmt.Println(string(data))
    // {"email":"alice@example.com","name":"Alice"}

    // Decode + validate
    _, err := json.Unmarshal([]byte(`{"name":"","email":"not-an-email"}`))
    fmt.Println(err)
    // validation errors: [name: expected non-empty string] [email: invalid email]
}

β†’ See docs/get-started.md for the next steps.


What you get

  • One codec β€” four concerns β€” encode, decode, validate, and schema from a single Codec[T] value; no struct tags, no reflection, no code generation
  • Multi-format β€” the same codec reads and writes JSON, YAML, TOML, Gob, and Binary (raw bytes) unchanged
  • Structured errors β€” all failures are concrete types (ValidationErrors, ConstraintError, TypeMismatchError, …); use errors.As or pass directly to log/slog
  • Builtin constraints β€” email, uuid, url, date, date-time, container-image, ranges, lengths, binary file formats (png, jpeg, pdf, zip, …) β€” validated and reflected into OpenAPI/AsyncAPI schema automatically
  • OpenAPI 3.1 + AsyncAPI 3.0 β€” complete specs derived from the same codec; no manual YAML, no drift
  • REST + HTTP client β€” typed Decode/Encode per route; nethttp.Call for typed client calls; both share the same Route definition
  • MQTT events β€” typed subscribe/publish with topic validation, wildcard support, and AsyncAPI spec
  • ZeroMQ β€” typed REQ/REP and PUB/SUB via the same codec declarations as REST and MQTT; AsyncAPI 3.0 with request-reply (api/zeromq); DEALER/ROUTER for concurrent patterns; transport-agnostic FramedSocket interface (no CGO in the adapter)
  • MCP server β€” Tools, Resources, and Prompts follow the same declare β†’ register β†’ handle pattern; codec drives the inputSchema automatically
  • SSE + templ SSR β€” codec-validated event streams; same route serves HTML and JSON via content negotiation
  • Forge pipelines β€” named, versioned, governed KPI computation with SHA-256 contract hash and pipeline YAML spec
  • Ports β€” protocol-agnostic IO boundaries β€” declare a SourcePort/SinkPort/IOPort/LatestPort/ToolPort with zero transport imports in domain code; bind a concrete adapter (MQTT, HTTP, SQL, Redis, file, ZeroMQ, WebSocket, …) only in main()
  • App lifecycle β€” one root context with the observer pre-injected, supervised goroutines with fail-fast semantics, ordered (LIFO) shutdown hooks β€” not a framework, just the choreography main() would otherwise hand-roll

Import paths

go get github.com/DaniDeer/go-codex@latest
What Import path
Core codecs github.com/DaniDeer/go-codex/codex
Format bridges (JSON, YAML, TOML, Gob, Binary) github.com/DaniDeer/go-codex/format
Env-var config loading (FromEnv/FromEnvVar) github.com/DaniDeer/go-codex/config
Built-in constraints github.com/DaniDeer/go-codex/validate
Protocol-agnostic IO ports (Source/Sink/IO/Latest/Tool) github.com/DaniDeer/go-codex/ports
Application lifecycle (context, supervised goroutines, shutdown) github.com/DaniDeer/go-codex/app
REST API builder github.com/DaniDeer/go-codex/api/rest
Event channel builder github.com/DaniDeer/go-codex/api/events
Request/reply builder (async request-reply over pub/sub transports) github.com/DaniDeer/go-codex/api/reqreply
MCP server builder github.com/DaniDeer/go-codex/api/mcp
net/http adapter (server + client) github.com/DaniDeer/go-codex/adapters/nethttp
chi adapter github.com/DaniDeer/go-codex/adapters/chi
Paho MQTT 3.1.1 adapter github.com/DaniDeer/go-codex/adapters/mqtt
MQTT 5.0 adapter (paho.golang) github.com/DaniDeer/go-codex/adapters/mqtt5
ZeroMQ adapter (PUB/SUB, REQ/REP, DEALER/ROUTER) github.com/DaniDeer/go-codex/adapters/zeromq
SQL adapter (goose migrations + codec validation) github.com/DaniDeer/go-codex/adapters/sql
Redis adapter (typed cache) github.com/DaniDeer/go-codex/adapters/redis
WebSocket adapter (server + client, duplex sessions) github.com/DaniDeer/go-codex/adapters/websocket
mark3labs/mcp-go adapter github.com/DaniDeer/go-codex/adapters/mcpgo
templ SSR format plug-in github.com/DaniDeer/go-codex/adapters/templ
OpenAPI 3.1 renderer github.com/DaniDeer/go-codex/render/openapi
AsyncAPI 3.0 renderer (2.6 also supported) github.com/DaniDeer/go-codex/render/asyncapi/v3
JSON Schema renderer github.com/DaniDeer/go-codex/render/jsonschema
Forge pipeline YAML renderer github.com/DaniDeer/go-codex/render/pipeline
Stream topology YAML renderer github.com/DaniDeer/go-codex/render/stream
Forge pipelines (governed, batch) github.com/DaniDeer/go-codex/forge
Reactive stream pipelines github.com/DaniDeer/go-codex/stream
HTTP route descriptors github.com/DaniDeer/go-codex/route
Schema model github.com/DaniDeer/go-codex/schema
Observer interfaces github.com/DaniDeer/go-codex/stats

Go library as contract

Codecs are plain Go values β€” put them in a shared package. The Go compiler enforces the contract: a field rename breaks both the server and the client at compile time.

examples/adapters-nethttp-client/contract/  ← shared Route specs, codecs, types
examples/adapters-mqtt-contract/contract/   ← shared Channel specs, codecs, types
examples/gob-contract/contract/             ← shared Gob format contract

β†’ docs/concepts/codec-as-contract.md


Project Structure

β†’ Full annotated directory tree in the docs, or browse docs/reference/project-structure.md in the repo.

Key top-level directories:

codex/       β€” ⭐ PUBLIC API: Codec[T], primitives, struct, union, slice, constraints
format/      β€” format bridges: JSON, YAML, TOML, Gob, Binary, embedded formats
config/      β€” standalone env-var config loading (FromEnv, FromEnvVar) β€” no Pattern, no adapter
ports/       β€” protocol-agnostic IO ports: SourcePort, SinkPort, IOPort, LatestPort, ToolPort, DuplexPort
app/         β€” application lifecycle: context + observer, supervised goroutines, shutdown hooks
api/         β€” transport-agnostic API builders (rest/, events/, reqreply/, mcp/)
adapters/    β€” transport adapters (nethttp, chi, mqtt, mqtt5, zeromq, sql, redis, websocket, mcpgo, templ, file)
forge/       β€” governed KPI computation pipelines (synchronous, batch, signed, spec-generating)
stream/      β€” reactive stream pipelines: From, Apply, Filter, Tap, Buffer, Merge, Drain over chan T
render/      β€” spec renderers (openapi/, asyncapi/v2, asyncapi/v3, jsonschema/, pipeline/, stream/)
validate/    β€” reusable constraints (Email, UUID, URL, ranges, MQTT topics, …)
stats/       β€” observer interfaces (ValidationObserver β†’ SQLObserver, CacheObserver, LoggingObserver, NewFanout)
schema/      β€” schema model (pure data, zero dependencies)
route/       β€” HTTP route descriptors + shared security-scheme vocabulary (OpenAPI + AsyncAPI)
examples/    β€” 50+ runnable demos (not importable by library packages)

Directories ΒΆ

Path Synopsis
adapters
chi
Package chi adapts api/rest route handles to github.com/go-chi/chi/v5 routers.
Package chi adapts api/rest route handles to github.com/go-chi/chi/v5 routers.
file
Package file provides protocol-agnostic file IO adapter bindings for the ports package.
Package file provides protocol-agnostic file IO adapter bindings for the ports package.
mcpgo
Package mcpgo adapts api/mcp handles to github.com/mark3labs/mcp-go servers.
Package mcpgo adapts api/mcp handles to github.com/mark3labs/mcp-go servers.
mqtt
Package mqtt adapts api/events channel handles to [Paho MQTT] callbacks.
Package mqtt adapts api/events channel handles to [Paho MQTT] callbacks.
mqtt5
Package mqtt5 provides codec-backed adapters for MQTT 5.0 using the github.com/eclipse/paho.golang library.
Package mqtt5 provides codec-backed adapters for MQTT 5.0 using the github.com/eclipse/paho.golang library.
nethttp
Package nethttp adapts api/rest route handles to net/http handlers.
Package nethttp adapts api/rest route handles to net/http handlers.
openai
Package openai implements ports.IOAdapter against any OpenAI-compatible Chat Completions endpoint (OpenAI itself, Azure OpenAI, Ollama, vLLM, LM Studio, Groq, and others that speak the same wire format).
Package openai implements ports.IOAdapter against any OpenAI-compatible Chat Completions endpoint (OpenAI itself, Azure OpenAI, Ollama, vLLM, LM Studio, Groq, and others that speak the same wire format).
redis
Package redis provides a typed cache boundary for go-codex pipelines, backed by any server speaking the Redis protocol.
Package redis provides a typed cache boundary for go-codex pipelines, backed by any server speaking the Redis protocol.
sql
Package sql provides protocol-agnostic SQL adapter bindings for the ports package.
Package sql provides protocol-agnostic SQL adapter bindings for the ports package.
templ
Package templ provides a format.Format factory that renders a github.com/a-h/templ component as a text/html response.
Package templ provides a format.Format factory that renders a github.com/a-h/templ component as a text/html response.
websocket
Package websocket provides server-side WebSocket adapters for go-codex ports: typed, codec-validated frame streams over persistent bidirectional connections.
Package websocket provides server-side WebSocket adapters for go-codex ports: typed, codec-validated frame streams over persistent bidirectional connections.
api
events
Package events provides a transport-agnostic event channel builder for go-codex.
Package events provides a transport-agnostic event channel builder for go-codex.
internal
Package internal provides shared helpers used by api/rest and api/events.
Package internal provides shared helpers used by api/rest and api/events.
llm
Package llm provides a transport-agnostic declaration for an LLM completion contract: a system prompt plus typed input/output codecs.
Package llm provides a transport-agnostic declaration for an LLM completion contract: a system prompt plus typed input/output codecs.
mcp
Package mcp provides a transport-agnostic MCP server builder for go-codex.
Package mcp provides a transport-agnostic MCP server builder for go-codex.
reqreply
Package reqreply provides a transport-agnostic request-reply API layer for async transports (ZeroMQ, MQTT 5, AMQP RPC, etc.).
Package reqreply provides a transport-agnostic request-reply API layer for async transports (ZeroMQ, MQTT 5, AMQP RPC, etc.).
rest
Package rest provides a transport-agnostic REST API builder for go-codex.
Package rest provides a transport-agnostic REST API builder for go-codex.
Package app is a minimal application lifecycle manager for go-codex services: one root context with the observer pre-injected, supervised goroutines with fail-fast semantics, and ordered (LIFO) shutdown hooks.
Package app is a minimal application lifecycle manager for go-codex services: one root context with the observer pre-injected, supervised goroutines with fail-fast semantics, and ordered (LIFO) shutdown hooks.
Package codex is the public API for go-codex: a self-documenting codec library for Go.
Package codex is the public API for go-codex: a self-documenting codec library for Go.
Package config loads typed values from OS environment variables using schema-driven coercion.
Package config loads typed values from OS environment variables using schema-driven coercion.
examples
adapters-chi command
Package adapters-chi demonstrates the three-layer codec pipeline pattern using the chi router.
Package adapters-chi demonstrates the three-layer codec pipeline pattern using the chi router.
adapters-chi-security command
Package adapters-chi-security demonstrates authentication and authorization for REST APIs built with go-codex and the chi router adapter.
Package adapters-chi-security demonstrates authentication and authorization for REST APIs built with go-codex and the chi router adapter.
adapters-mcp command
Package main demonstrates the go-codex MCP server adapter.
Package main demonstrates the go-codex MCP server adapter.
adapters-mqtt command
Package adapters-mqtt demonstrates the three-layer codec pipeline pattern for event-driven / MQTT applications.
Package adapters-mqtt demonstrates the three-layer codec pipeline pattern for event-driven / MQTT applications.
adapters-mqtt-contract command
Package adapters-mqtt-contract demonstrates the "codec-as-contract" pattern for MQTT event-driven services.
Package adapters-mqtt-contract demonstrates the "codec-as-contract" pattern for MQTT event-driven services.
adapters-mqtt-contract/contract
Package contract is the shared API contract between producer and consumer services.
Package contract is the shared API contract between producer and consumer services.
adapters-mqtt-security command
Package adapters-mqtt-security demonstrates SecurityFunc-based authentication for MQTT subscribe channels built with go-codex.
Package adapters-mqtt-security demonstrates SecurityFunc-based authentication for MQTT subscribe channels built with go-codex.
adapters-mqtt5 command
Package adapters-mqtt5 demonstrates the MQTT 5.0 adapter and its features that are specific to MQTT 5.0, compared to the MQTT 3.1.1 adapter:
Package adapters-mqtt5 demonstrates the MQTT 5.0 adapter and its features that are specific to MQTT 5.0, compared to the MQTT 3.1.1 adapter:
adapters-nethttp command
Package adapters-nethttp demonstrates the three-layer codec pipeline pattern where every boundary β€” HTTP request, database, HTTP response β€” is modelled as a codec contract.
Package adapters-nethttp demonstrates the three-layer codec pipeline pattern where every boundary β€” HTTP request, database, HTTP response β€” is modelled as a codec contract.
adapters-nethttp-client command
Package adapters-nethttp-client demonstrates the HTTP client-side adapter.
Package adapters-nethttp-client demonstrates the HTTP client-side adapter.
adapters-nethttp-client/contract
Package contract defines the shared HTTP API contract for the adapters-nethttp-client example.
Package contract defines the shared HTTP API contract for the adapters-nethttp-client example.
adapters-nethttp-security command
Package adapters-nethttp-security demonstrates authentication and authorization for REST APIs built with go-codex and the net/http adapter.
Package adapters-nethttp-security demonstrates authentication and authorization for REST APIs built with go-codex and the net/http adapter.
adapters-openai command
Package adapters-openai demonstrates go-codex CALLING an LLM β€” the other direction from examples/adapters-mcp (which lets an LLM call go-codex).
Package adapters-openai demonstrates go-codex CALLING an LLM β€” the other direction from examples/adapters-mcp (which lets an LLM call go-codex).
adapters-sse command
Package adapters-sse demonstrates Server-Sent Events (SSE) using the go-codex adapters/nethttp and adapters/chi adapters.
Package adapters-sse demonstrates Server-Sent Events (SSE) using the go-codex adapters/nethttp and adapters/chi adapters.
adapters-streaming-sse-templ command
Package main demonstrates two templ + go-codex patterns on a single server:
Package main demonstrates two templ + go-codex patterns on a single server:
adapters-templ command
Package main demonstrates how go-codex fits into a templ-based rendering pipeline using the adapters/templ format plug-in.
Package main demonstrates how go-codex fits into a templ-based rendering pipeline using the adapters/templ format plug-in.
adapters-zeromq command
Package adapters-zeromq demonstrates the ZeroMQ PUB/SUB adapter using go-codex's api/events channel declarations.
Package adapters-zeromq demonstrates the ZeroMQ PUB/SUB adapter using go-codex's api/events channel declarations.
adapters-zeromq-dealer-router command
Package adapters-zeromq-dealer-router demonstrates the ZeroMQ DEALER/ROUTER adapter pattern using go-codex's api/rest route declarations.
Package adapters-zeromq-dealer-router demonstrates the ZeroMQ DEALER/ROUTER adapter pattern using go-codex's api/rest route declarations.
adapters-zeromq-reqrep command
Package adapters-zeromq-reqrep demonstrates the ZeroMQ REQ/REP adapter using go-codex's api/rest route declarations.
Package adapters-zeromq-reqrep demonstrates the ZeroMQ REQ/REP adapter using go-codex's api/rest route declarations.
api-events command
Package api-events demonstrates the api/events builder: define channels with codec-backed payload types, get typed Decode/Encode helpers, and generate a full AsyncAPI 3.0 spec β€” all without importing any messaging library.
Package api-events demonstrates the api/events builder: define channels with codec-backed payload types, get typed Decode/Encode helpers, and generate a full AsyncAPI 3.0 spec β€” all without importing any messaging library.
api-rest command
Package api-rest demonstrates the api/rest builder: define routes with codec-backed types, get typed Decode/Encode helpers, and generate a full OpenAPI 3.1 spec β€” all without importing net/http or any HTTP framework.
Package api-rest demonstrates the api/rest builder: define routes with codec-backed types, get typed Decode/Encode helpers, and generate a full OpenAPI 3.1 spec β€” all without importing net/http or any HTTP framework.
cli-config command
Package main demonstrates using go-codex for CLI tool configuration: loading a TOML config file and overlaying environment variable overrides.
Package main demonstrates using go-codex for CLI tool configuration: loading a TOML config file and overlaying environment variable overrides.
codec-mapping command
Package main demonstrates three patterns for reusing and transforming codecs without repeating constraint definitions.
Package main demonstrates three patterns for reusing and transforming codecs without repeating constraint definitions.
construction command
decode-errors command
Package decode-errors demonstrates multi-field validation errors in go-codex.
Package decode-errors demonstrates multi-field validation errors in go-codex.
enum-union-sum command
Package enum-union-sum shows how go-codex handles the three key type-modeling patterns from Go: iota enums, union types, and sum types (discriminated unions).
Package enum-union-sum shows how go-codex handles the three key type-modeling patterns from Go: iota enums, union types, and sum types (discriminated unions).
env-config command
Package main demonstrates config.FromEnv: loading application configuration exclusively from environment variables using the codec as the single source of truth for field names, types, validations, and documentation.
Package main demonstrates config.FromEnv: loading application configuration exclusively from environment variables using the codec as the single source of truth for field names, types, validations, and documentation.
error-types command
Package error-types demonstrates every structured error type in go-codex.
Package error-types demonstrates every structured error type in go-codex.
event-driven command
Package event-driven demonstrates generating a full AsyncAPI 3.0 document from channel descriptors and Codec-derived schemas using the render/asyncapi/v3 package.
Package event-driven demonstrates generating a full AsyncAPI 3.0 document from channel descriptors and Codec-derived schemas using the render/asyncapi/v3 package.
events-nested-binary command
Package events-nested-binary demonstrates the Phase 2 "one struct, one call" merge-field convenience for MQTT/event channels (api/events + adapters/mqtt5) β€” the pub/sub mirror of examples/rest-nested-binary.
Package events-nested-binary demonstrates the Phase 2 "one struct, one call" merge-field convenience for MQTT/event channels (api/events + adapters/mqtt5) β€” the pub/sub mirror of examples/rest-nested-binary.
file-io command
Package main demonstrates ports.File: the declarative typed file descriptor for reading, writing, and updating files with full codec validation.
Package main demonstrates ports.File: the declarative typed file descriptor for reading, writing, and updating files with full codec validation.
file-patch-sink command
Package main demonstrates file.DrainPatchAdapter and file.DrainPatchEncodedAdapter: ports.SinkPort-bound sink adapters that apply each stream item as a PARTIAL update to an existing typed file, instead of the whole-file overwrite file.DrainWriteFileAdapter performs.
Package main demonstrates file.DrainPatchAdapter and file.DrainPatchEncodedAdapter: ports.SinkPort-bound sink adapters that apply each stream item as a PARTIAL update to an existing typed file, instead of the whole-file overwrite file.DrainWriteFileAdapter performs.
flat-key-patch command
Package main demonstrates flat dotted-key JSON patching with go-codex.
Package main demonstrates flat dotted-key JSON patching with go-codex.
forge-collection command
Package forge-collection demonstrates forge collection operations applied to a batch of MQTT-style sensor temperature readings.
Package forge-collection demonstrates forge collection operations applied to a batch of MQTT-style sensor temperature readings.
forge-oee command
Package main demonstrates the forge package for signed, governed KPI computation.
Package main demonstrates the forge package for signed, governed KPI computation.
formats command
Package formats demonstrates the builtin format constraints in validate/, as well as WithExample, WithDeprecated, and the Duration codec.
Package formats demonstrates the builtin format constraints in validate/, as well as WithExample, WithDeprecated, and the Duration codec.
gob-contract command
Package gob-contract demonstrates the "Go library as contract" pattern.
Package gob-contract demonstrates the "Go library as contract" pattern.
gob-contract/contract
Package contract is the shared API contract between producer and consumer services.
Package contract is the shared API contract between producer and consumer services.
html-sanitize command
Package main demonstrates where go-codex shines in a comment moderation use case: a single codec definition simultaneously escapes HTML, enforces length limits, and documents the schema β€” all derived from one value.
Package main demonstrates where go-codex shines in a comment moderation use case: a single codec definition simultaneously escapes HTML, enforces length limits, and documents the schema β€” all derived from one value.
http-trace-span-propagation command
Package http-trace-span-propagation demonstrates trace span propagation across HTTP, forge, and file I/O layers using the observer pattern.
Package http-trace-span-propagation demonstrates trace span propagation across HTTP, forge, and file I/O layers using the observer pattern.
multiformat command
oee-chain command
Package oee-chain demonstrates the three-layer go-codex architecture end-to-end:
Package oee-chain demonstrates the three-layer go-codex architecture end-to-end:
openapi command
Package openapi demonstrates generating an OpenAPI components/schemas section from Codec definitions using the render/openapi package.
Package openapi demonstrates generating an OpenAPI components/schemas section from Codec definitions using the render/openapi package.
order command
pattern-custom-format command
Package pattern-custom-format demonstrates ports.Pattern's CustomFormat escape hatch: FilePattern, CachePattern, and SocketPattern are normally locked to FileFormatKind{JSON, YAML, TOML} β€” CustomFormat lets a port declare ANY format.Format[T] instead (Gob, raw binary/PNG, or any custom marshal/unmarshal), closing the gap without waiting for go-codex to add a new enum value for every future wire format.
Package pattern-custom-format demonstrates ports.Pattern's CustomFormat escape hatch: FilePattern, CachePattern, and SocketPattern are normally locked to FileFormatKind{JSON, YAML, TOML} β€” CustomFormat lets a port declare ANY format.Format[T] instead (Gob, raw binary/PNG, or any custom marshal/unmarshal), closing the gap without waiting for go-codex to add a new enum value for every future wire format.
pipeline-segmentation command
Package pipeline_segmentation demonstrates PipePort[T] as a computation pipeline stage boundary β€” the primary use case.
Package pipeline_segmentation demonstrates PipePort[T] as a computation pipeline stage boundary β€” the primary use case.
png-upload command
Package png-upload demonstrates how to define REST routes for PNG binary transfer using go-codex:
Package png-upload demonstrates how to define REST routes for PNG binary transfer using go-codex:
ports-plain-go command
Package ports-plain-go demonstrates that ports.SourcePort, ports.SinkPort, and ports.ToolPort can be used with ZERO forge/gstream composition β€” plain idiomatic Go is a first-class consumption style, not a fallback.
Package ports-plain-go demonstrates that ports.SourcePort, ports.SinkPort, and ports.ToolPort can be used with ZERO forge/gstream composition β€” plain idiomatic Go is a first-class consumption style, not a fallback.
redis-cache command
Package redis-cache demonstrates the typed cache boundary of adapters/redis: an IOPort declared with a CachePattern, a read-through GetAdapter, a write-through SetAdapter, the standalone Get/Set plain functions (no ports.IOAdapter, no stream β€” the non-pipeline entrypoint GetAdapter/SetAdapter delegate to), a per-key-variable codec (CacheKeyParam) rejecting a malformed key var, the Seed warm-restart helper, and the standalone ports.NewCache constructor (no port/pipeline involved).
Package redis-cache demonstrates the typed cache boundary of adapters/redis: an IOPort declared with a CachePattern, a read-through GetAdapter, a write-through SetAdapter, the standalone Get/Set plain functions (no ports.IOAdapter, no stream β€” the non-pipeline entrypoint GetAdapter/SetAdapter delegate to), a per-key-variable codec (CacheKeyParam) rejecting a malformed key var, the Seed warm-restart helper, and the standalone ports.NewCache constructor (no port/pipeline involved).
rest-api command
Package rest-api demonstrates generating a full OpenAPI 3.1 document from route descriptors and Codec-derived schemas using the render/openapi package.
Package rest-api demonstrates generating a full OpenAPI 3.1 document from route descriptors and Codec-derived schemas using the render/openapi package.
rest-nested-binary command
Package rest-nested-binary demonstrates two extensions to the merge-field "one struct, one call" pattern that are easy to assume DON'T work without checking:
Package rest-nested-binary demonstrates two extensions to the merge-field "one struct, one call" pattern that are easy to assume DON'T work without checking:
sensor-service command
Command sensor-service is the go-codex flagship example: a small but complete sensor-readings service structured as a real project, with each concern in its own package:
Command sensor-service is the go-codex flagship example: a small but complete sensor-readings service structured as a real project, with each concern in its own package:
sensor-service/adapters
Package adapters holds the sensor service's infrastructure edge: the mock MQTT client used for the demo, the SQL-backed ReadingStore, and the HTTP handler factories.
Package adapters holds the sensor service's infrastructure edge: the mock MQTT client used for the demo, the SQL-backed ReadingStore, and the HTTP handler factories.
sensor-service/domain
Package domain is Layer 1 + Layer 2 of the sensor service: models, codecs, and pure business rules.
Package domain is Layer 1 + Layer 2 of the sensor service: models, codecs, and pure business rules.
sensor-service/ioports
Package ioports declares every IO boundary of the sensor service as a protocol-agnostic port or route β€” the service's complete IO surface, readable as a compact spec, with ZERO adapter imports.
Package ioports declares every IO boundary of the sensor service as a protocol-agnostic port or route β€” the service's complete IO surface, readable as a compact spec, with ZERO adapter imports.
sensor-service/observability
Package observability holds the cross-cutting observer for the sensor service.
Package observability holds the cross-cutting observer for the sensor service.
sensor-service/pipeline
Package pipeline is the sensor service's business logic layer: pure mapping functions and the stream topology.
Package pipeline is the sensor service's business logic layer: pure mapping functions and the stream topology.
shape command
stats-observer command
Package stats-observer demonstrates how to use stats.ValidationObserver and stats.ReportErrors with codecs directly β€” without any HTTP or MQTT adapter.
Package stats-observer demonstrates how to use stats.ValidationObserver and stats.ReportErrors with codecs directly β€” without any HTTP or MQTT adapter.
stream-oee command
Package stream-oee demonstrates how to govern OEE computation with forge and bridge it to a reactive machine event stream using the stream package.
Package stream-oee demonstrates how to govern OEE computation with forge and bridge it to a reactive machine event stream using the stream package.
stream-pipeline command
Package stream-pipeline demonstrates the go-codex stream package across ten sections, each showcasing a different group of operators.
Package stream-pipeline demonstrates the go-codex stream package across ten sections, each showcasing a different group of operators.
validate command
Package main shows how to use Codec.Validate and Format.Validate for explicit bidirectional validation.
Package main shows how to use Codec.Validate and Format.Validate for explicit bidirectional validation.
websocket-client command
Package websocket-client demonstrates websocket Phase 2: a CLIENT-side DialDuplexAdapter connecting one go-codex process to another over a real WebSocket connection, plus AsyncAPI spec generation for the socket.
Package websocket-client demonstrates websocket Phase 2: a CLIENT-side DialDuplexAdapter connecting one go-codex process to another over a real WebSocket connection, plus AsyncAPI spec generation for the socket.
websocket-duplex command
Package websocket-duplex demonstrates the DuplexPort β€” the sixth port type β€” served over a real WebSocket endpoint (adapters/websocket):
Package websocket-duplex demonstrates the DuplexPort β€” the sixth port type β€” served over a real WebSocket endpoint (adapters/websocket):
Package forge provides governed, self-documenting KPI computation functions.
Package forge provides governed, self-documenting KPI computation functions.
Package format bridges Codec[T] to concrete serialization formats.
Package format bridges Codec[T] to concrete serialization formats.
internal
templatematch
Package templatematch is the shared, module-internal core for matching a concrete path/topic string against a "{varName}"-style template and extracting the variable values β€” the inverse of building a concrete path/topic FROM a template + a vars map (that direction is handled per package, e.g.
Package templatematch is the shared, module-internal core for matching a concrete path/topic string against a "{varName}"-style template and extracting the variable values β€” the inverse of building a concrete path/topic FROM a template + a vars map (that direction is handled per package, e.g.
Package ports provides protocol-agnostic IO enforcement points for go-codex stream pipelines.
Package ports provides protocol-agnostic IO enforcement points for go-codex stream pipelines.
render
asyncapi/v2
Package v2 renders schema.Schema values as an AsyncAPI 2.6 document.
Package v2 renders schema.Schema values as an AsyncAPI 2.6 document.
asyncapi/v3
Package v3 renders schema.Schema values and route.SecurityScheme definitions as an AsyncAPI 3.0 document.
Package v3 renders schema.Schema values and route.SecurityScheme definitions as an AsyncAPI 3.0 document.
internal/schemarender
Package schemarender converts schema.Schema values to [map[string]any] objects suitable for marshalling into OpenAPI or AsyncAPI documents.
Package schemarender converts schema.Schema values to [map[string]any] objects suitable for marshalling into OpenAPI or AsyncAPI documents.
jsonschema
Package jsonschema renders schema.Schema values to plain JSON Schema compatible json.RawMessage.
Package jsonschema renders schema.Schema values to plain JSON Schema compatible json.RawMessage.
openaitools
Package openaitools renders existing go-codex tool/call declarations into the OpenAI "tools" array JSON shape used by Chat Completions/Responses API function calling (and by extension, most OpenAI-compatible providers and client frameworks such as LangChain that accept the same convention).
Package openaitools renders existing go-codex tool/call declarations into the OpenAI "tools" array JSON shape used by Chat Completions/Responses API function calling (and by extension, most OpenAI-compatible providers and client frameworks such as LangChain that accept the same convention).
openapi
Package openapi renders schema.Schema values as OpenAPI 3.x schema objects.
Package openapi renders schema.Schema values as OpenAPI 3.x schema objects.
pipeline
Package pipeline renders a forge.PipelineSpec as a YAML document.
Package pipeline renders a forge.PipelineSpec as a YAML document.
stream
Package stream renders a stream.TopologySpec as a human-readable YAML stream topology document.
Package stream renders a stream.TopologySpec as a human-readable YAML stream topology document.
Package route holds spec descriptors shared by the OpenAPI and AsyncAPI renderers: HTTP operation shapes and the security-scheme vocabulary.
Package route holds spec descriptors shared by the OpenAPI and AsyncAPI renderers: HTTP operation shapes and the security-scheme vocabulary.
Package schema defines the pure data model for describing value shapes.
Package schema defines the pure data model for describing value shapes.
Package stats defines the Observer interface for codec and adapter lifecycle events.
Package stats defines the Observer interface for codec and adapter lifecycle events.
Package stream provides a declarative reactive pipeline for go-codex, bridging push-based transport adapters (MQTT, ZeroMQ) with governed forge.Function computations over typed Go channels.
Package stream provides a declarative reactive pipeline for go-codex, bridging push-based transport adapters (MQTT, ZeroMQ) with governed forge.Function computations over typed Go channels.
Package validate provides reusable codex.Constraint values for common validation rules.
Package validate provides reusable codex.Constraint values for common validation rules.

Jump to

Keyboard shortcuts

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