Include config in status response and push on SIGHUP
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
16
http.go
16
http.go
@@ -25,6 +25,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StatusResponse struct {
|
type StatusResponse struct {
|
||||||
|
Config *Config `json:"config"`
|
||||||
Nodes []*Node `json:"nodes"`
|
Nodes []*Node `json:"nodes"`
|
||||||
Links []*Link `json:"links"`
|
Links []*Link `json:"links"`
|
||||||
MulticastGroups []*MulticastGroupMembers `json:"multicast_groups"`
|
MulticastGroups []*MulticastGroupMembers `json:"multicast_groups"`
|
||||||
@@ -45,7 +46,6 @@ func (t *Tendrils) startHTTPServer() {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/api/status", t.handleAPIStatus)
|
mux.HandleFunc("/api/status", t.handleAPIStatus)
|
||||||
mux.HandleFunc("/api/status/stream", t.handleAPIStatusStream)
|
mux.HandleFunc("/api/status/stream", t.handleAPIStatusStream)
|
||||||
mux.HandleFunc("/api/config", t.handleAPIConfig)
|
|
||||||
mux.HandleFunc("/api/errors/clear", t.handleClearError)
|
mux.HandleFunc("/api/errors/clear", t.handleClearError)
|
||||||
mux.Handle("/", http.FileServer(http.Dir("static")))
|
mux.Handle("/", http.FileServer(http.Dir("static")))
|
||||||
|
|
||||||
@@ -124,22 +124,18 @@ func (t *Tendrils) handleAPIStatus(w http.ResponseWriter, r *http.Request) {
|
|||||||
json.NewEncoder(w).Encode(status)
|
json.NewEncoder(w).Encode(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tendrils) handleAPIConfig(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
if t.config == nil {
|
|
||||||
json.NewEncoder(w).Encode(&Config{})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
json.NewEncoder(w).Encode(t.config)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Tendrils) GetStatus() *StatusResponse {
|
func (t *Tendrils) GetStatus() *StatusResponse {
|
||||||
var broadcastStats *BroadcastStatsResponse
|
var broadcastStats *BroadcastStatsResponse
|
||||||
if t.broadcast != nil {
|
if t.broadcast != nil {
|
||||||
stats := t.broadcast.GetStats()
|
stats := t.broadcast.GetStats()
|
||||||
broadcastStats = &stats
|
broadcastStats = &stats
|
||||||
}
|
}
|
||||||
|
config := t.config
|
||||||
|
if config == nil {
|
||||||
|
config = &Config{}
|
||||||
|
}
|
||||||
return &StatusResponse{
|
return &StatusResponse{
|
||||||
|
Config: config,
|
||||||
Nodes: t.getNodes(),
|
Nodes: t.getNodes(),
|
||||||
Links: t.getLinks(),
|
Links: t.getLinks(),
|
||||||
MulticastGroups: t.getMulticastGroups(),
|
MulticastGroups: t.getMulticastGroups(),
|
||||||
|
|||||||
@@ -1725,13 +1725,10 @@
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
evtSource.addEventListener('status', async (event) => {
|
evtSource.addEventListener('status', (event) => {
|
||||||
resetHeartbeat();
|
resetHeartbeat();
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
if (!currentConfig) {
|
currentConfig = data.config || {};
|
||||||
const configResp = await fetch('/api/config');
|
|
||||||
currentConfig = await configResp.json();
|
|
||||||
}
|
|
||||||
render(data, currentConfig);
|
render(data, currentConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ func (t *Tendrils) Run() {
|
|||||||
}
|
}
|
||||||
t.config = cfg
|
t.config = cfg
|
||||||
log.Printf("reloaded config from %s", t.ConfigFile)
|
log.Printf("reloaded config from %s", t.ConfigFile)
|
||||||
|
t.NotifyUpdate()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user