go-tsviewer/features/web/index/handler.go

32 lines
686 B
Go

package index
import (
"html/template"
"net/http"
"git.cliffbreak.de/Cliffbreak/tsviewer/features/web/weberror"
)
func IndexGUIHandler(s Service, t template.Template) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server, err := s.ServerInfo()
if err != nil {
weberror.NewPage(err, http.StatusNotFound).Send(w, t)
return
}
channels, err := s.ChannelsRaw()
if err != nil {
weberror.NewPage(err, http.StatusNotFound).Send(w, t)
return
}
clients, err := s.Clients()
if err != nil {
weberror.NewPage(err, http.StatusNotFound).Send(w, t)
return
}
NewPage(*server, channels, clients).Send(w, t)
})
}