prysm-pulse/beacon-chain/gateway/server/main.go
Raul Jordan 2e33595187
Implement GetBeaconState Endpoint (#5668)
* implement get beacon state
* gaz
* Merge branch 'master' into implement-debug-state
* passing tests
* enable with featureconfig
* struct oder
* Update beacon-chain/rpc/beacon/state.go
* Merge refs/heads/master into implement-debug-state
* lint resolve
* Merge branch 'implement-debug-state' of github.com:prysmaticlabs/prysm into implement-debug-state
* tested at runtime
* fix build
* Merge branch 'master' into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* build and fmt
* conf
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
* Merge refs/heads/master into implement-debug-state
2020-05-01 01:47:10 +00:00

67 lines
1.7 KiB
Go

// Package main allows for creation of an HTTP-JSON to gRPC
// gateway as a binary go process.
package main
import (
"context"
"flag"
"fmt"
"net/http"
"strings"
joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
"github.com/sirupsen/logrus"
_ "go.uber.org/automaxprocs"
)
var (
beaconRPC = flag.String("beacon-rpc", "localhost:4000", "Beacon chain gRPC endpoint")
port = flag.Int("port", 8000, "Port to serve on")
debug = flag.Bool("debug", false, "Enable debug logging")
allowedOrigins = flag.String("corsdomain", "", "A comma separated list of CORS domains to allow")
enableDebugRPCEndpoints = flag.Bool("enable-debug-rpc-endpoints", false, "Enable debug rpc endpoints such as /eth/v1alpha1/beacon/state")
)
func init() {
logrus.SetFormatter(joonix.NewFormatter())
}
var log = logrus.New()
func main() {
flag.Parse()
if *debug {
log.SetLevel(logrus.DebugLevel)
}
mux := http.NewServeMux()
gw := gateway.New(
context.Background(),
*beaconRPC,
fmt.Sprintf("0.0.0.0:%d", *port),
mux,
strings.Split(*allowedOrigins, ","),
*enableDebugRPCEndpoints,
)
mux.HandleFunc("/swagger/", gateway.SwaggerServer())
mux.HandleFunc("/healthz", healthzServer(gw))
gw.Start()
select {}
}
// healthzServer returns a simple health handler which returns ok.
func healthzServer(gw *gateway.Gateway) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
if err := gw.Status(); err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
return
}
if _, err := fmt.Fprintln(w, "ok"); err != nil {
log.WithError(err).Error("failed to respond to healthz")
}
}
}