summaryrefslogtreecommitdiff
path: root/cmd/home/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/home/main.go')
-rw-r--r--cmd/home/main.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmd/home/main.go b/cmd/home/main.go
new file mode 100644
index 0000000..f284c30
--- /dev/null
+++ b/cmd/home/main.go
@@ -0,0 +1,46 @@
+package main
+
+import (
+ "io/fs"
+ "log"
+ "net/http"
+ "time"
+
+ "git.sr.ht/~a73x/home"
+ "go.uber.org/zap"
+)
+
+func main() {
+ logger, _ := zap.NewProduction()
+ loggingMiddleware := func(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ start := time.Now()
+ next.ServeHTTP(w, r)
+ logger.Info("request received",
+ zap.String("url", r.URL.Path),
+ zap.String("method", r.Method),
+ zap.Duration("duration", time.Since(start)),
+ zap.String("user-agent", r.UserAgent()),
+ )
+ })
+ }
+
+ mux := http.NewServeMux()
+
+ staticFs, err := fs.Sub(home.Content, "public")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ mux.Handle("GET /", http.FileServer(http.FS(staticFs)))
+
+ server := http.Server{
+ Addr: ":8080",
+ Handler: loggingMiddleware(mux),
+ }
+
+ err = server.ListenAndServe()
+ if err != nil {
+ log.Fatal(err)
+ }
+}