gateway

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 0 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 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

View Source
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).

View Source
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

func NewServer

func NewServer(h http.Handler, log *slog.Logger) *http.Server

NewServer returns an http.Server for h that speaks HTTP/1.1 and h2c.

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 New

func New(env *emu.Env, log *reqlog.Log) *Gateway

New creates a gateway. Call Router for each service, then Serve.

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

func (g *Gateway) HandleAdmin(h http.Handler)

HandleAdmin mounts the admin API (not request-logged; only the Admin token guards it, see SetAdminToken).

func (*Gateway) HandleConsole added in v0.2.0

func (g *Gateway) HandleConsole(h http.Handler)

HandleConsole mounts the Web console at /console and /console/ (not request-logged; FR-UI-002). Only the Admin token guards it.

func (*Gateway) Hosts

func (g *Gateway) Hosts() []string

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

func (g *Gateway) Middleware(service string, h http.Handler) http.Handler

Middleware authenticates, recovers from panics and logs each HTTP request.

func (*Gateway) Register

func (g *Gateway) Register(s emu.Service) error

Register calls s.Register and records which gRPC services it added.

func (*Gateway) Router

func (g *Gateway) Router(service string) emu.Router

Router returns the registration surface for one service.

func (*Gateway) Serve

func (g *Gateway) Serve(l net.Listener) error

Serve serves on l until Shutdown.

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

func (g *Gateway) SetAdminToken(tok string)

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.

func (*Gateway) Shutdown

func (g *Gateway) Shutdown(ctx context.Context) error

Shutdown stops the gateway.

Jump to

Keyboard shortcuts

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