flounder

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

commit 8e3a3b5bff7f3f9fd98b1cf8c3d636623b7164ff
parent 3c696860461d44ec54c7a718b3e5221705c5e2d1
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue, 20 Oct 2020 22:57:42 -0700

change config to static config

Diffstat:
Mhttp.go | 13++++---------
Mmain.go | 7+++++--
2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/http.go b/http.go @@ -9,11 +9,6 @@ import ( var t *template.Template -type IndexHandler struct { - Domain string - SiteTitle string -} - // TODO somewhat better error handling const InternalServerErrorMsg = "500: Internal Server Error" @@ -25,7 +20,7 @@ func renderError(w http.ResponseWriter, errorMsg string, statusCode int) { // TO } } -func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func indexHandler(w http.ResponseWriter, r *http.Request) { indexFiles, err := getIndexFiles() if err != nil { log.Println(err) @@ -43,7 +38,7 @@ func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { PageTitle string Files []*File Users []string - }{h.Domain, h.SiteTitle, indexFiles, allUsers} + }{c.RootDomain, c.SiteTitle, indexFiles, allUsers} err = t.ExecuteTemplate(w, "index.html", data) if err != nil { log.Println(err) @@ -71,13 +66,13 @@ func mySiteHandler(w http.ResponseWriter, r *http.Request) { } } -func runHTTPServer(config *Config) { +func runHTTPServer() { var err error t, err = template.ParseGlob("./templates/*.html") // TODO make template dir configruable if err != nil { log.Fatal(err) } - http.Handle("/", &IndexHandler{config.RootDomain, config.SiteTitle}) + http.HandleFunc("/", indexHandler) http.HandleFunc("/my_site", mySiteHandler) http.HandleFunc("/edit/", editFileHandler) // http.HandleFunc("/delete/", deleteFileHandler) diff --git a/main.go b/main.go @@ -9,6 +9,8 @@ import ( "path/filepath" ) +var c Config // global var to hold static configuration + const ( // todo make configurable userFilesPath = "./files" ) @@ -64,11 +66,12 @@ func getUserFiles(user string) ([]*File, error) { func main() { configPath := flag.String("c", "flounder.toml", "path to config file") - config, err := getConfig(*configPath) + var err error + c, err = getConfig(*configPath) if err != nil { log.Fatal(err) } - runHTTPServer(&config) + runHTTPServer() // runGeminiServer(&config) // go log.Fatal(gmi.ListenAndServe(":8080", nil)) }