jsonapi

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package jsonapi provides JSON-serializable request and response models for the greet engine, together with mappers that convert to and from the domain models. The domain models themselves carry no jsonapi tags; all JSON shaping lives here so the wire format can evolve independently.

Structure mirrors the protocols/ tree: this root package holds the core Request/Response types plus a mapper registry, and each protocol has its own subpackage (jsonapi/tls, jsonapi/ssh, ...) that registers its data mapper and option decoder via Register(c *Codec). Import jsonapi/all to opt into every protocol.

All JSON field names use camelCase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationToMs

func DurationToMs(d time.Duration) float64

DurationToMs converts a time.Duration to fractional milliseconds.

Types

type Codec

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

Codec holds data mappers and option decoders for JSON serialization.

func NewCodec

func NewCodec() *Codec

NewCodec creates a new empty Codec.

func (*Codec) FromGreetResult

func (c *Codec) FromGreetResult(result *greet.GreetResult) *Response

FromGreetResult maps a domain *greet.GreetResult to a JSON-serializable *Response. It returns nil when result is nil.

func (*Codec) RegisterDataMapper

func (c *Codec) RegisterDataMapper(name string, m DataMapper)

RegisterDataMapper registers a DataMapper for the named protocol layer.

func (*Codec) RegisterOptionDecoder

func (c *Codec) RegisterOptionDecoder(name string, d OptionDecoder)

RegisterOptionDecoder registers an OptionDecoder for the named protocol.

type DataMapper

type DataMapper func(data greet.LayerData) any

DataMapper converts a protocol-specific domain payload (as stored in greet.LayerResult.Data) into its JSON-serializable form.

type Layer

type Layer struct {
	// Name is the layer slug (e.g. "tcp", "tls", "minecraft").
	Name string `json:"name"`

	// TTFBMs is the time to first byte from the shared start anchor, in milliseconds.
	TTFBMs float64 `json:"ttfbMs"`

	// TTLBMs is the time to last byte from the shared start anchor, in milliseconds.
	TTLBMs float64 `json:"ttlbMs"`

	// Success indicates whether this layer completed without error.
	Success bool `json:"success"`

	// Data holds the protocol-specific payload for this layer. Nil for
	// transport-only layers (tcp, udp).
	Data any `json:"data,omitempty"`
}

Layer is the JSON-serializable result of a single layer.

type OptionDecoder

type OptionDecoder func(raw json.RawMessage) ([]greet.GreetOption, error)

OptionDecoder decodes a protocol's raw JSON options into engine GreetOptions.

type Request

type Request struct {
	// Protocol is the registered protocol name, e.g. "tls", "minecraft".
	Protocol string `json:"protocol"`

	// Target is the host or host:port to probe.
	Target string `json:"target"`

	// Options holds per-protocol options keyed by protocol name. Each value is
	// decoded by the option decoder registered for that protocol.
	Options map[string]json.RawMessage `json:"options,omitempty"`
}

Request is the JSON-serializable input for a greet operation.

func (*Request) GreetOptions

func (r *Request) GreetOptions(c *Codec) ([]greet.GreetOption, error)

GreetOptions builds engine GreetOptions from the request. It dispatches each per-protocol option blob to its registered decoder. An unknown protocol key in Options is an error.

type Response

type Response struct {
	// Protocol is the name of the outermost application layer.
	Protocol string `json:"protocol"`

	// Transport is the base transport used ("tcp" or "udp").
	Transport string `json:"transport"`

	// TTDRMs is the time to DNS resolution, in milliseconds.
	TTDRMs float64 `json:"ttdrMs"`

	// RTTMs is the time to establish the transport connection, in milliseconds.
	RTTMs float64 `json:"rttMs"`

	// Success is true only when every layer in the stack succeeded.
	Success bool `json:"success"`

	// Layers contains per-layer results in stack order.
	Layers []Layer `json:"layers"`
}

Response is the JSON-serializable outcome of a greet operation.

Directories

Path Synopsis
Package http provides the JSON-serializable model, mapper, and option decoder for the HTTP layer.
Package http provides the JSON-serializable model, mapper, and option decoder for the HTTP layer.
Package minecraft provides the JSON-serializable model, mapper, and option decoder for the Minecraft layer.
Package minecraft provides the JSON-serializable model, mapper, and option decoder for the Minecraft layer.
Package postgresql provides the JSON-serializable model, mapper, and option decoder for the PostgreSQL layer.
Package postgresql provides the JSON-serializable model, mapper, and option decoder for the PostgreSQL layer.
Package ssh provides the JSON-serializable model and mapper for the SSH layer's result.
Package ssh provides the JSON-serializable model and mapper for the SSH layer's result.
Package tls provides the JSON-serializable model and mapper for the TLS layer's result.
Package tls provides the JSON-serializable model and mapper for the TLS layer's result.

Jump to

Keyboard shortcuts

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