flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 78fc9c855020b4d22872860be39769029bf6f85c
parent 54e04e31ab9c15c8d6850b33bffd5515454df31d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 30 Dec 2020 10:50:53 -0800

refactor constants

Diffstat:
Mconfig.go | 3+++
Mdb.go | 2+-
Mgemfeed.go | 4+---
Mgemini.go | 2+-
Mhttp.go | 2+-
Mmain.go | 2--
6 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/config.go b/config.go @@ -5,6 +5,9 @@ import ( "path/filepath" ) +const HiddenFolder = ".hidden" +const GemlogFolder = "gemlog" + type Config struct { FilesDirectory string TemplatesDirectory string diff --git a/db.go b/db.go @@ -118,7 +118,7 @@ func getIndexFiles(admin bool) ([]*File, error) { // cache this function log.Printf("Failure accessing a path %q: %v\n", thepath, err) return err // think about } - if !admin && info.IsDir() && info.Name() == HIDDEN_FOLDER { + if !admin && info.IsDir() && info.Name() == HiddenFolder { return filepath.SkipDir } // make this do what it should diff --git a/gemfeed.go b/gemfeed.go @@ -17,8 +17,6 @@ import ( "time" ) -const gemlogFolder = "gemlog" - type Gemfeed struct { Title string Creator string @@ -64,7 +62,7 @@ func urlFromPath(fullPath string) url.URL { // Non-standard extension // Requires yyyy-mm-dd formatted files func generateFeedFromUser(user string) *Gemfeed { - gemlogFolderPath := path.Join(c.FilesDirectory, user, gemlogFolder) + gemlogFolderPath := path.Join(c.FilesDirectory, user, GemlogFolder) // NOTE: assumes sanitized input u := urlFromPath(gemlogFolderPath) feed := Gemfeed{ diff --git a/gemini.go b/gemini.go @@ -83,7 +83,7 @@ func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { fileName := filepath.Clean(r.URL.Path) if fileName == "/" { fileName = "index.gmi" - } else if strings.HasPrefix(fileName, "/.hidden") { + } else if strings.HasPrefix(fileName, "/"+HiddenFolder) { w.WriteStatus(gmi.StatusNotFound) return } diff --git a/http.go b/http.go @@ -539,7 +539,7 @@ func userFile(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, path.Dir(p), http.StatusMovedPermanently) } - if strings.HasPrefix(p, "/"+HIDDEN_FOLDER) { + if strings.HasPrefix(p, "/"+HiddenFolder) { renderDefaultError(w, http.StatusForbidden) return } diff --git a/main.go b/main.go @@ -12,8 +12,6 @@ import ( var c Config // global var to hold static configuration -const HIDDEN_FOLDER = ".hidden" - func main() { configPath := flag.String("c", "flounder.toml", "path to config file") // doesnt work atm flag.Parse()