From 0c8741027527e369e3c1d946bd2eba1acc7a4119 Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Tue, 8 Oct 2024 12:20:29 +0200 Subject: [PATCH] fix linting errors (#2) --- metrics/metrics.go | 1 + proxy/cert_gen.go | 8 ++++++-- proxy/confighub.go | 1 + proxy/proxy.go | 15 ++++++++++----- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index dc47590..6711c76 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -1,3 +1,4 @@ +// Package metrics provides a way to collect and expose metrics for the application. package metrics import "github.com/VictoriaMetrics/metrics" diff --git a/proxy/cert_gen.go b/proxy/cert_gen.go index 466c86a..f1c3e27 100644 --- a/proxy/cert_gen.go +++ b/proxy/cert_gen.go @@ -13,10 +13,14 @@ import ( "time" ) -// hosts is a list of ip / dns names for the certificate +// GenerateCert generated a TLS certificate and key. +// - `hosts`: a list of ip / dns names to include in the certificate func GenerateCert(validFor time.Duration, hosts []string) (cert, key []byte, err error) { // copied from https://go.dev/src/crypto/tls/generate_cert.go priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + return nil, nil, err + } keyUsage := x509.KeyUsageDigitalSignature notBefore := time.Now() @@ -75,5 +79,5 @@ func GenerateCert(validFor time.Duration, hosts []string) (cert, key []byte, err return nil, nil, err } key = keyOut.Bytes() - return + return cert, key, nil } diff --git a/proxy/confighub.go b/proxy/confighub.go index 121a60e..930ebb7 100644 --- a/proxy/confighub.go +++ b/proxy/confighub.go @@ -1,3 +1,4 @@ +// Package proxy provides the main proxy server. package proxy import "github.com/ethereum/go-ethereum/common" diff --git a/proxy/proxy.go b/proxy/proxy.go index 744b61c..d3c31e9 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -48,8 +48,8 @@ func New(config Config) (*Proxy, error) { func (prx *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/cert" { - w.Header().Add("content-type", "application/octet-stream") - w.Write(prx.publicCertPEM) + w.Header().Add("Content-Type", "application/octet-stream") + w.Write(prx.publicCertPEM) //nolint: errcheck return } @@ -63,7 +63,7 @@ func (prx *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { Timeout: 1 * time.Second, } - req, err := http.NewRequest("POST", prx.Config.BuilderEndpoint, bytes.NewBuffer(body)) + req, err := http.NewRequest(http.MethodPost, prx.Config.BuilderEndpoint, bytes.NewBuffer(body)) if err != nil { prx.log.Error("Failed to create a req to the local builder", "err", err) return @@ -122,7 +122,9 @@ func (prx *Proxy) StartServersInBackground() error { Handler: prx, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{*prx.certificate}, + MinVersion: tls.VersionTLS13, }, + ReadHeaderTimeout: 2 * time.Second, } go func() { prx.log.Info("Starting orderflow users input", "addr", srvUsers.Addr) @@ -137,7 +139,9 @@ func (prx *Proxy) StartServersInBackground() error { Handler: prx, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{*prx.certificate}, + MinVersion: tls.VersionTLS13, }, + ReadHeaderTimeout: 2 * time.Second, } go func() { prx.log.Info("Starting orderflow network input", "addr", srvNetwork.Addr) @@ -148,8 +152,9 @@ func (prx *Proxy) StartServersInBackground() error { // cert server srvCert := &http.Server{ - Addr: prx.Config.CertListenAddr, - Handler: prx, + Addr: prx.Config.CertListenAddr, + Handler: prx, + ReadHeaderTimeout: 2 * time.Second, } go func() { prx.log.Info("Starting cert server", "addr", srvCert.Addr)