all repos — flounder @ 8e3a3b5bff7f3f9fd98b1cf8c3d636623b7164ff

A small site builder for the Gemini protocol

change config to static config
alex wennerberg alex@alexwennerberg.com
Tue, 20 Oct 2020 22:57:42 -0700
commit

8e3a3b5bff7f3f9fd98b1cf8c3d636623b7164ff

parent

3c696860461d44ec54c7a718b3e5221705c5e2d1

2 files changed, 9 insertions(+), 11 deletions(-)

jump to
M http.gohttp.go

@@ -9,11 +9,6 @@ )

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 @@ http.Error(w, errorMsg, statusCode)

} } -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 @@ Domain string

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 @@ fmt.Fprintf(w, "%s\n", file.Name)

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

@@ -9,6 +9,8 @@ "path"

"path/filepath" ) +var c Config // global var to hold static configuration + const ( // todo make configurable userFilesPath = "./files" )

@@ -64,11 +66,12 @@ }

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