Documentation
¶
Overview ¶
Package gateway is the control-plane gateway (FR-CORE-040): one listener serving every API over HTTP/1.1 REST and gRPC (h2c), routing by path prefix and Host, authenticating callers and recording the request log.
Index ¶
- Constants
- func NewServer(h http.Handler, log *slog.Logger) *http.Server
- type Gateway
- func (g *Gateway) GRPCOptions(service string) []grpc.ServerOption
- func (g *Gateway) HandleAdmin(h http.Handler)
- func (g *Gateway) HandleConsole(h http.Handler)
- func (g *Gateway) Hosts() []string
- func (g *Gateway) Middleware(service string, h http.Handler) http.Handler
- func (g *Gateway) Register(s emu.Service) error
- func (g *Gateway) Router(service string) emu.Router
- func (g *Gateway) Serve(l net.Listener) error
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) SetAdminToken(tok string)
- func (g *Gateway) Shutdown(ctx context.Context) error
Constants ¶
const ( AdminTokenHeader = "X-Gcpemu-Admin-Token" AdminTokenCookie = "gcpemu_admin" // AdminTokenQuery is the console URL parameter that sets the cookie. AdminTokenQuery = "token" )
Admin token transport (FR-UI-009, ADR 0006).
const PathHost = "www.googleapis.com"
PathHost is Google's legacy shared API host. Its URLs carry the API in the path (www.googleapis.com/storage/v1/..., /oauth2/v3/certs, the compute selfLink base), which is exactly the gateway's path routing, so it is always served without a host mount.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Gateway ¶
type Gateway struct {
// Faults holds fault-injection rules applied to every request (FR-CORE-060).
Faults fault.Set
// contains filtered or unexported fields
}
Gateway multiplexes REST and gRPC for all services.
func (*Gateway) GRPCOptions ¶
func (g *Gateway) GRPCOptions(service string) []grpc.ServerOption
GRPCOptions returns interceptors that authenticate and log gRPC calls; service names the owner for per-service servers ("" = look up by method).
func (*Gateway) HandleAdmin ¶
HandleAdmin mounts the admin API (not request-logged; only the Admin token guards it, see SetAdminToken).
func (*Gateway) HandleConsole ¶ added in v0.2.0
HandleConsole mounts the Web console at /console and /console/ (not request-logged; FR-UI-002). Only the Admin token guards it.
func (*Gateway) Hosts ¶
Hosts returns the sorted real hostnames mounted with host routing (e.g. "storage.googleapis.com") plus PathHost; the Google frontend (FR-CORE-043, FR-INT-007) serves exactly these names.
func (*Gateway) Middleware ¶
Middleware authenticates, recovers from panics and logs each HTTP request.
func (*Gateway) ServeHTTP ¶
func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP dispatches gRPC, host-mode and path-routed requests.
func (*Gateway) SetAdminToken ¶ added in v0.6.0
SetAdminToken makes every Admin API and Web console request present tok (the API gateway is bound beyond loopback); "" turns the guard off. Call it before Serve.