diff options
| author | a73x <[email protected]> | 2024-08-25 15:14:41 +0100 |
|---|---|---|
| committer | a73x <[email protected]> | 2024-08-25 15:14:41 +0100 |
| commit | fea0ef77c8c98dfadd2f9d29804653293fd31c99 (patch) | |
| tree | 6dadd3062fc77d37e622838eb6b16a60e2774f4d /main.go | |
| parent | 794401aaadfaa4efd91587db40439226231ff303 (diff) | |
feat: add templating
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/main.go b/main.go deleted file mode 100644 index d594cd1..0000000 --- a/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "embed" - "io/fs" - "log" - "net/http" - "time" - - "go.uber.org/zap" -) - -//go:embed public/index.html -var content embed.FS - -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(content, "public") - if err != nil { - log.Fatal(err) - } - - mux.Handle("/", http.FileServer(http.FS(staticFs))) - - server := http.Server{ - Addr: ":8080", - Handler: loggingMiddleware(mux), - } - - err = server.ListenAndServe() - if err != nil { - log.Fatal(err) - } -} |
