Documentation
¶
Overview ¶
Package tryit provides "Try It" functionality for invoking Connect/gRPC services.
Index ¶
- Variables
- func FilterHeaders(headers map[string]string, allowlist []string) map[string]string
- func IsSensitiveHeader(name string) bool
- func MergeHeaders(base, override map[string]string) map[string]string
- func RedactSensitiveHeaders(headers map[string][]string) map[string][]string
- func RedactSensitiveHeadersSingle(headers map[string]string) map[string]string
- func ValidateJSONSize(jsonBody string, maxBytes int64) error
- type ConnectInvoker
- type GRPCInvoker
- type GRPCWebInvoker
- type InvocationError
- type Invoker
- type Request
- type Response
- type Transport
Constants ¶
This section is empty.
Variables ¶
var SensitiveHeaders = []string{
"authorization",
"cookie",
"set-cookie",
"proxy-authorization",
"www-authenticate",
"x-api-key",
"api-key",
}
SensitiveHeaders is a list of headers that should never be logged or displayed.
Functions ¶
func FilterHeaders ¶
FilterHeaders filters headers through an allowlist. If the allowlist is empty, all headers are allowed. Returns a new map with only allowed headers (case-insensitive matching).
func IsSensitiveHeader ¶
IsSensitiveHeader returns true if the header name is considered sensitive.
func MergeHeaders ¶
MergeHeaders merges two header maps, with override taking precedence. Case is preserved from the override map.
func RedactSensitiveHeaders ¶
RedactSensitiveHeaders removes sensitive header values from a header map. Returns a new map with sensitive values replaced with "[REDACTED]".
func RedactSensitiveHeadersSingle ¶
RedactSensitiveHeadersSingle is like RedactSensitiveHeaders but for map[string]string.
func ValidateJSONSize ¶
ValidateJSONSize checks if the JSON body size is within limits.
Types ¶
type ConnectInvoker ¶
type ConnectInvoker struct {
// contains filtered or unexported fields
}
ConnectInvoker implements the Invoker interface for the Connect protocol.
func NewConnectInvoker ¶
func NewConnectInvoker() *ConnectInvoker
NewConnectInvoker creates a new Connect invoker.
type GRPCInvoker ¶
type GRPCInvoker struct {
}
GRPCInvoker implements the Invoker interface for the gRPC protocol.
type GRPCWebInvoker ¶
type GRPCWebInvoker struct {
// contains filtered or unexported fields
}
GRPCWebInvoker implements the Invoker interface for the gRPC-Web protocol.
func NewGRPCWebInvoker ¶
func NewGRPCWebInvoker() *GRPCWebInvoker
NewGRPCWebInvoker creates a new gRPC-Web invoker.
type InvocationError ¶
type InvocationError struct {
// Code is the error code (gRPC code or HTTP status code).
Code int
// Message is the error message.
Message string
// Details contains additional error details (e.g., gRPC error details).
Details []string
}
InvocationError represents detailed error information from an invocation.
type Invoker ¶
type Invoker interface {
// Invoke executes an RPC and returns the response.
Invoke(ctx context.Context, req *Request) (*Response, error)
}
Invoker represents a transport-agnostic RPC invoker.
type Request ¶
type Request struct {
// Environment is the name of the configured environment to invoke against.
Environment string
// MethodDescriptor is the protobuf method descriptor for the RPC.
MethodDescriptor protoreflect.MethodDescriptor
// JSONBody is the user-provided JSON request body (to be converted to protobuf).
JSONBody string
// Headers are additional HTTP/metadata headers to include with the request.
// These should already be filtered through the header allowlist.
Headers map[string]string
// BaseURL is the base URL of the upstream service (from environment config).
BaseURL string
// Timeout is the maximum duration for the request.
Timeout time.Duration
// InsecureSkipVerify indicates whether to skip TLS certificate verification.
InsecureSkipVerify bool
}
Request represents a "Try It" invocation request.
func (*Request) InputMessageDescriptor ¶
func (r *Request) InputMessageDescriptor() protoreflect.MessageDescriptor
InputMessageDescriptor returns the descriptor for the input message type.
func (*Request) MethodFullName ¶
MethodFullName returns the fully-qualified method name in the format "package.Service/Method".
func (*Request) OutputMessageDescriptor ¶
func (r *Request) OutputMessageDescriptor() protoreflect.MessageDescriptor
OutputMessageDescriptor returns the descriptor for the output message type.
type Response ¶
type Response struct {
// Status is the HTTP status code (for Connect) or gRPC status code.
Status int
// StatusText is a human-readable status description.
StatusText string
// Headers are the response headers/metadata returned by the server.
// Sensitive headers should be redacted before returning to the user.
Headers map[string][]string
// JSONBody is the response body converted to JSON for display.
JSONBody string
// Latency is the total time taken for the request (including network and processing).
Latency time.Duration
// Error contains error details if the invocation failed.
Error *InvocationError
}
Response represents the result of an RPC invocation.
type Transport ¶
type Transport string
Transport represents the RPC transport protocol.
func ParseTransport ¶
ParseTransport converts a string to a Transport type.