all repos — flounder @ 78fc9c855020b4d22872860be39769029bf6f85c

A small site builder for the Gemini protocol

refactor constants
alex wennerberg alex@alexwennerberg.com
Wed, 30 Dec 2020 10:50:53 -0800
commit

78fc9c855020b4d22872860be39769029bf6f85c

parent

54e04e31ab9c15c8d6850b33bffd5515454df31d

6 files changed, 7 insertions(+), 8 deletions(-)

jump to
M config.goconfig.go

@@ -5,6 +5,9 @@ "github.com/BurntSushi/toml"

"path/filepath" ) +const HiddenFolder = ".hidden" +const GemlogFolder = "gemlog" + type Config struct { FilesDirectory string TemplatesDirectory string
M db.godb.go

@@ -118,7 +118,7 @@ if err != nil {

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
M gemfeed.gogemfeed.go

@@ -17,8 +17,6 @@ "strings"

"time" ) -const gemlogFolder = "gemlog" - type Gemfeed struct { Title string Creator string

@@ -64,7 +62,7 @@

// 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{
M gemini.gogemini.go

@@ -83,7 +83,7 @@ userName := filepath.Clean(strings.Split(r.URL.Host, ".")[0]) // clean probably unnecessary

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 }
M http.gohttp.go

@@ -539,7 +539,7 @@ if strings.HasSuffix(p, "index.gmi") {

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 }
M main.gomain.go

@@ -12,8 +12,6 @@ )

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()