rest

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package rest provides a mesh-aware transport for client-go's rest.Config. It lets a generated clientset resolve a logical service name through the onexmesh registry and load-balance across its instances on every request, without giving up the typed client-go API surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MeshServiceName

func MeshServiceName(host string) (string, bool)

MeshServiceName reports the service name when host is a onexmesh:// reference (e.g. "onexmesh://mb-ginserver" -> "mb-ginserver"), and ok=false otherwise.

func NewForMeshConfig

func NewForMeshConfig(serviceName string, opts ...Option) (*rest.Config, error)

NewForMeshConfig builds a client-go rest.Config whose transport discovers the logical service via the onexmesh registry and load-balances across its instances. The returned config is meant to be passed to a generated clientset's NewForConfig.

The caller owns any TLS configuration: for TLS-backed (https) instances set the returned config's TLSClientConfig (e.g. Insecure or CAData) before use.

func SetDefaultRegistry

func SetDefaultRegistry(name string, opts any)

SetDefaultRegistry forwards to meshclient.SetDefaultRegistry so REST callers can configure the process-wide default registry without importing the gRPC client package.

Types

type Option

type Option func(*options)

Option configures a mesh-aware REST config (see NewForMeshConfig).

func WithBreaker

func WithBreaker(window, probeInterval time.Duration) Option

WithBreaker enables a sliding-window circuit breaker around calls. window is the sliding window duration; probeInterval is how often a request is force-passed while throttling.

func WithBulkhead

func WithBulkhead(maxConcurrent int) Option

WithBulkhead isolates the downstream service by bounding the number of concurrent in-flight requests. A value <= 0 disables the bulkhead.

func WithDiscovery

func WithDiscovery(d registry.Discovery) Option

WithDiscovery injects a pre-built registry.Discovery, taking precedence over WithRegistry.

func WithDiscoveryCache

func WithDiscoveryCache(ttl time.Duration, opts ...cache.Option) Option

WithDiscoveryCache wraps the discovery backend in a read-through cache with the given service TTL. When ttl <= 0 the cache is disabled.

func WithRegistry

func WithRegistry(name string, opts any) Option

WithRegistry selects the registry backend and its options.

func WithRetry

func WithRetry(maxAttempts int, base, max time.Duration) Option

WithRetry enables retry with exponential backoff. base and max are the base and maximum backoff durations.

func WithRetryable

func WithRetryable(f func(error) bool) Option

WithRetryable sets the predicate deciding which errors are retried. When nil, every error surfaced by node selection or transport is retried (those are the only errors that reach the retry layer; HTTP status errors are returned to the caller untouched).

func WithSelector

func WithSelector(s selector.Selector) Option

WithSelector overrides the default round-robin selector.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout imposes a per-call deadline.

Jump to

Keyboard shortcuts

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