connectrpco

package
v0.0.0-...-7cb198f Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamedConnectConfig = "connectrpco.ConnectConfig"

	GroupRegisterFunc        = "connectrpco.RegisterFunc"
	GroupUtilityRegisterFunc = "connectrpco.UtilityRegisterFunc"
	GroupServerInterceptor   = "connectrpco.ServerInterceptor"
	GroupConnectHttpOption   = "connectrpco.ConnectHttpOption"

	GroupHttpHandler    = "connectrpco.HttpHandler"
	GroupHttpMiddleware = "connectrpco.HttpMiddleware"
)

Variables

This section is empty.

Functions

func GetAuthnInfo

func GetAuthnInfo(ctx context.Context) any

GetAuthnInfo returns the authentication information attached to the context.

func NewAuthnMiddleware

func NewAuthnMiddleware(
	authnFn func(context.Context, *http.Request) (any, error),
	opts ...connecthttp.Option,
) httpo.HttpMiddleware

NewAuthnMiddleware creates a Connect authentication middleware. Pass the same Connect HTTP options as the server.

func NewConnectCorsOptions

func NewConnectCorsOptions(options cors.Options) cors.Options

NewConnectCorsOptions creates a Connect CORS options. It merges the provided options with the defaults required by Connect.

func NewCorsHandler

func NewCorsHandler(config corso.Config) httpo.HttpMiddleware

NewCorsHandler creates a Connect CORS middleware for Connect HTTP handler.

func RegisterGrpcHealth

func RegisterGrpcHealth(server *connect.Server)

RegisterGrpcHealth registers the gRPC health service. It reports every service already registered on the server as serving, so pass it to RegisterUtilityServices to run it after the application services.

func RegisterGrpcReflect

func RegisterGrpcReflect(server *connect.Server)

RegisterGrpcReflect registers the gRPC reflection service, which describes all services registered on the server. For custom reflection options, call grpcreflect.Register directly.

func SetAuthnInfo

func SetAuthnInfo(ctx context.Context, info any) context.Context

SetAuthnInfo attaches authentication information to the context.

Types

type ConnectConfig

type ConnectConfig struct {
	Enabled           bool          `default:"true"`
	Addr              string        `default:":8080"`
	ReadHeaderTimeout time.Duration `default:"1s"`
	ReadTimeout       time.Duration `default:"30s"`
	WriteTimeout      time.Duration `default:"30s"`
	IdleTimeout       time.Duration `default:"120s"`
	MaxHeaderBytes    int           `default:"8192"` // 8KiB
}

type ConnectServer

type ConnectServer struct {
	*http.Server
	// contains filtered or unexported fields
}

ConnectServer is an HTTP server wrapper.

func NewConnectServer

func NewConnectServer(opts ...ConnectServerOption) (*ConnectServer, error)

func (*ConnectServer) RPCServer

func (s *ConnectServer) RPCServer() *connect.Server

RPCServer returns the underlying Connect server, e.g. for use with an in-process transport in tests.

type ConnectServerOption

type ConnectServerOption func(*ConnectServer)

ConnectServerOption is an Connect server option.

func Address

func Address(addr string) ConnectServerOption

Address with server address.

func ConnectHttpOptions

func ConnectHttpOptions(options ...connecthttp.Option) ConnectServerOption

ConnectHttpOptions with Connect HTTP transport options, such as read limits or compression settings. They apply to every registered service.

func Handle

func Handle(pattern string, handler http.Handler) ConnectServerOption

Handle registers a new plain HTTP handler for a given pattern.

func HttpMiddleware

func HttpMiddleware(middleware ...httpo.HttpMiddleware) ConnectServerOption

HttpMiddleware with server http middleware.

func HttpPatternHandlers

func HttpPatternHandlers(patternHandlers ...httpo.HttpPatternHandler) ConnectServerOption

HttpPatternHandlers registers plain HTTP handlers.

func IdleTimeout

func IdleTimeout(timeout time.Duration) ConnectServerOption

IdleTimeout with server idle timeout.

func MaxHeaderBytes

func MaxHeaderBytes(bytes int) ConnectServerOption

MaxHeaderBytes with server max header bytes.

func ReadHeaderTimeout

func ReadHeaderTimeout(timeout time.Duration) ConnectServerOption

ReadHeaderTimeout with server read header timeout.

func ReadTimeout

func ReadTimeout(timeout time.Duration) ConnectServerOption

ReadTimeout with server read timeout.

func RegisterServices

func RegisterServices(fns ...RegisterFunc) ConnectServerOption

RegisterServices registers Connect services. The functions run in the order they are given, after all server interceptors are known.

func RegisterUtilityServices

func RegisterUtilityServices(fns ...RegisterFunc) ConnectServerOption

RegisterUtilityServices registers utility services, such as health and reflection. They run after all services passed to RegisterServices, regardless of option order, so they can inspect the registered services.

func ServerInterceptors

func ServerInterceptors(interceptors ...connect.ServerInterceptor) ConnectServerOption

ServerInterceptors with Connect server interceptors. Interceptors apply to every registered service; the first one wraps the outermost call.

func WithConnectConfig

func WithConnectConfig(config ConnectConfig) ConnectServerOption

WithConnectConfig with server config.

func WriteTimeout

func WriteTimeout(timeout time.Duration) ConnectServerOption

WriteTimeout with server write timeout.

type RegisterFunc

type RegisterFunc func(*connect.Server)

RegisterFunc registers one or more Connect services on a server, typically by calling a generated Register<Service>Handler function.

Directories

Path Synopsis
Package connectrpcotest provides utilities for testing Connect services.
Package connectrpcotest provides utilities for testing Connect services.
internal
authn
Package authn provides authentication middleware for connect.
Package authn provides authentication middleware for connect.
echotest
Package echotest provides a minimal Connect service for tests.
Package echotest provides a minimal Connect service for tests.

Jump to

Keyboard shortcuts

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