Skip to content

Commit

Permalink
feat(beacon): refactor HTTP client initialization to use a parameter …
Browse files Browse the repository at this point in the history
…slice for better flexibility and maintainability

feat(beacon): add methods to Options struct for managing GoEth2Client parameters to enhance configurability
  • Loading branch information
samcm committed Feb 6, 2025
1 parent cad0d3f commit 64a0614
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/beacon/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ func (n *node) ensureClients(ctx context.Context) error {
default:
timeout := 10 * time.Minute

client, err := ehttp.New(ctx,
params := []ehttp.Parameter{
ehttp.WithAddress(n.config.Addr),
ehttp.WithLogLevel(zerologLevel),
ehttp.WithTimeout(timeout),
ehttp.WithExtraHeaders(n.config.Headers),
ehttp.WithEnforceJSON(true), // TODO(sam): HACK: Remove this once we have a proper spec
)
}

params = append(params, n.options.GetGoEth2ClientParams()...)

client, err := ehttp.New(ctx, params...)
if err != nil {
failures++

Expand Down
14 changes: 14 additions & 0 deletions pkg/beacon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package beacon
import (
"time"

ehttp "github.com/attestantio/go-eth2-client/http"
"github.com/ethpandaops/beacon/pkg/human"
)

Expand All @@ -12,6 +13,7 @@ type Options struct {
HealthCheck HealthCheckOptions
PrometheusMetrics bool
DetectEmptySlots bool
GoEth2ClientParams []ehttp.Parameter
}

// EnablePrometheusMetrics enables Prometheus metrics.
Expand Down Expand Up @@ -122,3 +124,15 @@ func DefaultHealthCheckOptions() HealthCheckOptions {
FailedResponses: 3,
}
}

// AddGoEth2ClientParams adds the given parameters to the options.
func (o *Options) AddGoEth2ClientParams(params ...ehttp.Parameter) *Options {
o.GoEth2ClientParams = append(o.GoEth2ClientParams, params...)

return o
}

// GetGoEth2ClientParams returns the parameters for the go-eth2-client.
func (o *Options) GetGoEth2ClientParams() []ehttp.Parameter {
return o.GoEth2ClientParams
}

0 comments on commit 64a0614

Please sign in to comment.