erigon-pulse/cl/beacon/router.go
Enrique Jose Avila Asapche 1cb1c303d4
added a listener for beacon api and added get genesis (#7659)
Added two new flags beacon.api.port and beacon.api.addr

Now we can listen for beacon api and get beacon genesis

---------

Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
2023-06-08 09:43:27 +02:00

38 lines
931 B
Go

package beacon
import (
"net"
"net/http"
"time"
"github.com/ledgerwatch/erigon/cl/beacon/handler"
"github.com/ledgerwatch/log/v3"
)
// TODO(enriavil1): Make this configurable via flags
type RouterConfiguration struct {
Protocol string
Address string
ReadTimeTimeout time.Duration
IdleTimeout time.Duration
WriteTimeout time.Duration
}
func ListenAndServe(api *handler.ApiHandler, routerCfg *RouterConfiguration) {
listener, err := net.Listen(routerCfg.Protocol, routerCfg.Address)
server := &http.Server{
Handler: api,
ReadTimeout: routerCfg.ReadTimeTimeout,
IdleTimeout: routerCfg.IdleTimeout,
WriteTimeout: routerCfg.IdleTimeout,
}
if err != nil {
log.Warn("[Beacon API] Failed to start listening", "addr", routerCfg.Address, "err", err)
}
if err := server.Serve(listener); err != nil {
log.Warn("[Beacon API] failed to start serving", "addr", routerCfg.Address, "err", err)
}
}