summaryrefslogtreecommitdiff
path: root/allowed.go
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2026-04-26 20:17:51 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2026-04-26 20:17:51 -0400
commit888d48300fd2d098a676503a69ac96db94e61a04 (patch)
tree12aa1be24bcc501fa18f9ebeb4961cdb89f76dc6 /allowed.go
parentee64cdc2712a8e7f77c6af02385afd43a2a1e61b (diff)
feat: OS Index Pages
Diffstat (limited to 'allowed.go')
-rw-r--r--allowed.go18
1 files changed, 16 insertions, 2 deletions
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
+}
+