intake/web/root.go

31 lines
739 B
Go
Raw Normal View History

2025-01-24 00:18:41 +00:00
package web
import (
"net/http"
2025-01-24 15:15:54 +00:00
"github.com/Jaculabilis/intake/core"
2025-01-24 00:18:41 +00:00
"github.com/Jaculabilis/intake/web/html"
)
2025-01-24 15:15:54 +00:00
func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) {
names, err := core.GetSources(env.db)
if err != nil {
writer.Write([]byte(err.Error()))
}
var sources []html.SourceData
2025-01-24 15:15:54 +00:00
for _, name := range names {
sources = append(sources, html.SourceData{Name: name})
}
data := html.HomeData{
Sources: sources,
2025-01-24 15:15:54 +00:00
}
html.Home(writer, data)
}
2025-01-24 00:18:41 +00:00
2025-01-24 15:15:54 +00:00
func (env *Env) styleHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header()["Cache-Control"] = []string{"public, max-age=86400"}
writer.Header()["Content-Type"] = []string{"text/css; charset=utf-8"}
2025-01-24 15:15:54 +00:00
writer.Write(html.Stylesheet)
2025-01-24 00:18:41 +00:00
}