Help us shape the future of Go! Take the 2026 Go Developer Survey

transport

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README ΒΆ

Nexss Transport

Nexss Flow πŸŒ€ ready

CI Latest tag Go Reference License

Nexss Transport connects Nexss Kernel actions to protocol-specific entry points and runtimes. Adapters translate incoming requests, commands, events, and schedules into typed action executions, while the action handler stays independent of the transport.

A common transport.Transport contract provides binding discovery, action mounting, and lifecycle management. An action can carry multiple bindings and be mounted on more than one transport.

Scope: This module includes HTTP and CLI adapters, in-process messaging and scheduling tools, and Nexss Flow integration. Its bus and task queue are in-memory components, not external brokers or durable storage.

Architecture

Application / Nexss Flow
          β”‚
          β–Ό
Typed Nexss Kernel actions
  .Route(thttp.GET(... )) Β· .Route(tcli.Command(...)) Β· other bindings
          β”‚
          β–Ό
Nexss Transport
  β”œβ”€β”€ thttp     HTTP routes, SSE, streaming
  β”œβ”€β”€ tcli      commands and flags
  β”œβ”€β”€ tbus      in-process event bus
  β”œβ”€β”€ tmsg      canonical message envelopes
  β”œβ”€β”€ tworker   interval-driven workers
  └── cron      scheduled actions
          β”‚
          └── shared codecs, identity, bus, mediator, and task queue packages

Adapters implement a shared lifecycle: CanHandle recognizes their binding types, Mount registers actions, and Do(ctx, ... ) starts a listener or runs the selected command. Long-running transports stop when their context is canceled.

Install

Requires Go 1.26.9 or newer.

go get github.com/nexssp/transport@latest

Quick start: HTTP

Create a typed action, bind it to a route, then mount it on an HTTP server:

package main

import (
	"context"
	"errors"
	"log"
	"os"
	"os/signal"

	"github.com/nexssp/kernel/action"
	"github.com/nexssp/transport/thttp"
 )

type HelloRequest struct {
	Name string `path:"name"`
}

type HelloResponse struct {
	Message string `json:"message"`
}

func main() {
	hello := action.New("hello", func(_ context.Context, req HelloRequest) (HelloResponse, error) {
		return HelloResponse{Message: "Hello, " + req.Name}, nil
	}).Route(thttp.GET("/hello/{name}" )).Build()

	server := thttp.New(":8080" )
	server.Mount([]action.AnyAction{hello})

	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
	defer stop()

	if _, err := server.Do(ctx, nil); err != nil && !errors.Is(err, context.Canceled) {
		log.Fatal(err)
	}
}

Run the application and try the route:

curl http://localhost:8080/hello/Maks

The HTTP adapter binds the path parameter to HelloRequest.Name and encodes the response as JSON.

Quick start: CLI

The CLI adapter maps actions to named commands, binds request fields to flags or positionals, and generates help from the command metadata:

package main

import (
	"context"
	"log"

	"github.com/nexssp/kernel/action"
	"github.com/nexssp/transport/tcli"
 )

type HelloRequest struct {
	Name string `cli:"name,n"`
}

func main() {
	hello := action.New("hello", func(_ context.Context, req HelloRequest) (string, error) {
		return "Hello, " + req.Name, nil
	}).Route(tcli.Command("hello", "Greet someone")).Build()

	cli := tcli.New() // Reads os.Args by default.
	cli.Mount([]action.AnyAction{hello})
	if _, err := cli.Do(context.Background(), nil); err != nil {
		log.Fatal(err)
	}
}

For example, invoke the built application as app hello --name Julia. Use tcli.WithArgs(...) to supply arguments directly, and tcli.WithOutput(...) to redirect output in tests or embedded use.

Transports and packages

Package Purpose
thttp HTTP routes and raw handlers; automatic path, query, header, cookie, and form binding; middleware; configurable codecs and request limits; categorized error-to-status mapping; Server-Sent Events (SSE); and O(1)-memory NDJSON streaming.
tcli CLI command routing, aliases, flags, positional arguments, request schemas, generated help, and encoded results.
tbus Connects action bindings to a concurrent, in-process publish/subscribe bus.
tmsg and message Route protocol-neutral message envelopes through an in-process router, preserving request, execution, and trace identity.
tworker Run bound actions on intervals with isolated request contexts and optional restart-on-error behavior.
cron Run actions on standard cron schedules or fixed intervals.
bus Generic in-process pub/sub, typed 1:1 command routing, and logging, panic-recovery, and timeout middleware.
bus/mediator CQRS-style mediator: typed 1:1 commands and 1:N event publishing.
bus/taskqueue In-memory task queue with high, normal, and low priority lanes, worker pools, retries, dead-letter handling, panic recovery, and backpressure. It is not a durable queue.
codec Shared codec interface; JSON is the default implementation.
HTTP request binding

HTTP request fields can be populated from route parameters, the URL query, headers, cookies, or form data using struct tags. Request bodies use the configured codec (JSON by default). The HTTP adapter also provides middleware hooks, request/execution/trace headers, SSE, and direct NDJSON iterator streaming.

Nexss Flow πŸŒ€ integration

Bundles under thttp/nexssflow, tcli/nexssflow, tbus/nexssflow, tworker/nexssflow, cron/nexssflow, bus/nexssflow, bus/mediator/nexssflow, and bus/taskqueue/nexssflow expose transport listeners, messaging actions, and bindings to Nexss Flow programs. Each flow uses @require to load its bundle and, for listeners, a binding modifier on a pipeline:

