Documentation
¶
Index ¶
- Variables
- func CORSMiddleware(allowedOrigins []string, next http.Handler) http.Handler
- func NewGRPCServer(opts *Opts) (*grpc.Server, error)
- func NewTracerProvider(c *conf.Bootstrap, logger log.Logger) (trace.TracerProvider, func(), error)
- type APIServer
- type GRPCServers
- type HTTPMetricsServer
- type Opts
Constants ¶
This section is empty.
Variables ¶
var ProviderSet = wire.NewSet(wire.Struct(new(Opts), "*"), NewGRPCServers, NewHTTPServer, NewHTTPMetricsServer, NewTracerProvider)
ProviderSet is server providers.
var Version = "dev"
Functions ¶
func CORSMiddleware ¶ added in v1.82.0
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 ¶
NewGRPCServer retains the existing native listener and its independent TLS.
func NewTracerProvider ¶ added in v1.95.2
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
Endpoint returns the real bound address of the shared endpoint.
func (*APIServer) Start ¶ added in v1.126.0
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.
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 ¶
HTTPMetricsServer is a HTTP server that exposes the metrics endpoint
func NewHTTPMetricsServer ¶
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.