summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-01-12 01:08:53 +0100
committerAki <please@ignore.pl>2024-01-12 01:08:53 +0100
commit47916bdd0a782fe61d37b47bde09f6edceedce5f (patch)
treeddc5cfd108e9527af268fa37d41c6a7f8ad17303 /main.go
parent6fe3e5394e2e6736222ce85c7b5afbadffda5b82 (diff)
downloadrudone-47916bdd0a782fe61d37b47bde09f6edceedce5f.zip
rudone-47916bdd0a782fe61d37b47bde09f6edceedce5f.tar.gz
rudone-47916bdd0a782fe61d37b47bde09f6edceedce5f.tar.bz2
Moved all config-like things into one placeHEADmaster
Diffstat (limited to 'main.go')
-rw-r--r--main.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/main.go b/main.go
index 011e8c4..e3cd540 100644
--- a/main.go
+++ b/main.go
@@ -7,7 +7,6 @@ import (
"html/template"
"log"
"net/http"
- "os"
"strconv"
"time"
@@ -118,28 +117,20 @@ func handleHome(pathname string) func(http.ResponseWriter, *http.Request) {
}
}
-func handleRequests() {
+func handleRequests(port string) {
router := mux.NewRouter()
router.HandleFunc("/entries", handleEntryOptions).Methods("OPTIONS")
router.HandleFunc("/entries", handleEntryPost).Methods("POST")
router.HandleFunc("/entries", handleEntryGet).Methods("GET")
router.HandleFunc("/", handleHome("index.html.in")).Methods("GET")
router.PathPrefix("/").Handler(http.FileServer(http.FS(content)))
- log.Fatal(http.ListenAndServe(configure(), router))
-}
-
-func configure() string {
- at := os.Getenv("STATSAT")
- if at == "" {
- log.Println("Defaulting to STATSAT=:8080")
- at = ":8080"
- }
- return at
+ log.Fatal(http.ListenAndServe(port, router))
}
func main() {
log.Println("Starting up")
- InitEntries()
+ cfg := LoadConfig()
+ InitEntries(cfg.DB)
defer CloseEntries()
- handleRequests()
+ handleRequests(cfg.Port)
}