From 3dfa497689815bdee774c8561c3c6243a933a05d Mon Sep 17 00:00:00 2001 From: leah Date: Thu, 27 Jan 2022 20:21:09 +0000 Subject: [PATCH] template bits --- .gitignore | 7 +++++-- main.go | 30 +++++++++++++++++++++++++----- resources/main.css | 6 +++--- tailwind.config.js | 7 +++++++ templates/home.html | 12 ++++++++---- 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tailwind.config.js diff --git a/.gitignore b/.gitignore index a4366de..9a190d6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,8 @@ # vendor/ # sensitive data that shouldn't be pushed -data/* -config.yml \ No newline at end of file +data/ +config.yml + +# build bits +resources/build/ \ No newline at end of file diff --git a/main.go b/main.go index dbdbd58..6b977c1 100644 --- a/main.go +++ b/main.go @@ -2,20 +2,24 @@ package main import ( "fmt" - "html" "io/ioutil" "log" "net/http" + "text/template" "gopkg.in/yaml.v3" ) +// Config types +// ------------ type ServerConfig struct { Name string Homepage string } type AdminConfig struct { WebRoot string + Port int + LogPath string } type AuthConfig struct { GiteaURL string @@ -39,15 +43,31 @@ func loadConfig() (err error) { return err } +func handler(w http.ResponseWriter, r *http.Request) { + path := r.URL.Path + var tmpl string + if path == "/" { + tmpl = "templates/home.html" + } else { + tmpl = fmt.Sprintf("templates/%s", path) + } + t, _ := template.ParseFiles(tmpl) + t.Execute(w, config) +} + func main() { err := loadConfig() + fmt.Print(config) + if err != nil { - log.Fatal("oh no !!!") + log.Fatalf("couldn't load config: %s", err) } - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) - }) + http.Handle("/resources/", + http.StripPrefix("/resources/", + http.FileServer(http.Dir("./resources")))) + + http.HandleFunc("/", handler) err = http.ListenAndServe(":8080", nil) if err != nil { diff --git a/resources/main.css b/resources/main.css index 702c286..bd6213e 100644 --- a/resources/main.css +++ b/resources/main.css @@ -1,3 +1,3 @@ -body { - color: purple; -} \ No newline at end of file +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 0000000..cfd5467 --- /dev/null +++ b/tailwind.config.js @@ -0,0 +1,7 @@ +module.exports = { + content: ["./templates/*.html"], + theme: { + extend: {}, + }, + plugins: [], +} diff --git a/templates/home.html b/templates/home.html index 37e1b55..873fbfb 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,14 +1,18 @@ + - { server.name } Admin Panel + {{.Server.Name}} Admin Panel - - + + - +

+ Hello world! +

+ \ No newline at end of file