prysm-pulse/validator/web/server.go
Raul Jordan bec91d348e
Use Password Specific to Web UI Instead of Wallet Password (#7569)
* use password specific to web UI

* fix up a few more tests

* tests passing

* gaz

* fix fmt
2020-10-20 02:26:31 +00:00

58 lines
1.1 KiB
Go

package web
import (
"context"
"net/http"
"time"
"github.com/prysmaticlabs/prysm/shared"
"github.com/sirupsen/logrus"
)
var (
_ = shared.Service(&Server{})
log = logrus.WithField("prefix", "prysm-web")
)
// Server for the Prysm Web UI.
type Server struct {
http *http.Server
}
// NewServer creates a server service for the Prysm web UI.
func NewServer(addr string) *Server {
mux := http.NewServeMux()
mux.HandleFunc("/", webHandler)
return &Server{
http: &http.Server{
Addr: addr,
Handler: mux,
},
}
}
// Start the web server.
func (s *Server) Start() {
go func() {
log.WithField("address", "http://"+s.http.Addr).Info(
"Starting Prysm web UI on address, open in browser to access",
)
if err := s.http.ListenAndServe(); err != nil {
log.WithError(err).Error("Failed to run validator web server")
}
}()
}
// Stop the web server gracefully with 1s timeout.
func (s *Server) Stop() error {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
return s.http.Shutdown(ctx)
}
// Status check for web server. Always returns nil.
func (s *Server) Status() error {
return nil
}