Migrated all http mechanics to a central handler, changed static

content to all be front-loaded and thread safe
This commit is contained in:
2018-11-18 05:28:02 +00:00
committed by cdramey
parent 4d3a84b6b3
commit 90e419f5a4
4 changed files with 128 additions and 80 deletions

16
main.go
View File

@ -7,7 +7,6 @@ import (
"net/http"
"os"
"qurl/pages"
"qurl/static"
"qurl/storage"
"runtime"
)
@ -54,22 +53,15 @@ func main() {
return
}
mux := http.NewServeMux()
mux.Handle("/index.html", &static.StaticContent{Content: "index.html"})
mux.Handle("/favicon.ico", &static.StaticContent{Content: "favicon.ico"})
mux.Handle("/qurl.css", &static.StaticContent{Content: "qurl.css"})
submit := &pages.SubmitHandler{Storage: stor}
err = submit.Init()
root := &pages.RootHandler{Storage: stor}
err = root.Init()
if err != nil {
fmt.Fprintf(os.Stderr, "Submit init error: %s\n", err.Error())
fmt.Fprintf(os.Stderr, "Handler Init Error: %s\n", err.Error())
return
}
mux.Handle("/submit.html", submit)
fmt.Fprintf(os.Stdout, "qurl listening .. \n")
err = http.Serve(listen, mux)
err = http.Serve(listen, root)
if err != nil {
fmt.Fprintf(os.Stderr, "Serve error: %s\n", err.Error())
}