diff options
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 +} + |
