summaryrefslogtreecommitdiff
path: root/src/Render/Render.go
diff options
context:
space:
mode:
authorPhyscik <mynameisgennadiy@vk.com>2025-12-25 18:55:59 +0500
committerPhyscik <mynameisgennadiy@vk.com>2025-12-25 18:55:59 +0500
commit1f8ae1bcb66f5ff9029612307b882dfe85aa810b (patch)
tree4282f37a2101e993f2e1cc64614b29e7402ed4f2 /src/Render/Render.go
Structure pt 1
Diffstat (limited to 'src/Render/Render.go')
-rw-r--r--src/Render/Render.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Render/Render.go b/src/Render/Render.go
new file mode 100644
index 0000000..85061d7
--- /dev/null
+++ b/src/Render/Render.go
@@ -0,0 +1,41 @@
+package render
+
+import (
+ "fmt"
+ "log/slog"
+ "net/http"
+ "strings"
+
+ settings "physick.ru/Settings"
+)
+
+const indexTemplateName string = "index.html"
+
+func RegisterEndpoints() {
+ // http.Handle("static/", http.FileServer(http.FS(os.DirFS(settings.Current.StaticLocation))))
+ http.HandleFunc("/", mux)
+}
+
+func mux(w http.ResponseWriter, r *http.Request) {
+ slog.Info("Request", slog.String("URL", r.URL.String()))
+ if r.URL.String() == "/favicon.ico" {
+ http.ServeFile(w, r, fmt.Sprintf("%s/favicon.ico", settings.Current.StaticLocation))
+ }
+ if strings.HasPrefix(r.URL.String(), "/static") {
+ var filePath = strings.Replace(r.URL.String(), "/static", settings.Current.StaticLocation, 1)
+ http.ServeFile(w, r, filePath)
+ return
+ }
+ render(w, r)
+}
+
+func render(w http.ResponseWriter, r *http.Request) {
+ var indexTempl, readErr = getTemplateString(indexTemplateName)
+ if readErr != nil {
+ slog.Warn("Failed to load template", slog.Any("Error", readErr))
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ slog.Info("Requested a template")
+ w.Write([]byte(indexTempl))
+}