server

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package server provides the HTTP server for kumo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCBORRequest

func DecodeCBORRequest(r *http.Request, v any) error

DecodeCBORRequest decodes a CBOR request body into the given value. It uses a custom DecMode that handles CBOR time tags (Tag 1).

func WriteCBORError

func WriteCBORError(w http.ResponseWriter, code, message string, status int)

WriteCBORError writes an error response in CBOR format.

func WriteCBORResponse

func WriteCBORResponse(w http.ResponseWriter, v any)

WriteCBORResponse writes a CBOR response with the smithy-protocol header. It uses a custom EncMode that outputs time values as CBOR time tags (Tag 1).

Types

type CBORProtocolDispatcher

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

CBORProtocolDispatcher routes Smithy RPC v2 CBOR protocol requests to the appropriate service based on the URL path: /service/{serviceName}/operation/{operationName}.

func NewCBORProtocolDispatcher

func NewCBORProtocolDispatcher() *CBORProtocolDispatcher

NewCBORProtocolDispatcher creates a new CBOR protocol dispatcher.

func (*CBORProtocolDispatcher) Register

func (d *CBORProtocolDispatcher) Register(serviceName string, handler CBORServiceHandler)

Register registers a service handler for the given service name. The service name matches the one in the URL path: /service/{serviceName}/operation/{operationName}.

func (*CBORProtocolDispatcher) ServeHTTP

ServeHTTP implements http.Handler and dispatches to the appropriate service. It handles requests to /service/{serviceName}/operation/{operationName}.

type CBORServiceHandler

type CBORServiceHandler func(w http.ResponseWriter, r *http.Request, operation string)

CBORServiceHandler handles RPC v2 CBOR protocol requests for a specific service.

type Config

type Config struct {
	Host     string
	Port     int
	LogLevel slog.Level
	InitDir  string // Directory containing init scripts to execute on startup
}

Config holds the server configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default server configuration. KUMO_HOST and KUMO_PORT override the bind address when set; an unparseable KUMO_PORT is ignored and the default port is kept. KUMO_LOG_LEVEL (debug|info|warn|error) overrides the default INFO level — useful when benchmarking, where per-request INFO logs dominate CPU.

type JSONProtocolDispatcher

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

JSONProtocolDispatcher routes AWS JSON 1.0 protocol requests to the appropriate service based on the X-Amz-Target header prefix.

func NewJSONProtocolDispatcher

func NewJSONProtocolDispatcher() *JSONProtocolDispatcher

NewJSONProtocolDispatcher creates a new JSON protocol dispatcher.

func (*JSONProtocolDispatcher) Register

func (d *JSONProtocolDispatcher) Register(prefix string, handler JSONServiceHandler)

Register registers a service handler for the given target prefix. The prefix is the part before the dot in X-Amz-Target header, e.g., "AmazonSQS" for "AmazonSQS.CreateQueue" or "DynamoDB_20120810" for "DynamoDB_20120810.CreateTable".

func (*JSONProtocolDispatcher) ServeHTTP

ServeHTTP implements http.Handler and dispatches to the appropriate service.

type JSONServiceHandler

type JSONServiceHandler func(w http.ResponseWriter, r *http.Request)

JSONServiceHandler handles JSON protocol requests for a specific service.

type QueryProtocolDispatcher

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

QueryProtocolDispatcher routes AWS Query protocol requests to the appropriate service based on the Action parameter and User-Agent header. The User-Agent header must contain an api/{service} token (set by AWS SDK v2) to identify the target service.

func NewQueryProtocolDispatcher

func NewQueryProtocolDispatcher() *QueryProtocolDispatcher

NewQueryProtocolDispatcher creates a new Query protocol dispatcher.

func (*QueryProtocolDispatcher) Register

func (d *QueryProtocolDispatcher) Register(serviceName string, handler QueryServiceHandler)

Register registers a service handler.

func (*QueryProtocolDispatcher) RegisterAction

func (d *QueryProtocolDispatcher) RegisterAction(action, servicePrefix, serviceIdentifier string, handler QueryServiceHandler)

RegisterAction registers a handler for a specific action under a service identifier.

func (*QueryProtocolDispatcher) ServeHTTP

ServeHTTP implements http.Handler and dispatches to the appropriate service.

type QueryServiceHandler

type QueryServiceHandler func(w http.ResponseWriter, r *http.Request)

QueryServiceHandler handles Query protocol requests for a specific service.

type Route

type Route struct {
	Method  string
	Pattern string
	Handler http.HandlerFunc
}

Route represents a registered HTTP route.

type Router

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

Router is the HTTP router for kumo.

func NewRouter

func NewRouter(logger *slog.Logger) *Router

NewRouter creates a new router.

func (*Router) Handle

func (r *Router) Handle(method, pattern string, handler http.HandlerFunc)

Handle registers a handler for the given method and pattern.

func (*Router) HandleFunc

func (r *Router) HandleFunc(method, pattern string, handler http.HandlerFunc)

HandleFunc is an alias for Handle for compatibility with service.Router interface.

func (*Router) Routes

func (r *Router) Routes() []Route

Routes returns all registered routes.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

type Server

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

Server is the main HTTP server for kumo.

func New

func New(config Config) *Server

New creates a new server with the given configuration. Services registered via init() are automatically loaded.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server address.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for the server. This can be used with httptest.NewServer for in-process testing.

func (*Server) RegisterService

func (s *Server) RegisterService(svc service.Service)

RegisterService registers a service with the server.

func (*Server) Registry

func (s *Server) Registry() *service.Registry

Registry returns the service registry.

func (*Server) Router

func (s *Server) Router() *Router

Router returns the router.

func (*Server) Run

func (s *Server) Run() error

Run starts the server and handles graceful shutdown.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start(readyCh ...chan struct{}) error

Start starts the HTTP server. It accepts an optional readyCh channel that will be closed once the server is listening and ready to accept connections.

Jump to

Keyboard shortcuts

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