From 5c1af23f658766780cecc65b898e14f48751e836 Mon Sep 17 00:00:00 2001 From: MrMelon Date: Thu, 21 Apr 2022 09:06:14 +0100 Subject: [PATCH] Change homepage to dark mode --- cmd/melon-tools/main.go | 25 +++++++++++++++++++++++-- cmd/melon-tools/pages/index.go.html | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 cmd/melon-tools/pages/index.go.html diff --git a/cmd/melon-tools/main.go b/cmd/melon-tools/main.go index 57a2c11..201392d 100644 --- a/cmd/melon-tools/main.go +++ b/cmd/melon-tools/main.go @@ -4,12 +4,14 @@ import ( "code.mrmelon54.xyz/sean/melon-tools/module/discord" "code.mrmelon54.xyz/sean/melon-tools/module/gitea" "code.mrmelon54.xyz/sean/melon-tools/utils" + _ "embed" "encoding/gob" "fmt" "github.com/google/uuid" "github.com/gorilla/mux" "github.com/gorilla/sessions" "github.com/joho/godotenv" + "html/template" "log" "net/http" "os" @@ -22,6 +24,9 @@ var ( discord.New(), } sessionStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY"))) + + //go:embed pages/index.go.html + indexTemplate string ) func main() { @@ -37,9 +42,25 @@ func main() { router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("Content-Type", "text/html") rw.WriteHeader(http.StatusOK) - _, _ = rw.Write([]byte("Melon Tools
\n")) + + modTmp := make([]template.HTML, 0) for _, v := range modules { - _, _ = rw.Write([]byte(fmt.Sprintf("%s
\n", v.GetEndpoint(), v.GetName()))) + modTmp = append(modTmp, template.HTML(fmt.Sprintf("%s", v.GetEndpoint(), v.GetName()))) + } + + tmp, err := template.New("homepage").Parse(indexTemplate) + if err != nil { + fmt.Println("Template parse error:", err) + return + } + err = tmp.Execute(rw, struct { + Modules []template.HTML + }{ + Modules: modTmp, + }) + if err != nil { + fmt.Println("Template execute error:", err) + return } }) diff --git a/cmd/melon-tools/pages/index.go.html b/cmd/melon-tools/pages/index.go.html new file mode 100644 index 0000000..2243111 --- /dev/null +++ b/cmd/melon-tools/pages/index.go.html @@ -0,0 +1,25 @@ + + + + + Melon Tools + + + +

Melon Tools

+ + +