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

server

package
v1.126.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

ProviderSet is server providers.

View Source
var Version = "dev"

Functions

func CORSMiddleware added in v1.82.0

func CORSMiddleware(allowedOrigins []string, next http.Handler) http.Handler

CORSMiddleware returns an http.Handler that applies CORS headers based on allowedOrigins. If allowedOrigins is empty, the middleware is a passthrough (CORS disabled). If "*" is in the list, any origin is allowed. Otherwise, only origins in the list are echoed back. OPTIONS preflight requests are short-circuited with 204 No Content before reaching the next handler.

func NewGRPCServer

func NewGRPCServer(opts *Opts) (*grpc.Server, error)

NewGRPCServer retains the existing native listener and its independent TLS.

func NewTracerProvider added in v1.95.2

func NewTracerProvider(c *conf.Bootstrap, logger log.Logger) (trace.TracerProvider, func(), error)

NewTracerProvider creates an OTel TracerProvider configured from the Bootstrap config. When tracing is disabled or not configured, it returns a noop TracerProvider.

Types

type APIServer added in v1.126.0

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

APIServer owns the shared CAS listener on server.http.addr. The standard HTTP server owns every connection and dispatches each request:

native gRPC (HTTP/2 + application/grpc*) -> httputil.ReverseProxy ->
  the private native gRPC server (grpc.Server.Serve, native transport)
everything else                         -> the existing Kratos HTTP routes

ByteStream keeps the native transport: the proxy streams the request body into the private connection, whose HTTP/2 flow-control window paces the proxy's reads, and net/http's own window paces the client. No unbounded read-ahead exists anywhere on the path, in either direction. Mixed gRPC and ordinary HTTP requests may share one upstream connection in any order, as they do on the control plane (spec D-020).

func NewHTTPServer

func NewHTTPServer(settings *Opts, grpcServers *GRPCServers) (*APIServer, error)

NewHTTPServer binds the shared CAS endpoint and dispatches every request. When it returns an error, it has closed the private gRPC socket it would have consumed, so a failed construction does not leak it.

func (*APIServer) Endpoint added in v1.126.0

func (s *APIServer) Endpoint() (*url.URL, error)

Endpoint returns the real bound address of the shared endpoint.

func (*APIServer) Start added in v1.126.0

func (s *APIServer) Start(ctx context.Context) error

Start serves the shared endpoint until ctx is cancelled or a transport fails. The HTTP server serves every connection; the private native gRPC server serves the connections the proxy opens to it. A genuine failure of either transport — including the private gRPC listener failing — is surfaced so the whole endpoint stops, rather than serving HTTP while proxied gRPC answers 502.

func (*APIServer) Stop added in v1.126.0

func (s *APIServer) Stop(ctx context.Context) error

Stop drains the HTTP server first — which includes every proxied gRPC stream, because those live on HTTP connections — then stops the private native gRPC server so its in-flight RPCs finish.

type GRPCServers added in v1.126.0

type GRPCServers struct {
	Private     *grpc.Server
	PrivateAddr string
	// PrivateLis holds the private listener so a caller that never starts
	// the server can still close the socket: before Start registers the
	// listener with grpc-go, Private.Stop does not close it.
	PrivateLis net.Listener
	Legacy     *grpc.Server
}

GRPCServers keeps the shared endpoint's private native gRPC server separate from the optional legacy listener. Both run the same services and interceptors. Private binds an ephemeral loopback listener that the shared endpoint's reverse proxy dials; it is independent of the legacy listener's address, TLS configuration, and flag, and exists whether or not the legacy listener is enabled.

func NewGRPCServers added in v1.126.0

func NewGRPCServers(opts *Opts) (*GRPCServers, error)

NewGRPCServers builds the private native server for the shared endpoint and the optional legacy listener, with the same services and interceptors.

func (*GRPCServers) Close added in v1.126.0

func (s *GRPCServers) Close() error

Close releases the private socket without serving. Callers that hand the servers to the application lifecycle must not call it; construction-failure paths use it to avoid leaking the bound address.

type HTTPMetricsServer

type HTTPMetricsServer struct {
	*http.Server
}

HTTPMetricsServer is a HTTP server that exposes the metrics endpoint

func NewHTTPMetricsServer

func NewHTTPMetricsServer(c *conf.Server, logger log.Logger) (*HTTPMetricsServer, error)

NewHTTPMetricsServer exposes the metrics endpoint. server.http_metrics never applied TLS: a configured tls_config is ignored with a warning rather than rejected, so existing deployments that set it keep working.

type Opts added in v1.126.0

type Opts struct {
	ServerConfig *conf.Server
	AuthConfig   *conf.Auth
	ByteService  *service.ByteStreamService
	ResourceSvc  *service.ResourceService
	DownloadSvc  *service.DownloadService
	Providers    backend.Providers
	Validator    protovalidate.Validator
	Logger       log.Logger
}

Opts provides the shared service implementations and transport settings.

Jump to

Keyboard shortcuts

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