|
|
@@ -3,11 +3,14 @@ package control |
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
"github.com/jan/fm-rds-tx/internal/config" |
|
|
"github.com/jan/fm-rds-tx/internal/config" |
|
|
|
|
|
drypkg "github.com/jan/fm-rds-tx/internal/dryrun" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type Server struct { |
|
|
type Server struct { |
|
|
|
|
|
mu sync.RWMutex |
|
|
cfg config.Config |
|
|
cfg config.Config |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -17,6 +20,7 @@ func (s *Server) Handler() http.Handler { |
|
|
mux := http.NewServeMux() |
|
|
mux := http.NewServeMux() |
|
|
mux.HandleFunc("/healthz", s.handleHealth) |
|
|
mux.HandleFunc("/healthz", s.handleHealth) |
|
|
mux.HandleFunc("/status", s.handleStatus) |
|
|
mux.HandleFunc("/status", s.handleStatus) |
|
|
|
|
|
mux.HandleFunc("/dry-run", s.handleDryRun) |
|
|
return mux |
|
|
return mux |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -26,12 +30,25 @@ func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (s *Server) handleStatus(w http.ResponseWriter, _ *http.Request) { |
|
|
func (s *Server) handleStatus(w http.ResponseWriter, _ *http.Request) { |
|
|
|
|
|
s.mu.RLock() |
|
|
|
|
|
cfg := s.cfg |
|
|
|
|
|
s.mu.RUnlock() |
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
_ = json.NewEncoder(w).Encode(map[string]any{ |
|
|
_ = json.NewEncoder(w).Encode(map[string]any{ |
|
|
"service": "fm-rds-tx", |
|
|
"service": "fm-rds-tx", |
|
|
"backend": s.cfg.Backend.Kind, |
|
|
|
|
|
"frequencyMHz": s.cfg.FM.FrequencyMHz, |
|
|
|
|
|
"stereoEnabled": s.cfg.FM.StereoEnabled, |
|
|
|
|
|
"rdsEnabled": s.cfg.RDS.Enabled, |
|
|
|
|
|
|
|
|
"backend": cfg.Backend.Kind, |
|
|
|
|
|
"frequencyMHz": cfg.FM.FrequencyMHz, |
|
|
|
|
|
"stereoEnabled": cfg.FM.StereoEnabled, |
|
|
|
|
|
"rdsEnabled": cfg.RDS.Enabled, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) handleDryRun(w http.ResponseWriter, _ *http.Request) { |
|
|
|
|
|
s.mu.RLock() |
|
|
|
|
|
cfg := s.cfg |
|
|
|
|
|
s.mu.RUnlock() |
|
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
|
|
_ = json.NewEncoder(w).Encode(drypkg.Generate(cfg)) |
|
|
|
|
|
} |