REST API: add a method to get the status of the services

added a status page to the built-in web admin
This commit is contained in:
Nicola Murino
2020-12-08 11:18:34 +01:00
parent 6977a4a18b
commit 50982229e1
22 changed files with 424 additions and 71 deletions

View File

@@ -33,6 +33,7 @@ var (
type webDavServer struct {
config *Configuration
certMgr *common.CertManager
status ServiceStatus
}
func newServer(config *Configuration, configDir string) (*webDavServer, error) {
@@ -53,8 +54,12 @@ func newServer(config *Configuration, configDir string) (*webDavServer, error) {
}
func (s *webDavServer) listenAndServe() error {
addr := fmt.Sprintf("%s:%d", s.config.BindAddress, s.config.BindPort)
s.status.IsActive = true
s.status.Address = addr
s.status.Protocol = "HTTP"
httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%d", s.config.BindAddress, s.config.BindPort),
Addr: addr,
Handler: server,
ReadHeaderTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
@@ -75,6 +80,7 @@ func (s *webDavServer) listenAndServe() error {
httpServer.Handler = server
}
if s.certMgr != nil {
s.status.Protocol = "HTTPS"
httpServer.TLSConfig = &tls.Config{
GetCertificate: s.certMgr.GetCertificateFunc(),
MinVersion: tls.VersionTLS12,