json

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package json provides an es.TypedCodec backed by the standard library's encoding/json package.

Typical usage:

import (
    "github.com/ianunruh/synapse/es"
    jsoncodec "github.com/ianunruh/synapse/codec/json"
)

reg := es.NewRegistry()
es.Register(reg, "order.placed",  jsoncodec.For[OrderPlaced]())
es.Register(reg, "order.shipped", jsoncodec.For[OrderShipped]())

Event types may freely implement encoding/json.Marshaler and encoding/json.Unmarshaler; encoding/json honors them. The Go 1.24 `omitzero` struct tag works transparently.

Index

Constants

View Source
const ContentType es.ContentType = "application/json"

ContentType is the IANA media type emitted by codecs from this package.

Variables

This section is empty.

Functions

func For

func For[E any]() es.TypedCodec[E]

For returns an es.TypedCodec that serializes values of type E through encoding/json. Register it with es.Register:

es.Register(reg, "order.placed", jsoncodec.For[OrderPlaced]())

The returned codec is stateless and safe for concurrent use; the zero value of the internal type carries no fields, so calling For is effectively free.

Types

This section is empty.

Jump to

Keyboard shortcuts

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