api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package api implements the Forky HTTP API as defined by the OpenAPI spec at api/openapi.yaml. The handlers implement the ogen-generated rest.Handler interface and map domain types onto the generated schema types, so the wire format is enforced by the spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	EdgeCacheConfig EdgeCacheConfig `yaml:"edge_cache" default:"{}"`
}

func (*Config) Validate

func (c *Config) Validate() error

type EdgeCacheConfig

type EdgeCacheConfig struct {
	Enabled bool `yaml:"enabled" default:"true"`

	FrameTTL human.Duration `yaml:"frame_ttl" default:"1440m"`
}

func (*EdgeCacheConfig) Validate

func (c *EdgeCacheConfig) Validate() error

type HTTP

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

HTTP serves the Forky API over HTTP.

func NewHTTP

func NewHTTP(log logrus.FieldLogger, svc *service.ForkChoice, config *Config, opts *Options) (*HTTP, error)

NewHTTP creates a new HTTP API around the fork-choice service.

func (*HTTP) GetEthereumNow

func (h *HTTP) GetEthereumNow(ctx context.Context) (rest.GetEthereumNowRes, error)

GetEthereumNow implements getEthereumNow: the current wall-clock slot and epoch.

func (*HTTP) GetEthereumSpec

func (h *HTTP) GetEthereumSpec(ctx context.Context) (rest.GetEthereumSpecRes, error)

GetEthereumSpec implements getEthereumSpec: the configured network name and spec.

func (*HTTP) GetFrame

func (h *HTTP) GetFrame(ctx context.Context, params rest.GetFrameParams) (rest.GetFrameRes, error)

GetFrame implements getFrame: a single fork-choice frame by ID.

func (*HTTP) Handler

func (h *HTTP) Handler() (http.Handler, error)

Handler returns the http.Handler serving the API, instrumented with per-route metrics.

func (*HTTP) ListMetadata

func (h *HTTP) ListMetadata(ctx context.Context, req *rest.MetadataQuery) (rest.ListMetadataRes, error)

ListMetadata implements listMetadata: a page of frame metadata.

func (*HTTP) ListMetadataEpochs

func (h *HTTP) ListMetadataEpochs(ctx context.Context, req *rest.MetadataQuery) (rest.ListMetadataEpochsRes, error)

ListMetadataEpochs implements listMetadataEpochs: distinct epochs.

func (*HTTP) ListMetadataLabels

func (h *HTTP) ListMetadataLabels(ctx context.Context, req *rest.MetadataQuery) (rest.ListMetadataLabelsRes, error)

ListMetadataLabels implements listMetadataLabels: distinct labels.

func (*HTTP) ListMetadataNodes

func (h *HTTP) ListMetadataNodes(ctx context.Context, req *rest.MetadataQuery) (rest.ListMetadataNodesRes, error)

ListMetadataNodes implements listMetadataNodes: distinct node names.

func (*HTTP) ListMetadataSlots

func (h *HTTP) ListMetadataSlots(ctx context.Context, req *rest.MetadataQuery) (rest.ListMetadataSlotsRes, error)

ListMetadataSlots implements listMetadataSlots: distinct slots.

func (*HTTP) NewError

func (h *HTTP) NewError(_ context.Context, err error) *rest.UnexpectedErrorStatusCode

NewError maps handler errors onto the spec's default error response.

type Metrics

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

Metrics records request/response counts and durations per route.

func NewMetrics

func NewMetrics(enabled bool, namespace string) Metrics

NewMetrics creates the API metrics collectors, registering them when enabled.

func (Metrics) ObserveRequest

func (m Metrics) ObserveRequest(method, path string)

ObserveRequest records an incoming request.

func (Metrics) ObserveResponse

func (m Metrics) ObserveResponse(method, path, code, encoding string, duration time.Duration)

ObserveResponse records a completed response.

type Options

type Options struct {
	MetricsEnabled bool
}

func DefaultOptions

func DefaultOptions() *Options

func (*Options) SetMetricsEnabled

func (o *Options) SetMetricsEnabled(enabled bool) *Options

func (*Options) Validate

func (o *Options) Validate() error

func (*Options) WithMetricsDisabled

func (o *Options) WithMetricsDisabled() *Options

func (*Options) WithMetricsEnabled

func (o *Options) WithMetricsEnabled() *Options

Jump to

Keyboard shortcuts

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