rest

package
v7.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Code generated by hack/gen-logs.sh; DO NOT EDIT. This file is created and regenerated automatically. Anything added here might get removed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Get(ctx context.Context, endpoint string, resp any) error
	GetStatusCode(ctx context.Context, endpoint string) (int, error)
	GetSSZ(ctx context.Context, endpoint string) ([]byte, http.Header, error)
	Post(ctx context.Context, endpoint string, headers map[string]string, data *bytes.Buffer, resp any) error
	PostSSZ(ctx context.Context, endpoint string, headers map[string]string, data *bytes.Buffer) ([]byte, http.Header, error)
	Host() string
}

Handler defines the interface for making REST API requests.

func NewHandler

func NewHandler(client http.Client, host string) Handler

NewHandler returns a Handler

type MockHandler

type MockHandler struct {
	MockHost string
}

MockHandler implements Handler for testing.

func (*MockHandler) Get

func (m *MockHandler) Get(_ context.Context, _ string, _ any) error

func (*MockHandler) GetSSZ

func (m *MockHandler) GetSSZ(_ context.Context, _ string) ([]byte, http.Header, error)

func (*MockHandler) GetStatusCode

func (m *MockHandler) GetStatusCode(_ context.Context, _ string) (int, error)

func (*MockHandler) Host

func (m *MockHandler) Host() string

func (*MockHandler) Post

func (m *MockHandler) Post(_ context.Context, _ string, _ map[string]string, _ *bytes.Buffer, _ any) error

func (*MockHandler) PostSSZ

func (m *MockHandler) PostSSZ(_ context.Context, _ string, _ map[string]string, _ *bytes.Buffer) ([]byte, http.Header, error)

type MockRestProvider

type MockRestProvider struct {
	MockClient  *http.Client
	MockHandler Handler
	MockHosts   []string
	HostIndex   int
}

MockRestProvider implements RestConnectionProvider for testing.

func (*MockRestProvider) CurrentHost

func (m *MockRestProvider) CurrentHost() string

func (*MockRestProvider) Handler

func (m *MockRestProvider) Handler() Handler

func (*MockRestProvider) Hosts

func (m *MockRestProvider) Hosts() []string

func (*MockRestProvider) HttpClient

func (m *MockRestProvider) HttpClient() *http.Client

func (*MockRestProvider) SwitchHost

func (m *MockRestProvider) SwitchHost(index int) error

type RestConnectionProvider

type RestConnectionProvider interface {
	// HttpClient returns the configured HTTP client with headers, timeout, and optional tracing.
	HttpClient() *http.Client
	// Handler returns the REST handler for making API requests.
	Handler() Handler
	// CurrentHost returns the current REST API endpoint URL.
	CurrentHost() string
	// Hosts returns all configured REST API endpoint URLs.
	Hosts() []string
	// SwitchHost switches to the endpoint at the given index.
	SwitchHost(index int) error
}

RestConnectionProvider manages HTTP client configuration for REST API with failover support. It allows switching between different beacon node REST endpoints when the current one becomes unavailable.

func NewRestConnectionProvider

func NewRestConnectionProvider(endpoint string, opts ...RestConnectionProviderOption) (RestConnectionProvider, error)

NewRestConnectionProvider creates a new REST connection provider that manages HTTP client configuration. The endpoint parameter can be a comma-separated list of URLs (e.g., "http://host1:3500,http://host2:3500").

type RestConnectionProviderOption

type RestConnectionProviderOption func(*restConnectionProvider)

RestConnectionProviderOption is a functional option for configuring the REST connection provider.

func WithHttpHeaders

func WithHttpHeaders(headers map[string][]string) RestConnectionProviderOption

WithHttpHeaders sets custom HTTP headers to include in all requests.

func WithHttpTimeout

func WithHttpTimeout(timeout time.Duration) RestConnectionProviderOption

WithHttpTimeout sets the HTTP client timeout.

func WithTracing

func WithTracing() RestConnectionProviderOption

WithTracing enables OpenTelemetry tracing for HTTP requests.

Jump to

Keyboard shortcuts

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