connectserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package connectserver serves an app's API over Connect, on the app's 2 sockets: its private socket, where its own user works, and its lodge socket, where lodge forwards a user's calls.

The route is the code that protoc-gen-connect-go writes: the handler of an app's service is the API that protoc-gen-hearth-authz generates, and the generated client satisfies the agent interface that protoc-gen-hearth-mcp generates. This package adds the 3 things that no generator writes: the error mapping of the permission runtime, the admission of the 2 sockets, and the server itself.

docs/specs/connect.md is the contract.

Index

Constants

View Source
const (
	// CallerHeader is lodge's header for the kind of caller of a request. It
	// arrives only on the app's lodge socket: lodge writes it, and the adapter
	// deletes every Lodge-* header of the private socket.
	CallerHeader = "Lodge-Caller"
	// PrincipalCaller is the value of CallerHeader for a call that lodge
	// forwards for an authenticated principal. A call with any other value is
	// refused.
	PrincipalCaller = "principal"
)

The header that names the caller of a call on the lodge socket, and the 1 value that admits it.

View Source
const LodgePrefix = "/connect/"

LodgePrefix is the path under which lodge forwards a call on an app's lodge socket: POST /connect/<service>/<method>.

Variables

This section is empty.

Functions

func Error

func Error(err error) error

Error returns err as a Connect error whose code names what went wrong, and whose message is err's own text.

  • a *connect.Error stays as it is;
  • a refusal of the permission runtime (*authz.DeniedError, or authz.ErrNoCaller) is CodePermissionDenied, with the text "permission denied: needs <capability> on <selector>=<path>";
  • an invalid path (*authz.PathError) is CodeInvalidArgument;
  • context.Canceled is CodeCanceled, and context.DeadlineExceeded is CodeDeadlineExceeded;
  • any other error is CodeInternal, because an app's own error is its own business.

func HandlerOptions

func HandlerOptions(opts ...connect.HandlerOption) []connect.HandlerOption

HandlerOptions returns the handler options of an app's service: the error mapping of Interceptor, and then opts.

func Interceptor

func Interceptor() connect.Interceptor

Interceptor returns 1 Connect interceptor that maps the error of each unary call with Error, so that a refusal reaches the client with the permission runtime's code and text. A streaming call passes through unchanged.

func Lodge

func Lodge(path string, h http.Handler) http.Handler

Lodge returns the handler of an app's lodge socket, for mounting at LodgePrefix. It serves h at path, and it refuses a request with 403 unless the CallerHeader names PrincipalCaller and the path is under LodgePrefix. Behind that, lodge.Handler reads the principal and the grant of lodge's 2 headers, and refuses a connection that lodge's listener did not accept.

The app mounts its own routes beside this adapter, outside it: /health and every other path that is no Connect call is the app's, and lodge's headers bound no part of it.

func Private

func Private(path string, h http.Handler) http.Handler

Private returns the handler of an app's private socket: h at path, as the local user, and no other path.

The adapter deletes every Lodge-* header of the request, so a forged Lodge-Principal or Lodge-Grant reaches no handler: the caller of every call on this socket is authz.LocalCaller().

func Serve

func Serve(ctx context.Context, l net.Listener, h http.Handler) error

Serve serves h on l until ctx ends, and it then shuts the server down. It returns nil after a clean stop, and the server's error otherwise: an error of the server closes the connections it accepted, so no new call starts after Serve returns (a call in flight sees its connection close).

The caller passes the listener of either socket: lodge.Listener(l, uid) serves the socket of 1 user only, and Serve marks the connections of that listener with lodge.ConnContext, so lodge.Handler can tell a call that came from lodge's socket from any other.

func UnixClient

func UnixClient(socket string) *http.Client

UnixClient returns a client of the HTTP server on 1 Unix socket.

The host of the client's base URL is ignored, and a client dials the socket whatever it is given, so a caller writes "http://localhost" and not a real host.

Types

This section is empty.

Jump to

Keyboard shortcuts

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