diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 20:17:51 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 20:17:51 -0400 |
| commit | 888d48300fd2d098a676503a69ac96db94e61a04 (patch) | |
| tree | 12aa1be24bcc501fa18f9ebeb4961cdb89f76dc6 /allowed.go | |
| parent | ee64cdc2712a8e7f77c6af02385afd43a2a1e61b (diff) | |
feat: OS Index Pages
Diffstat (limited to 'allowed.go')
| -rw-r--r-- | allowed.go | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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 +} + |
