From 888d48300fd2d098a676503a69ac96db94e61a04 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sun, 26 Apr 2026 20:17:51 -0400 Subject: feat: OS Index Pages --- allowed.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'allowed.go') diff --git a/allowed.go b/allowed.go index e6789206..d199a40d 100644 --- a/allowed.go +++ b/allowed.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "html/template" "log" @@ -11,7 +12,7 @@ import ( ) type AllowedFiles struct { - allowedFiles []string + AllowedFiles []string } func (a *AllowedFiles) GetFiles(w http.ResponseWriter, r *http.Request) { @@ -27,7 +28,7 @@ func (a *AllowedFiles) GetFiles(w http.ResponseWriter, r *http.Request) { url = "static/index.html" } - if !slices.Contains(a.allowedFiles, url) { + if !slices.Contains(a.AllowedFiles, url) { ErrorPage(w, 404) return } @@ -46,3 +47,16 @@ func (a *AllowedFiles) GetFiles(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, url) } } + +func GetAllowed(path string) (*AllowedFiles, error) { + var allowed AllowedFiles + + allowedJson, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + err = json.Unmarshal(allowedJson, &allowed) + return &allowed, err +} + -- cgit v1.2.3