|
- package control
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/jan/fm-rds-tx/internal/config"
- )
-
- type Server struct {
- cfg config.Config
- }
-
- func NewServer(cfg config.Config) *Server { return &Server{cfg: cfg} }
-
- func (s *Server) Handler() http.Handler {
- mux := http.NewServeMux()
- mux.HandleFunc("/healthz", s.handleHealth)
- mux.HandleFunc("/status", s.handleStatus)
- return mux
- }
-
- func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _ = json.NewEncoder(w).Encode(map[string]any{"ok": true})
- }
-
- func (s *Server) handleStatus(w http.ResponseWriter, _ *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- _ = json.NewEncoder(w).Encode(map[string]any{
- "service": "fm-rds-tx",
- "backend": s.cfg.Backend.Kind,
- "frequencyMHz": s.cfg.FM.FrequencyMHz,
- "stereoEnabled": s.cfg.FM.StereoEnabled,
- "rdsEnabled": s.cfg.RDS.Enabled,
- })
- }
|