api

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 6 Imported by: 2 modules, 2 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 api configures listeners and middleware served by the SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCOption

type GRPCOption interface {
	// contains filtered or unexported methods
}

GRPCOption configures Service.GRPC.

func Reflection

func Reflection() GRPCOption

Reflection serves grpc.reflection (v1 and v1alpha) on this route's port, once per port, for grpcurl and similar tools. It is not announced to external routing: it answers on the port directly.

type HTTPOption

type HTTPOption interface {
	// contains filtered or unexported methods
}

HTTPOption configures Service.HTTP and Service.GraphQL.

type HostOption

type HostOption interface {
	HTTPOption
	WSProtoOption
}

HostOption applies to managed HTTP/ws-proto APIs and API declarations.

func Host

func Host(h string) HostOption

Host matches the route by Host header in addition to its prefix: an exact host ("api.example.com") or a wildcard ("*.example.com"). Managed HTTP routes with one prefix and different hosts share a port.

type InterceptorOption

type InterceptorOption interface {
	GRPCOption
	WSProtoOption
}

InterceptorOption applies to Service.GRPC, Service.Internal and wsproto.Serve.

func Interceptors

Interceptors wrap the unary calls of this registration's services only, the first outermost, inside the SDK's recovery and tracing. The same register function passed to Service.GRPC and wsproto.Serve takes them separately.

func StreamInterceptors

func StreamInterceptors(i ...grpc.StreamServerInterceptor) InterceptorOption

StreamInterceptors wrap the streaming calls of this registration's services only, the first outermost.

type ListenOption

type ListenOption interface {
	GRPCOption
	HTTPOption
	WSProtoOption
}

ListenOption applies to managed routes.

func Listen

func Listen(name, addr string) ListenOption

Listen serves a managed route on its own listener, named in code, at addr (usually from configuration) instead of the shared public port. Routes on one listener share one server. The manifest names the listener; the instance state carries its port, so the manifest does not depend on addr. One name has one address.

type MTLSOption added in v0.6.20

type MTLSOption interface {
	GRPCOption
	HTTPOption
	WSProtoOption
}

MTLSOption applies to Service.GRPC, Service.HTTP, Service.GraphQL and wsproto.Serve.

func MTLS added in v0.6.20

func MTLS() MTLSOption

MTLS serves the route's port to services of the mesh only: mutual TLS with the certificates of the installed driver (Consul's CA), every call authorized by the mesh's rules (Consul intentions) and its caller in backplane.CallerOf. A port is mTLS or not as a whole: every route on it says the same, or Run fails. Without the driver or Consul, Run fails. Clients call it with Root.ServiceCredentials (gRPC) or Root.ServiceTLS.

type MiddlewareOption

type MiddlewareOption interface {
	HTTPOption
	WSProtoOption
}

MiddlewareOption applies to Service.HTTP, Service.GraphQL and wsproto.Serve.

func Middleware

func Middleware(mw func(http.Handler) http.Handler) MiddlewareOption

Middleware wraps this route's handler; repeated, the first is outermost. On ws-proto it runs once per connection, around its whole life: it sees the upgrade request and rejects it by answering without calling next; the request context it passes to next is the connection's, every call's context derives from it and canceling it closes the connection; next returns when the connection has closed.

type Origins

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

Origins is the browser origin policy of a WebSocket endpoint (ws-proto). It is a required argument where it applies; the zero value allows only same-origin browsers and non-browser clients.

func AllowOrigins

func AllowOrigins(patterns ...string) Origins

AllowOrigins accepts upgrades from browsers on these host patterns ("app.example.com", "*.example.com") in addition to same-origin ones.

func AnyOrigin

func AnyOrigin() Origins

AnyOrigin accepts every origin: for endpoints that authenticate each call themselves and never rely on cookies.

func (Origins) IsAny

func (o Origins) IsAny() bool

IsAny reports whether every origin is accepted.

func (Origins) Patterns

func (o Origins) Patterns() []string

Patterns are the accepted host patterns.

type WSProtoOption

type WSProtoOption interface {
	// contains filtered or unexported methods
}

WSProtoOption configures wsproto.Serve.

func CallMiddleware added in v0.6.46

func CallMiddleware(mw ...wsrpc.Middleware) WSProtoOption

CallMiddleware wraps every call of a ws-proto endpoint, however its services were registered, the first outermost, inside the SDK's recovery and tracing. Its context is the call's, derived from the connection's (see Middleware).

func Keepalive added in v0.6.46

func Keepalive(interval, timeout time.Duration) WSProtoOption

Keepalive pings the clients of a ws-proto endpoint every interval and closes a connection whose pong does not come within timeout; interval <= 0 disables pinging. Without it: every 20s, timeout 10s.

Jump to

Keyboard shortcuts

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