aboutsummaryrefslogtreecommitdiff
path: root/page
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-12-14 09:51:15 -0500
committerMitch Riedstra <mitch@riedstra.us>2019-12-14 09:51:15 -0500
commitb2056fbf48849e321389977e3fdbb0f5841822c4 (patch)
tree0f0b993d1f2ea0221067e4f689e606e33ba47bbd /page
parentc19536be6e4f8733af329204a50ffc254a679ee5 (diff)
downloadgo-website-b2056fbf48849e321389977e3fdbb0f5841822c4.tar.gz
go-website-b2056fbf48849e321389977e3fdbb0f5841822c4.tar.xz
Tidy up the server command, pull the handlers into the page library. Convert to go modules. Add a build script and version to the command
Diffstat (limited to 'page')
-rw-r--r--page/http.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/page/http.go b/page/http.go
new file mode 100644
index 0000000..acf9147
--- /dev/null
+++ b/page/http.go
@@ -0,0 +1,34 @@
+package page
+
+import (
+ "log"
+ "net/http"
+ "path/filepath"
+)
+
+func SetupHandlers() {
+ http.Handle("/static/", StaticHandler())
+ http.HandleFunc("/", PageHandler)
+}
+
+func PageHandler(w http.ResponseWriter, r *http.Request) {
+ u := r.URL.Path
+ if u == "/" {
+ u = "/index"
+ }
+ u = filepath.Join(".", u)
+ log.Println(u)
+
+ p := &Page{Name: u}
+ err := p.Render(w)
+ if err != nil {
+ log.Println(err)
+ http.Error(w, "Internal server error", 500)
+ return
+ }
+
+}
+
+func StaticHandler() (h http.Handler) {
+ return http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
+}