adapter

package
v0.7.4 Latest Latest
Warning

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

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

Documentation

Overview

Package adapter is the codec boundary. It is interaction-model-agnostic: the core passes a Binding (never positional proto names) and the adapter never sees the inbound transport — DecodeRequest's product is the upstream intent. A future GraphQL adapter (single endpoint, request-defined response shape) would implement the same interface without touching server/negotiate. The current codec is protobuf↔JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	DecodeRequest(b Binding, in []byte) (UpstreamCall, *wireerror.Error)
	EncodeResponse(b Binding, upstreamJSON []byte) (out []byte, contentType string, err *wireerror.Error)
	EncodeError(b Binding, status int, upstreamJSON []byte) (out []byte, contentType string, err *wireerror.Error)
}

Adapter converts between an external codec and the internal JSON backend.

type Binding

type Binding interface {
	Method() string
	Route() string
	RequestMessage() string
	ResponseMessage() string
	ErrorMessage(status int) (string, bool)
}

Binding is what the adapter needs to express upstream intent. bundle.Contract satisfies it structurally (no import cycle).

type MessageResolver

type MessageResolver interface {
	Message(fullName string) (protoreflect.MessageDescriptor, error)
}

MessageResolver resolves a fully-qualified proto name to its descriptor. bundle.Bundle satisfies it structurally.

type ProtoJSON

type ProtoJSON struct {
	// contains filtered or unexported fields
}

ProtoJSON is the reference adapter: protobuf in, JSON to the upstream, and back. It owns no transport and no routing policy.

func NewProtoJSON

func NewProtoJSON(r MessageResolver) *ProtoJSON

func (*ProtoJSON) DecodeRequest

func (p *ProtoJSON) DecodeRequest(b Binding, in []byte) (UpstreamCall, *wireerror.Error)

func (*ProtoJSON) EncodeError added in v0.7.0

func (p *ProtoJSON) EncodeError(b Binding, status int, upstreamJSON []byte) ([]byte, string, *wireerror.Error)

EncodeError encodes an upstream non-success body into the message the bundle binds for (route, status). The adapter is generic over descriptors, so a typed error body reuses the success-path machinery. The caller resolves declared-ness before calling; an unbound status is a programmer error and yields upstream_error.

func (*ProtoJSON) EncodeResponse

func (p *ProtoJSON) EncodeResponse(b Binding, upstreamJSON []byte) ([]byte, string, *wireerror.Error)

type UpstreamCall

type UpstreamCall struct {
	Method      string
	Path        string
	RawQuery    string
	Body        []byte
	ContentType string
}

UpstreamCall is the adapter's product: the intent of one upstream call. The adapter sets Method/Path/Body/ContentType from the binding + codec; it does not set RawQuery — the verbatim inbound query is transport the server owns.

Jump to

Keyboard shortcuts

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