@require github.com/nexssp/transport/thttp/nexssflow { addr: ":8080" }
@pipeline hello:route="GET /hello"
  runtime.const @{ value: "Hello, Maks" }
@end
thttp.listen
@require github.com/nexssp/transport/tcli/nexssflow
@pipeline hello:cli="hello:Greet someone"
  runtime.const @{ value: "Hello, Julia" }
@end
tcli.listen
@require github.com/nexssp/transport/tbus/nexssflow
@pipeline orders:topic="orders"
  runtime.noop
@end
tbus.listen
@require github.com/nexssp/transport/tworker/nexssflow
@pipeline heartbeat:worker=1m
  runtime.const @{ value: "tick" }
@end
tworker.listen
@require github.com/nexssp/transport/cron/nexssflow
@pipeline hourly:cron="0 * * * *"
  runtime.const @{ value: "tick" }
@end
cron.listen

The generic bus exposes bus.publish (input { subject, payload }), bus.send (input { name, payload }), and bus.listen; bind subscribers with subject and command handlers with command:

@require github.com/nexssp/transport/bus/nexssflow
@pipeline orders:subject="orders"
  runtime.noop
@end
bus.listen

The mediator exposes mediator.send (input { name, payload }) and mediator.publish (input { name, payload }). Register command handlers with command and event subscribers with event:

@require github.com/nexssp/transport/bus/mediator/nexssflow
@pipeline createUser:command="users.create"
  runtime.noop
@end
mediator.listen

The task queue exposes taskqueue.enqueue (input { type, payload, priority }, where priority is high, normal, or low) and taskqueue.listen; bind worker pipelines with task:

@require github.com/nexssp/transport/bus/taskqueue/nexssflow
@pipeline sendEmail:task="email.send"
  runtime.noop
@end
taskqueue.listen

Run a flow file with nflow run <file>.nflow. The repository's fuller HTTP samples are in nflows/.

Flow parity: Flow supports HTTP routes, CLI commands, in-process topic pub/sub, interval workers, cron listeners, generic bus pub/sub and commands, mediator commands/events, and task queue producers/workers. Some advanced HTTP/CLI controls remain Go-only.

Development commands

Local workflows and CI use Task. Install it once:

go install github.com/go-task/task/v3/cmd/task@latest

List available targets and run the common checks:

task --list
task test                 # short test suite
task test -- ./thttp      # test one package
task test:race            # race-enabled tests
task bench                # benchmarks with memory statistics
task ci                   # repository CI gate
  • Nexss Kernel β€” typed actions and execution runtime.

  • Nexss Flow β€” flow language and runtime for composing actions.

  • Task β€” task runner used by this repository's local workflows and CI.

Documentation ΒΆ

Overview ΒΆ

Package transport defines the universal boundary interface for Nexss applications. Concrete adapters (thttp, tcli, tbus, cron, tworker) translate incoming network or CLI invocations into typed action.Executable dispatches.

Index ΒΆ

Constants ΒΆ

View Source
const (
	HeaderRequestID   = "X-Request-ID"
	HeaderExecutionID = "X-Execution-ID"
	HeaderTraceID     = "X-Trace-ID"
	HeaderSpanID      = "X-Span-ID"
)

Standard transport-level correlation headers and keys.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func MapToHTTPStatus ΒΆ

func MapToHTTPStatus(k xerr.Kind) int

MapToHTTPStatus converts an xerr.Kind to its corresponding standard HTTP status code.

Types ΒΆ

type Transport ΒΆ

type Transport interface {
	fmt.Stringer

	// CanHandle reports whether this transport can process the given routing binding.
	CanHandle(b action.Binding) bool

	// Mount registers actions into the transport's internal routing table.
	Mount(actions []action.AnyAction)

	// Do starts the transport listener loop and blocks until ctx is canceled.
	Do(ctx context.Context, v any) (any, error)
}

Transport defines the universal lifecycle and routing contract for protocol listeners.

Directories ΒΆ

Path Synopsis
bus
Package bus provides a lightweight, type-safe in-process message bus.
Package bus provides a lightweight, type-safe in-process message bus.
mediator
Package mediator provides a CQRS-style mediator.
Package mediator provides a CQRS-style mediator.
mediator/nexssflow
Package nexssflow exposes the CQRS mediator to Nexss Flow.
Package nexssflow exposes the CQRS mediator to Nexss Flow.
nexssflow
Package nexssflow exposes the generic in-process bus to Nexss Flow.
Package nexssflow exposes the generic in-process bus to Nexss Flow.
taskqueue/nexssflow
Package nexssflow exposes the in-process task queue to Nexss Flow.
Package nexssflow exposes the in-process task queue to Nexss Flow.
Package identity provides helpers for reading and propagating transport identity.
Package identity provides helpers for reading and propagating transport identity.
internal
flowutil
Package flowutil contains shared helpers for Nexss Flow adapters.
Package flowutil contains shared helpers for Nexss Flow adapters.
Package message provides a protocol-neutral envelope and router.
Package message provides a protocol-neutral envelope and router.
Package tmsg routes canonical messages to Kernel actions.
Package tmsg routes canonical messages to Kernel actions.

Jump to

Keyboard shortcuts

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