intake/web/root.go

36 lines
721 B
Go

package web
import (
"net/http"
"github.com/Jaculabilis/intake/core"
"github.com/Jaculabilis/intake/web/html"
)
type SourceData struct {
Name string
}
type HomeData struct {
Sources []SourceData
}
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 []SourceData
for _, name := range names {
sources = append(sources, SourceData{name})
}
data := HomeData{sources}
html.Home(writer, data)
}
func (env *Env) styleHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header()["Cache-Control"] = []string{"public, max-age=86400"}
writer.Write(html.Stylesheet)
}