diff options
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) |