crossbowhttp

package module
v0.0.0-...-edf7215 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

Crossbowhttp

Crossbowhttp is a lightweight adapter for exposing crossbow servers over http. It includes basic handling of JSON and supports middleware chaining (see chain).

Usage

Adapters just have to implement the HttpMarshaller interface. For examples see json. The marshaler allows decoding incoming requests and encoding outgoing responses.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHttpAdapter

func RegisterHttpAdapter[M any, O any](mux *http.ServeMux, adapter HttpAdapter[M, O], params RegisterHttpAdapterParams)

Register a HttpAdapter to a http.ServeMux

Types

type Chain

type Chain []func(http.Handler) http.Handler

A simple chain of middlewares to be put in front of an endpoint

func (*Chain) Add

func (c *Chain) Add(f func(http.Handler) http.Handler)

type HealthEncoder

type HealthEncoder = func(ServerHealth) ([]byte, int)

function mapping health metrics of a server to a byte blob ready for streaming over http. The second return is the http status code

type HttpAdapter

type HttpAdapter[M any, O any] struct {
	// contains filtered or unexported fields
}

func (*HttpAdapter[M, O]) HandleCall

func (h *HttpAdapter[M, O]) HandleCall() http.HandlerFunc

Returns the http handler function for synchronous calls to the server

func (*HttpAdapter[M, O]) HandleSend

func (h *HttpAdapter[M, O]) HandleSend() http.HandlerFunc

Returns the http handler function for asynchronous sends to the server

func (*HttpAdapter[M, O]) HealthHandler

func (h *HttpAdapter[M, O]) HealthHandler(enc HealthEncoder) http.HandlerFunc

returns the http handler for fetching the health metrics of the server.

type HttpMarshaller

type HttpMarshaller[M any, O any] interface {
	Decode(*http.Request) (M, error)
	Econde(O, error) ([]byte, int, error)
	MapError(error) ([]byte, int)
}

type RegisterHttpAdapterParams

type RegisterHttpAdapterParams struct {
	HealthEnc HealthEncoder // function that encoedes the server health to the desired output format

	SendMiddleware   Chain // middleware chain for the .../send endpoint
	CallMiddleware   Chain // middleware chain for the .../call endpoint
	HealthMiddleware Chain // middleware chain for the .../health endpoint
	// contains filtered or unexported fields
}

Params for HttpAdapter to http.ServeMux registration

type ServerHealth

type ServerHealth struct {
	Stats      crossbow.StatsSnapshot
	MailboxLen int
	Terminated bool
}

Health metrics of a server aggregated into a single struct for encoding

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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