intake/web/root.go
2025-01-27 21:08:33 -08:00

42 lines
1.0 KiB
Go

package web
import (
"net/http"
"github.com/Jaculabilis/intake/core"
"github.com/Jaculabilis/intake/web/html"
)
func (env *Env) getRoot(writer http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
http.NotFound(writer, req)
return
}
names, err := core.GetSources(env.db)
if err != nil {
writer.Write([]byte(err.Error()))
}
var sources []html.SourceData
for _, name := range names {
sources = append(sources, html.SourceData{Name: name})
}
data := html.HomeData{
Sources: sources,
}
html.Home(writer, data)
}
func (env *Env) getStyle(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"}
writer.Write(html.Stylesheet)
}
func (env *Env) getScript(writer http.ResponseWriter, req *http.Request) {
writer.Header()["Cache-Control"] = []string{"public, max-age=86400"}
writer.Header()["Content-Type"] = []string{"application/javascript; charset=utf-8"}
writer.Write(html.Htmx)
}