2020-01-11 20:18:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
2022-09-27 00:15:49 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
|
|
"github.com/spf13/afero"
|
2024-07-30 21:11:50 +00:00
|
|
|
"tuxpa.in/a/pprofweb/pkg/pprofweb"
|
2020-01-11 20:18:50 +00:00
|
|
|
)
|
|
|
|
|
2022-09-27 00:15:49 +00:00
|
|
|
func main() {
|
2020-01-11 20:18:50 +00:00
|
|
|
|
2022-09-27 00:15:49 +00:00
|
|
|
filepath := os.Getenv("STORAGE_PATH")
|
|
|
|
if filepath == "" {
|
|
|
|
filepath = "./tmp"
|
2020-01-11 20:18:50 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 00:15:49 +00:00
|
|
|
s := pprofweb.NewServer(
|
|
|
|
afero.NewBasePathFs(afero.NewOsFs(), filepath),
|
|
|
|
pprofweb.Config{},
|
|
|
|
)
|
2020-01-11 20:18:50 +00:00
|
|
|
|
2022-09-27 00:15:49 +00:00
|
|
|
port := os.Getenv("PORT")
|
2020-01-11 20:18:50 +00:00
|
|
|
if port == "" {
|
2022-09-27 00:15:49 +00:00
|
|
|
port = "7443"
|
|
|
|
log.Printf("warning: %s not specified; using default %s", "PORT", port)
|
2020-01-11 20:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr := ":" + port
|
|
|
|
log.Printf("listen addr %s (http://localhost:%s/)", addr, port)
|
2022-09-27 00:15:49 +00:00
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Use(middleware.Recoverer, middleware.Logger)
|
|
|
|
r.Use(middleware.NewCompressor(6).Handler)
|
|
|
|
r.Route("/", s.HandleHTTP())
|
|
|
|
if err := http.ListenAndServe(addr, r); err != nil {
|
2020-01-11 20:18:50 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|