From 7e0a3cbcbe2f36afe17bf73e739f9d0d2362ac12 Mon Sep 17 00:00:00 2001 From: olikol <78661364+olikols07@users.noreply.github.com> Date: Wed, 27 Aug 2025 06:52:31 +0200 Subject: [PATCH] Changed file structure to align with the recommendations given by https://github.com/golang-standards/project-layout --- api/Admin.go | 1 + {src => api}/FileHandlers.go | 2 +- {src => api}/UploadHandlers.go | 2 +- main.go | 17 +++++++++-------- src/Admin.go | 1 - {templates => website/templates}/admin.html | 0 {templates => website/templates}/ascii.html | 0 {templates => website/templates}/images.html | 3 +++ 8 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 api/Admin.go rename {src => api}/FileHandlers.go (99%) rename {src => api}/UploadHandlers.go (98%) delete mode 100644 src/Admin.go rename {templates => website/templates}/admin.html (100%) rename {templates => website/templates}/ascii.html (100%) rename {templates => website/templates}/images.html (86%) diff --git a/api/Admin.go b/api/Admin.go new file mode 100644 index 0000000..778f64e --- /dev/null +++ b/api/Admin.go @@ -0,0 +1 @@ +package api diff --git a/src/FileHandlers.go b/api/FileHandlers.go similarity index 99% rename from src/FileHandlers.go rename to api/FileHandlers.go index 190ff3d..5bbd46c 100644 --- a/src/FileHandlers.go +++ b/api/FileHandlers.go @@ -1,4 +1,4 @@ -package src +package api import ( "encoding/json" diff --git a/src/UploadHandlers.go b/api/UploadHandlers.go similarity index 98% rename from src/UploadHandlers.go rename to api/UploadHandlers.go index 3ac2f18..0051d54 100644 --- a/src/UploadHandlers.go +++ b/api/UploadHandlers.go @@ -1,4 +1,4 @@ -package src +package api import ( "fmt" diff --git a/main.go b/main.go index fdb6a5f..ddf8c70 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,16 @@ package main import ( - "Advertisement_Panel/src" + "Advertisement_Panel/api" "fmt" "html/template" "net/http" ) -var templ *template.Template +var templates *template.Template func main() { - templ, _ = template.ParseGlob("templates/*.html") + templates, _ = template.ParseGlob("website/templates/*.html") fmt.Print("Now running server!\n") @@ -18,7 +18,7 @@ func main() { http.HandleFunc("/", index_handler) // Serves json for html to find file names - http.HandleFunc("/files", src.FileHandler) + http.HandleFunc("/files", api.FileHandler) // Serves ascii page http.HandleFunc("/ascii", ascii_handler) @@ -32,7 +32,7 @@ func main() { http.HandleFunc("/admin/", admin_handler) // Handles image upload - http.HandleFunc("/upload", src.UploadHandler) + http.HandleFunc("/upload", api.UploadHandler) fmt.Print("Webserver running on http://localhost:8080\n") @@ -42,12 +42,13 @@ func main() { } func index_handler(w http.ResponseWriter, r *http.Request) { - templ.ExecuteTemplate(w, "images.html", nil) + templates.ExecuteTemplate(w, "images.html", nil) } func ascii_handler(w http.ResponseWriter, r *http.Request) { - templ.ExecuteTemplate(w, "ascii.html", nil) + templates.ExecuteTemplate(w, "ascii.html", nil) } + func admin_handler(w http.ResponseWriter, r *http.Request) { - templ.ExecuteTemplate(w, "admin.html", nil) + templates.ExecuteTemplate(w, "admin.html", nil) } diff --git a/src/Admin.go b/src/Admin.go deleted file mode 100644 index c6d5f54..0000000 --- a/src/Admin.go +++ /dev/null @@ -1 +0,0 @@ -package src diff --git a/templates/admin.html b/website/templates/admin.html similarity index 100% rename from templates/admin.html rename to website/templates/admin.html diff --git a/templates/ascii.html b/website/templates/ascii.html similarity index 100% rename from templates/ascii.html rename to website/templates/ascii.html diff --git a/templates/images.html b/website/templates/images.html similarity index 86% rename from templates/images.html rename to website/templates/images.html index db6d1a0..0046501 100644 --- a/templates/images.html +++ b/website/templates/images.html @@ -21,6 +21,9 @@ index = (index + 1) % images.length; document.getElementById("images").src = images[index]; }, 1000); + setTimeout(() => { + window.location.reload(); + }, images.length*2*1000); });