transport

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 1 Imported by: 15

Documentation

Overview

Package transport defines the core transport-layer abstractions for the go-wind framework.

It deliberately contains no concrete transport implementations. Callers implement the Server interface to plug in gRPC, HTTP, or any other protocol, and pass those implementations to [wind.New]. This keeps the framework core decoupled from any specific RPC stack; projects bring their own *grpc.Server / *http.Server and wrap it in a type that satisfies Server.

The Server contract

Server is intentionally minimal — three methods covering the full lifecycle of a single network listener:

  • Server.Start begins accepting connections and MUST block until its context is cancelled or an error occurs. The blocking contract is what lets [wind.App] run many servers concurrently under a single errgroup.
  • Server.Stop performs a graceful shutdown. The context it receives carries a deadline that implementations should respect.
  • Server.Endpoint returns the actual network address the server is listening on. For servers bound to ":0" (OS-assigned port), this MUST return the resolved address after Start begins accepting connections, so callers can register it with a service registry.

A minimal implementation

type MyServer struct{}

func (s *MyServer) Start(ctx context.Context) error {
    <-ctx.Done()
    return ctx.Err()
}

func (s *MyServer) Stop(ctx context.Context) error {
    // perform graceful cleanup, honoring ctx.Deadline()
    return nil
}

func (s *MyServer) Endpoint() string {
    return "grpc://0.0.0.0:9000"
}

Multiple servers are composed by passing them all to [wind.WithServer]:

app := wind.New(
    wind.WithName("gateway"),
    wind.WithServer(grpcServer, httpServer, wsServer),
)
// All three start concurrently and stop concurrently on signal.

Lifecycle ownership

transport.Server does not manage its own goroutine or signal handling — that is exclusively the responsibility of [wind.App]. A Server's job is only to expose Start/Stop/Endpoint; the App orchestrates concurrent startup, crash-cascading, and graceful shutdown. See the package documentation of the root wind package for the full lifecycle model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server interface {
	// Start begins accepting connections. It MUST block until ctx is
	// cancelled or an error occurs.
	Start(ctx context.Context) error
	// Stop performs a graceful shutdown. The provided ctx carries a deadline
	// that implementations should respect.
	Stop(ctx context.Context) error
	// Endpoint returns the actual network address the server is listening
	// on. For servers that bind to ":0" (OS-assigned port), this MUST
	// return the resolved address after [Start] begins accepting
	// connections, so callers can register it with a service registry.
	//
	// Implementations that have not yet started, or that listen on a
	// fixed address, may return the configured address immediately.
	Endpoint() string
}

Server represents a single network server whose lifecycle is managed by the application. A typical implementation wraps a *grpc.Server, *http.Server, or similar, and blocks in Start until ctx is cancelled. See doc.go for the full contract and a minimal implementation example.

Jump to

Keyboard shortcuts

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