Documentation
¶
Overview ¶
Package connectaip provides the runtime for AIP-shaped REST endpoints generated by the protoc-gen-aip-{go,ts,py} plugins.
The runtime forwards HTTP requests received on AIP-style routes (e.g. POST /v1/resources, GET /v1/resources/{name}) to the corresponding Connect RPC procedure handlers. Server-streaming methods are forwarded to a connect-sse Server (see github.com/firetiger-oss/connect-sse).
Most users will not import this package directly; instead, run protoc-gen-aip-go on services with google.api.http annotations and call the generated NewServiceAIPHandler / NewServiceAIPClient constructors.
Index ¶
- func Forward[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler)
- func ForwardWithBody[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler, ...)
- func ForwardWithPathVars[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler, ...)
- func Handle(mux *http.ServeMux, handlers iter.Seq2[string, http.Handler])
- func NewLoopbackTransport(handler http.Handler) http.RoundTripper
- func NewSSEClient(httpClient connect.HTTPClient, rawURL string, ...) connect.HTTPClient
- func SSEProcedureURL(baseURL, procedure string) string
- func SplitMultiWildcard(val, prefix, sep string, idx int) string
- type Client
- type ClientOption
- type MethodSpec
- type PathVar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Forward ¶
func Forward[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler)
Forward clones the request, rewrites URL/method, and forwards to the ConnectRPC handler. Used for POST/PATCH with body: "*" and no path variables.
func ForwardWithBody ¶
func ForwardWithBody[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler, reqMsg Req)
ForwardWithBody clones the request, applies path vars and query params, and forwards. Used for GET/DELETE requests.
func ForwardWithPathVars ¶
func ForwardWithPathVars[Req, Resp proto.Message](w http.ResponseWriter, req *http.Request, path string, handler http.Handler, pathVarsMsg Req)
ForwardWithPathVars clones the request, merges path variables into the body, and forwards. Used for POST/PATCH with body: "*" and path variables.
func NewLoopbackTransport ¶
func NewLoopbackTransport(handler http.Handler) http.RoundTripper
NewLoopbackTransport returns an http.RoundTripper that dispatches every request directly to the provided handler, bypassing the network. This lets in-process callers use a generated REST client (which speaks HTTP) to invoke the same mux that the external API handlers are registered on — no TCP, no port binding, no startup ordering gymnastics.
Wrap it in &http.Client{Transport: ...} at the call site. Returning the transport (not a *http.Client) keeps the primitive composable with other RoundTripper middleware (auth, tracing, retry) and avoids inheriting default-Client behaviors like redirect following and a cookie jar that don't make sense for loopback traffic.
Use this to wire REST clients to the api_server's own mux for service-to-service calls that used to be in-process ConnectRPC calls.
func NewSSEClient ¶
func NewSSEClient(httpClient connect.HTTPClient, rawURL string, pathVarFn func([]byte) iter.Seq2[string, string], opts ...ClientOption) connect.HTTPClient
NewSSEClient creates a connect.HTTPClient suitable for server-streaming REST calls via SSE. rawURL is the full target URL (e.g. baseURL+"/v2/query"); url.Parse is used to decode it. pathVarFn, if non-nil, is called with the JSON-encoded message from each request to substitute path-variable placeholders (e.g. "{name}") in the URL.
func SSEProcedureURL ¶
SSEProcedureURL returns the URL to pass to connect.NewClient for server-streaming REST methods. It strips any path component from baseURL so that the Connect procedure path is not prefixed in the nested SSE request (which would break handler dispatch).
func SplitMultiWildcard ¶
SplitMultiWildcard extracts one segment from a multi-wildcard resource name. It trims prefix from val, splits on sep, and returns the element at idx. If the split produces fewer parts than idx+1 (malformed name), it returns "".
This is used in generated PathVars helpers for patterns like {name=agents/*/slos/*}.
Types ¶
type Client ¶
type Client[Req, Resp any] struct { // contains filtered or unexported fields }
Client is a generic REST client for a single method. It uses connect.HTTPClient for compatibility with ConnectRPC clients.
func NewClient ¶
func NewClient[Req, Resp any]( httpClient connect.HTTPClient, baseURL string, spec MethodSpec, pathVarFn func(*Req) map[string]string, queryFn func(*Req) map[string]string, opts ...ClientOption, ) *Client[Req, Resp]
NewClient creates a new REST method client.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption configures a Client.
func WithHeader ¶
func WithHeader(key, value string) ClientOption
WithHeader adds a header to all requests made by the client.
func WithInterceptors ¶
func WithInterceptors(interceptors ...connect.UnaryInterceptorFunc) ClientOption
WithInterceptors adds interceptors that run before each request. Interceptors see a connect.AnyRequest with the proto message and HTTP headers, and can modify headers (e.g., inject Authorization) before the request is sent. This matches the ConnectRPC connect.WithInterceptors() pattern.
type MethodSpec ¶
type MethodSpec struct {
HTTPMethod string // GET, POST, PATCH, DELETE, PUT
URLPattern string // e.g., "/v1/credentials/{name}"
PathVars []PathVar // path variable extraction info
}
MethodSpec describes a REST method's HTTP configuration.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
protoc-gen-aip-go
command
protoc-gen-aip-go generates AIP-shaped REST/HTTP handlers and clients for ConnectRPC services.
|
protoc-gen-aip-go generates AIP-shaped REST/HTTP handlers and clients for ConnectRPC services. |
|
protoc-gen-aip-py
command
|
|
|
protoc-gen-aip-ts
command
|
|
|
internal
|
|