package node import ( "fmt" "net/http" "text/template" ) const debugText = ` Node status: {{.Name}}
Name: {{.Name}}
Master: {{if .IsMaster}}YES{{else}}NO{{end}}
Icecast: {{if .IcecastUp}}OK{{else}}DOWN{{end}}
Bandwidth: {{.BandwidthUsage}}%

Transcoders

{{if .Transcoders}} {{range .Transcoders}} {{end}}
Source Target Mount Format Bitrate/Q
{{.SourceURL}} {{.TargetIP}}:{{.TargetPort}} {{.TargetMount}} {{.Format}} {{if gt .BitRate 0}}{{.BitRate}}{{else}}{{.Quality}}{{end}}
{{else}}

No active transcoders on this node.

{{end}} ` var ( debugTmpl = template.Must(template.New("node debug").Parse(debugText)) ) // ServeHTTP serves the debug console. func (rc *RadioNode) ServeHTTP(w http.ResponseWriter, r *http.Request) { rc.transcodersMx.Lock() var transcoders []*transcoder for _, t := range rc.transcoders { transcoders = append(transcoders, t) } rc.transcodersMx.Unlock() ctx := struct { Name string IsMaster bool IcecastUp bool BandwidthUsage float64 Transcoders []*transcoder }{ Name: rc.name, IsMaster: rc.me.IsMaster(), IcecastUp: rc.icecast.GetStatus().Up, BandwidthUsage: rc.bw.GetUsage(), Transcoders: transcoders, } err := debugTmpl.Execute(w, &ctx) if err != nil { fmt.Fprintln(w, "debug: error executing template: ", err.Error()) } }