diff --git a/cmd/serve.go b/cmd/serve.go index 812747e..e5cefbd 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,18 +1,17 @@ package cmd import ( - "log" - + "github.com/Jaculabilis/intake/web" "github.com/spf13/cobra" ) var serveCmd = &cobra.Command{ Use: "serve", Short: "Serve the web interface", - Long: ` + Long: `Serve the intake web interface. `, Run: func(cmd *cobra.Command, args []string) { - log.Fatal("not implemented") + web.RunServer() }, } diff --git a/web/html/home.html b/web/html/home.html new file mode 100644 index 0000000..881e323 --- /dev/null +++ b/web/html/home.html @@ -0,0 +1 @@ +{{ define "content" }}

Hello {{ . }}

{{ end }} diff --git a/web/html/html.go b/web/html/html.go new file mode 100644 index 0000000..62d1904 --- /dev/null +++ b/web/html/html.go @@ -0,0 +1,20 @@ +package html + +import ( + "embed" + "html/template" + "io" +) + +//go:embed *.html +var templates embed.FS + +func load(file string) *template.Template { + return template.Must(template.New("layout.html").ParseFS(templates, "layout.html", file)) +} + +var home = load("home.html") + +func Home(writer io.Writer, data any) error { + return home.Execute(writer, data) +} diff --git a/web/html/layout.html b/web/html/layout.html new file mode 100644 index 0000000..f827cde --- /dev/null +++ b/web/html/layout.html @@ -0,0 +1,8 @@ + + +Intake + + +{{ template "content" . }} + + diff --git a/web/root.go b/web/root.go new file mode 100644 index 0000000..c5d5ed1 --- /dev/null +++ b/web/root.go @@ -0,0 +1,19 @@ +package web + +import ( + "log" + "net/http" + + "github.com/Jaculabilis/intake/web/html" +) + +func rootHandler(writer http.ResponseWriter, req *http.Request) { + log.Printf("%s %s", req.Method, req.URL.Path) + html.Home(writer, "world") +} + +func RunServer() { + http.HandleFunc("/", rootHandler) + + log.Fatal(http.ListenAndServe("localhost:8081", nil)) +}