diff --git a/web/html/layout.html b/web/html/layout.html index 57be7b2..cbdc8d1 100644 --- a/web/html/layout.html +++ b/web/html/layout.html @@ -1,3 +1,4 @@ + diff --git a/web/main.go b/web/main.go index 4d94022..c76225b 100644 --- a/web/main.go +++ b/web/main.go @@ -27,9 +27,9 @@ func RunServer(db *core.DB, addr string, port string) { env := &Env{db} bind := net.JoinHostPort(addr, port) - handleFunc("/", env.rootHandler) - handleFunc("/style.css", env.styleHandler) - handleFunc("/source/", env.sourceHandler) + handleFunc("GET /", env.getRoot) + handleFunc("GET /style.css", env.getStyle) + handleFunc("GET /source/{source}", env.getSource) log.Fatal(http.ListenAndServe(bind, nil)) } diff --git a/web/root.go b/web/root.go index 80da95f..db247d0 100644 --- a/web/root.go +++ b/web/root.go @@ -7,7 +7,12 @@ import ( "github.com/Jaculabilis/intake/web/html" ) -func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) { +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())) @@ -23,7 +28,7 @@ func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) { html.Home(writer, data) } -func (env *Env) styleHandler(writer http.ResponseWriter, req *http.Request) { +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) diff --git a/web/source.go b/web/source.go index 3d296f7..e576c15 100644 --- a/web/source.go +++ b/web/source.go @@ -7,8 +7,13 @@ import ( "github.com/Jaculabilis/intake/web/html" ) -func (env *Env) sourceHandler(writer http.ResponseWriter, req *http.Request) { - source := req.URL.Path[len("/source/"):] +func (env *Env) getSource(writer http.ResponseWriter, req *http.Request) { + source := req.PathValue("source") + if source == "" { + http.NotFound(writer, req) + return + } + // TODO this needs to properly error if the source doesn't exist instead of just returning [] items, err := core.GetAllItemsForSource(env.db, source) if err != nil {