Open Web UI in Browser Automatically (#7481)

* open web

* Update shared/browser/browser_test.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* Update shared/browser/browser.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* add to depz.bazel

* run gazelle

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Raul Jordan
2020-10-09 14:51:46 -05:00
committed by GitHub
parent 650ec797da
commit a3a77ab5a8
9 changed files with 153 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ go_library(
visibility = ["//validator:__subpackages__"],
deps = [
"//shared:go_default_library",
"//shared/browser:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

View File

@@ -5,8 +5,6 @@ import (
"net/http"
"net/url"
"path"
log "github.com/sirupsen/logrus"
)
const prefix = "external/prysm_web_ui"

View File

@@ -6,10 +6,14 @@ import (
"time"
"github.com/prysmaticlabs/prysm/shared"
log "github.com/sirupsen/logrus"
"github.com/prysmaticlabs/prysm/shared/browser"
"github.com/sirupsen/logrus"
)
var _ = shared.Service(&Server{})
var (
_ = shared.Service(&Server{})
log = logrus.WithField("prefix", "prysm-web")
)
// Server for the Prysm Web UI.
type Server struct {
@@ -37,6 +41,16 @@ func (s *Server) Start() {
log.WithError(err).Error("Failed to start validator web server")
}
}()
time.Sleep(time.Second * 1)
cmd, err := browser.Command("http://" + s.http.Addr)
if err != nil {
log.WithError(err).Errorf("Could not open Prysm web UI in browser")
return
}
if err := cmd.Run(); err != nil {
log.WithError(err).Errorf("Could not open Prysm web UI in browser")
return
}
}
// Stop the web server gracefully with 1s timeout.