openapiclient

package
v0.0.0-...-8c81104 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package openapiclient implements a client to proxy requests to external services.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerURLRequired = errors.New("server url is required")
	ErrMetadataRequired  = errors.New("metadata for the proxy client is required")
	ErrNoAvailableServer = errors.New(
		"failed to initialize servers. Require at least 1 server has URL",
	)
)

Functions

func BuildMetadataTree

func BuildMetadataTree(
	document *highv3.Document,
	getEnv goenvconf.GetEnvFunc,
) (*internal.Node, error)

BuildMetadataTree builds the metadata tree from the API document.

Types

type ClientOption

type ClientOption func(*clientOptions)

ClientOption abstracts a function to modify proxy client options.

func AllowTraceRequestHeaders

func AllowTraceRequestHeaders(keys []string) ClientOption

AllowTraceRequestHeaders creates an option to set allowed headers for tracing.

func AllowTraceResponseHeaders

func AllowTraceResponseHeaders(keys []string) ClientOption

AllowTraceResponseHeaders creates an option to set allowed headers for tracing.

func EnableClientTrace

func EnableClientTrace(enabled bool) ClientOption

EnableClientTrace creates an option to enable the HTTP client trace.

func WithAuthenticator

func WithAuthenticator(authenticator authscheme.HTTPClientAuthenticator) ClientOption

WithAuthenticator creates an option to set the default authenticator.

func WithClientOptions

func WithClientOptions(options *gohttpc.ClientOptions) ClientOption

WithClientOptions create an option to set the client options of gohttpc client.

func WithCustomAttributesFunc

func WithCustomAttributesFunc(fn gohttpc.CustomAttributesFunc) ClientOption

WithCustomAttributesFunc sets the function to add custom attributes to spans and metrics.

func WithGetEnvFunc

func WithGetEnvFunc(getter goenvconf.GetEnvFunc) ClientOption

WithGetEnvFunc returns a function to set the GetEnvFunc getter to [HTTPClientAuthenticatorOptions].

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient create an option to set the HTTP client.

func WithMetricHighCardinalityPath

func WithMetricHighCardinalityPath(enabled bool) ClientOption

WithMetricHighCardinalityPath enables high cardinality path on metrics.

func WithRetry

WithRetry creates an option to set the default retry policy.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout creates an option to set the default timeout.

func WithTraceHighCardinalityPath

func WithTraceHighCardinalityPath(enabled bool) ClientOption

WithTraceHighCardinalityPath enables high cardinality path on traces.

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent creates an option to set the user agent.

type ProxyClient

type ProxyClient struct {
	// contains filtered or unexported fields
}

ProxyClient helps manage and execute REST and GraphQL APIs from the API document.

func NewProxyClient

func NewProxyClient(
	ctx context.Context,
	metadata *oaschema.OpenAPIResourceDefinition,
	options ...ClientOption,
) (*ProxyClient, error)

NewProxyClient creates a proxy client from the API document.

func (*ProxyClient) Close

func (pc *ProxyClient) Close() error

Close method performs cleanup and closure activities on the client instance.

func (*ProxyClient) Execute

func (pc *ProxyClient) Execute(
	ctx context.Context,
	method string,
	requestPath string,
	header http.Header,
	body any,
) (*http.Response, any, error)

Execute routes and proxies the request to the remote server.

func (*ProxyClient) ServeHTTP

func (pc *ProxyClient) ServeHTTP(
	writer http.ResponseWriter,
	request *http.Request,
)

func (*ProxyClient) Settings

Settings returns the inner settings of the resource.

func (*ProxyClient) Stream

func (pc *ProxyClient) Stream(
	ctx context.Context,
	writer http.ResponseWriter,
	request *proxyhandler.Request,
) (*http.Response, error)

Stream routes the request to the remote server. The response will be transformed and written into the stream.

Directories

Path Synopsis
Package handler defines the global proxy handler with default constructors
Package handler defines the global proxy handler with default constructors
graphqlhandler
Package graphqlhandler evaluates and execute GraphQL requests to the remote server.
Package graphqlhandler evaluates and execute GraphQL requests to the remote server.
proxyhandler
Package proxyhandler defines types for the proxy handler.
Package proxyhandler defines types for the proxy handler.
resthandler
Package resthandler evaluates and execute REST requests to the remote server.
Package resthandler evaluates and execute REST requests to the remote server.
Package internal implements internal functionality for the proxy client.
Package internal implements internal functionality for the proxy client.

Jump to

Keyboard shortcuts

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