diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-08-28 15:22:01 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-08-28 15:22:01 +0300 |
commit | 670fadcfbcef7d139ebb81e3d4aa5f8ccac804ee (patch) | |
tree | 38e9139a43ee68ba03dfcb5d5b7535ba9efd55e1 /main.go | |
parent | 094e63a2ef716876fc299d03be02f90218266d21 (diff) |
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -5,25 +5,30 @@ import ( "flag" "io/fs" "log" + "log/slog" "net/http" "os" "os/signal" "path/filepath" "time" + "go.neonxp.ru/mux" + "go.neonxp.ru/mux/middleware" "golang.org/x/sync/errgroup" ) var ( - host string - listen string - path string - ttl time.Duration + host string + listen string + path string + htmlPath string + ttl time.Duration ) func init() { flag.StringVar(&host, "host", "https://nixshare.ru/", "host of nixshare") flag.StringVar(&listen, "listen", ":8000", "port to listen") + flag.StringVar(&htmlPath, "html_path", "./html", "html directory") flag.StringVar(&path, "path", "./storage", "storage directory") flag.DurationVar(&ttl, "ttl", 24*time.Hour, "time to delete uploaded file") } @@ -37,11 +42,16 @@ func main() { r := http.NewServeMux() r.Handle("POST /upload", http.HandlerFunc(uploadHandler)) - r.Handle("/", http.FileServer(http.Dir(path))) + r.Handle("/", http.FileServer(http.Dir("html"))) + r.Handle("/s/", http.StripPrefix("/s/", http.FileServer(http.Dir(path)))) srv := http.Server{ - Addr: listen, - Handler: r, + Addr: listen, + Handler: mux.Use(r, + middleware.Recover(slog.Default()), + middleware.RequestID, + middleware.Logger(slog.Default()), + ), } eg, egCtx := errgroup.WithContext(ctx) |