go-codex

module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 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/ β€” 35+ runnable demos
Get started docs/get-started.md

The three layers

go-codex grows with your system. Use only what you need:

Layer Package What you declare What you get
1 β€” Codec codex/ Shape + constraints Encode, decode, validate, schema β€” once, for free
2 β€” API contract api/rest, api/events, api/mcp Routes and channels Typed helpers + OpenAPI / AsyncAPI / MCP spec
3 β€” Pipeline forge/ Computation contract Governed, signed, self-documenting KPI functions

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 β€” 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, and Gob 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, ranges, lengths β€” 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
  • 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

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) github.com/DaniDeer/go-codex/format
Built-in constraints github.com/DaniDeer/go-codex/validate
REST API builder github.com/DaniDeer/go-codex/api/rest
Event channel builder github.com/DaniDeer/go-codex/api/events
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 adapter github.com/DaniDeer/go-codex/adapters/mqtt
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 github.com/DaniDeer/go-codex/render/asyncapi/v3
Forge pipelines github.com/DaniDeer/go-codex/forge
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

go-codex/
β”œβ”€β”€ go.mod
β”œβ”€β”€ README.md

β”œβ”€β”€ codex/                  # ⭐ PUBLIC API: codecs, primitives, struct, union, slice
β”‚   β”œβ”€β”€ codec.go            # Codec[T], WithDescription, WithTitle, WithExample, WithDeprecated, Validate, New
β”‚   β”œβ”€β”€ either.go           # Either[A,B] type, Either2 codec
β”‚   β”œβ”€β”€ errors.go           # ValidationError, ValidationErrors, EitherError
β”‚   β”œβ”€β”€ map.go              # MapCodecSafe, MapCodecValidated, Downcast
β”‚   β”œβ”€β”€ must.go             # Must[T] β€” generic panic-on-error helper
β”‚   β”œβ”€β”€ nullable.go         # Nullable[T]
β”‚   β”œβ”€β”€ object.go           # Field[T,F], RequiredField, OptionalField, DefaultField, Struct[T]
β”‚   β”œβ”€β”€ primitives.go       # Int, Int32, Int64, Uint, Uint64, Float32, Float64, String, Bool, Bytes, Any, Pure
β”‚   β”œβ”€β”€ refine.go           # Constraint[T], Refine, RefineFunc, Eq (Constraint.Schema for schema reflection)
β”‚   β”œβ”€β”€ slice.go            # SliceOf[T]
β”‚   β”œβ”€β”€ stringmap.go        # StringMap[V], Map[K, V]
β”‚   β”œβ”€β”€ time.go             # Time(), Date(), Duration()
β”‚   └── union.go            # TaggedUnion[T], UntaggedUnion[T], UntaggedVariant[T]
β”‚
β”œβ”€β”€ format/                 # format bridges: JSON, YAML, TOML, Gob, streaming
β”‚   └── format.go           # Format[T], JSON(), YAML(), TOML(), Gob(), New(), NewTyped(), NewStreamed(), FromEnv()
β”‚
β”œβ”€β”€ route/                  # HTTP route descriptors (no renderer logic)
β”‚   └── route.go            # Route, Param, Body, Response, SecurityScheme, SecurityRequirement
β”‚
β”œβ”€β”€ api/                    # transport-agnostic API builders
β”‚   β”œβ”€β”€ internal/           # shared helpers (not public API)
β”‚   β”‚   └── template.go     # ParseTemplateVars, BuildFromTemplate, StripTemplateVars
β”‚   β”œβ”€β”€ rest/               # REST API builder: typed Decode/Encode + OpenAPI spec
β”‚   β”‚   └── builder.go      # Builder, Route[Req,Resp]/NewRoute, SSERoute[Req,Event]/NewSSERoute,
β”‚   β”‚                       #   RouteHandle (Decode, Encode, EncodeRequest, DecodeResponse, ClientHandle),
β”‚   β”‚                       #   SSERouteHandle, BuildPath, AddServer, AddSchema, AddSecurityScheme,
β”‚   β”‚                       #   AddGlobalSecurity, PathParam, QueryParam, CookieParam, HeaderParam,
β”‚   β”‚                       #   ResponseHeaderParam, ResponseCookieParam, RouteMeta, SecurityScheme
β”‚   β”œβ”€β”€ events/             # Event channel builder: typed Decode/Encode + AsyncAPI spec
β”‚   β”‚   └── builder.go      # Builder, Channel[T]/NewChannel, ChannelHandle, BuildTopic,
β”‚   β”‚                       #   AddServer, AddSchema, AddSecurityScheme, AddGlobalSecurity,
β”‚   β”‚                       #   TopicParam, ChannelMeta, Subscribe, Publish, SecurityScheme
β”‚   └── mcp/                # MCP server builder: Tools, Resources, Prompts
β”‚       β”œβ”€β”€ builder.go      # Builder, NewTool[In,Out], NewResource[T], NewPrompt,
β”‚       β”‚                   #   ToolHandle, ResourceHandle, PromptHandle, MCPSpec
β”‚       └── errors.go       # ToolInputError, ToolOutputError, ResourceEncodeError,
β”‚                           #   ResourceParamError, MissingResourceVarError, PromptArgError, …
β”‚
β”œβ”€β”€ adapters/               # transport-specific adapters
β”‚   β”œβ”€β”€ nethttp/            # net/http adapter β€” server + client
β”‚   β”‚   β”œβ”€β”€ adapter.go      # Handler, Register, SSEHandler, RegisterSSE, RequestFromContext,
β”‚   β”‚   β”‚                   #   WithResponseHeaders, ResponseHeadersFromContext,
β”‚   β”‚   β”‚                   #   WithResponseCookies, ResponseCookiesFromContext, Options
β”‚   β”‚   β”œβ”€β”€ client.go       # Call[Req,Resp], CallOptions, UnexpectedStatusError,
β”‚   β”‚   β”‚                   #   RequestBuildError, RequestError, ResponseBodyError
β”‚   β”‚   └── cookie.go       # SetCookie, CookieOptions, PendingCookie
β”‚   β”œβ”€β”€ chi/                # chi adapter for api/rest RouteHandles (github.com/go-chi/chi/v5)
β”‚   β”‚   └── adapter.go      # Handler, Register, SSEHandler, RegisterSSE, RequestFromContext,
β”‚   β”‚                       #   WithResponseHeaders, WithResponseCookies, SetCookie, CookieOptions, Options
β”‚   β”œβ”€β”€ mqtt/               # Paho MQTT adapter for api/events ChannelHandles
β”‚   β”‚   β”œβ”€β”€ adapter.go      # SubscribeHandler, SubscribeOptions, Publish, PublishOptions,
β”‚   β”‚   β”‚                   #   SubscribeError, ErrorKind, MessageFromContext
β”‚   β”‚   └── topicvars.go    # TopicVarsFromMessage, TopicMismatchError
β”‚   β”œβ”€β”€ mcpgo/              # mark3labs/mcp-go adapter for api/mcp handles
β”‚   β”‚   └── adapter.go      # ToolHandler, ResourceHandler, PromptHandler,
β”‚   β”‚                       #   RegisterTool, RegisterResource, RegisterPrompt, Options
β”‚   └── templ/              # templ SSR format plug-in for api/rest RouteHandles
β”‚       └── adapter.go      # Format[Props], StreamingFormat[Props], DecodeNotSupportedError
β”‚
β”œβ”€β”€ forge/                  # governed KPI computation pipeline (Layer 3)
β”‚   β”œβ”€β”€ forge.go            # Measured[T], MeasuredCodec[T], Function[In,Out], NewFunction,
β”‚   β”‚                       #   Compose, Registry, PipelineSpec, PipelineInfo, FunctionMeta
β”‚   β”œβ”€β”€ collection.go       # Map, Filter, Reduce, MapValues, MapValuesK collection ops
β”‚   └── compose.go          # Compose β€” type-safe function chaining
β”‚
β”œβ”€β”€ render/                 # spec renderers (no runtime codec logic)
β”‚   β”œβ”€β”€ internal/
β”‚   β”‚   └── schemarender/   # shared schema-to-map renderer (used by openapi + asyncapi)
β”‚   β”‚       └── schemarender.go  # SchemaObject
β”‚   β”œβ”€β”€ openapi/            # OpenAPI 3.1 renderer
β”‚   β”‚   β”œβ”€β”€ openapi.go      # SchemaObject, ComponentsSchemas, MarshalJSON, MarshalYAML
β”‚   β”‚   └── document.go     # DocumentBuilder, Document, Info, Server β€” full 3.1 spec
β”‚   β”œβ”€β”€ asyncapi/
β”‚   β”‚   β”œβ”€β”€ v2/             # AsyncAPI 2.6 renderer (frozen)
β”‚   β”‚   β”‚   └── document.go # DocumentBuilder, Document, ChannelItem, Operation, Message
β”‚   β”‚   └── v3/             # AsyncAPI 3.0 renderer
β”‚   β”‚       └── document.go # DocumentBuilder, Document, Server, Operation, ChannelItem (Address)
β”‚   β”œβ”€β”€ jsonschema/         # plain JSON Schema renderer (used by api/mcp)
β”‚   β”‚   └── jsonschema.go   # Schema(s schema.Schema) json.RawMessage
β”‚   └── pipeline/           # pipeline YAML renderer (for forge.PipelineSpec)
β”‚       └── pipeline.go     # Render(spec) []byte
β”‚
β”œβ”€β”€ schema/                 # schema model (pure data, zero dependencies)
β”‚   └── schema.go           # Schema, Property, DiscriminatorSchema
β”‚
β”œβ”€β”€ validate/               # reusable constraints (reflect into schema automatically)
β”‚   β”œβ”€β”€ bytes.go            # MaxBytes(n), MinBytes(n)
β”‚   β”œβ”€β”€ duration.go         # PositiveDuration, NonNegativeDuration, MinDuration, MaxDuration
β”‚   β”œβ”€β”€ float.go            # PositiveFloat, NegativeFloat, NonZeroFloat, MinFloat, MaxFloat, RangeFloat
β”‚   β”œβ”€β”€ format.go           # Email, UUID, URL, URLWithSchemes, URI, Hostname, IPv4, IPv6, IP,
β”‚   β”‚                       #   Date, Time, DateTime, SemVer, Slug, CIDR, BearerToken
β”‚   β”œβ”€β”€ int.go              # PositiveInt, NegativeInt, NonZeroInt, MinInt, MaxInt, RangeInt; int32 + int64 variants
β”‚   β”œβ”€β”€ uint.go             # PositiveUint, MinUint, MaxUint, RangeUint; uint64 variants
β”‚   └── string.go           # NonEmptyString, MinLen, MaxLen, Pattern, OneOf, HTTPPath,
β”‚                           #   MQTTTopic, MQTTPublishTopic, IntString, PositiveIntString,
β”‚                           #   NonNegativeIntString, IntStringInRange
β”‚
β”œβ”€β”€ stats/                  # dependency-free metrics observer interfaces
β”‚   └── observer.go         # ValidationObserver, Observer, PipelineObserver, SecurityObserver, NoopObserver
β”‚
└── examples/               # usage demonstrations β€” not importable by library packages
    β”‚
    β”‚   # ── Codec (Layer 1) ────────────────────────────────────────────────────
    β”œβ”€β”€ construction/       # New + Must: construction-time validation demo
    β”œβ”€β”€ decode-errors/      # multi-field ValidationErrors + errors.As demo
    β”œβ”€β”€ error-types/        # every structured error type: ValidationError, TypeMismatch, etc.
    β”œβ”€β”€ codec-mapping/      # shared field codecs, sub-codec reuse, MapCodecSafe, MapCodecValidated
    β”œβ”€β”€ formats/            # builtin format constraints demo (Email, UUID, URL, …)
    β”œβ”€β”€ html-sanitize/      # sanitizing untrusted HTML input with a codec
    β”œβ”€β”€ multiformat/        # JSON / YAML / TOML with one codec
    β”œβ”€β”€ order/              # nested structs, SliceOf, Time, Nullable, StringMap demo
    β”œβ”€β”€ shape/              # tagged union + Downcast demo
    └── validate/           # explicit Validate before marshal
    β”‚
    β”‚   # ── REST / HTTP (Layer 2) ───────────────────────────────────────────────
    β”œβ”€β”€ api-rest/               # REST API builder: typed helpers + OpenAPI spec
    β”œβ”€β”€ openapi/                # OpenAPI components/schemas generation from a Codec
    β”œβ”€β”€ rest-api/               # full OpenAPI 3.1 document from route descriptors
    β”œβ”€β”€ adapters-nethttp/       # net/http adapter: three-layer pipeline, multi-format bodies, observer
    β”œβ”€β”€ adapters-nethttp-security/   # net/http adapter: bearer JWT, scopes, SecurityFunc, observer
    β”œβ”€β”€ adapters-nethttp-client/     # codec-as-contract HTTP client: shared contract/, Call, CredentialFunc
    β”‚   └── contract/               #   shared Route specs, codecs, types (importable by both sides)
    β”œβ”€β”€ adapters-chi/           # chi adapter: wiring api/rest to chi.Router
    β”œβ”€β”€ adapters-chi-security/  # chi adapter: bearer JWT security, per-route scopes
    β”œβ”€β”€ adapters-sse/           # SSE: NewSSERoute, SSEHandler, path codec, OpenAPI spec
    β”œβ”€β”€ adapters-streaming-sse-templ/ # chunked streaming + SSE HTML fragments via templ components
    β”œβ”€β”€ adapters-templ/         # templ SSR: same route serves HTML and JSON; observer wired
    └── png-upload/             # binary payload upload: Bytes codec, content-type enforcement
    β”‚
    β”‚   # ── Events / MQTT (Layer 2) ─────────────────────────────────────────────
    β”œβ”€β”€ api-events/             # Event channel builder: typed helpers + AsyncAPI spec
    β”œβ”€β”€ event-driven/           # full AsyncAPI 2.6 document from channel descriptors
    β”œβ”€β”€ adapters-mqtt/          # Paho MQTT: three-layer pipeline, multi-format pub/sub, wildcard
    β”œβ”€β”€ adapters-mqtt-security/ # Paho MQTT: security credentials, SecurityFunc, observer
    β”œβ”€β”€ adapters-mqtt-contract/ # codec-as-contract MQTT: shared contract/, producer + consumer
    β”‚   └── contract/           #   shared Channel specs, codecs, types (importable by both sides)
    └── gob-contract/           # Go library as contract: gob wire encoding, no code-gen
        └── contract/           #   shared Channel, codec, Gob format β€” compiler-enforced contract
    β”‚
    β”‚   # ── MCP (Layer 2) ────────────────────────────────────────────────────────
    └── adapters-mcp/           # MCP server: Tools, Resources, Prompts, MCPSpec, observer
    β”‚
    β”‚   # ── Forge / Pipeline (Layer 3) ──────────────────────────────────────────
    β”œβ”€β”€ forge-oee/          # forge pipeline: OEE KPI computation, governance, Compose, MeasuredCodec
    β”œβ”€β”€ forge-collection/   # forge collection ops: Map, Filter, Reduce, MapValues on MQTT sensor batches
    └── oee-chain/          # full three-layer chain: codex + api/events + forge with AsyncAPI + pipeline spec
    β”‚
    β”‚   # ── Config / CLI ────────────────────────────────────────────────────────
    β”œβ”€β”€ cli-config/         # CLI tool config: TOML file + env var overlay with codecs
    β”œβ”€β”€ env-config/         # format.FromEnv: schema-driven env var loading with defaults
    └── stats-observer/     # stats.ValidationObserver wired to codecs directly (no adapter)

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.
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.
nethttp
Package nethttp adapts api/rest route handles to net/http handlers.
Package nethttp adapts api/rest route handles to net/http handlers.
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.
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.
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.
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 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.
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-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-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.
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.
env-config command
Package main demonstrates format.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 format.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.
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.
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
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:
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.
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.
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.
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 (JSON, YAML, TOML, Gob).
Package format bridges Codec[T] to concrete serialization formats (JSON, YAML, TOML, Gob).
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.
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.
Package route describes HTTP operations for use with API spec renderers.
Package route describes HTTP operations for use with API spec renderers.
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 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