pprofweb/pkg/webserver/pprofweb.go
a e9f27bb967
Some checks failed
commit-tag / release-image (push) Failing after 50s
update deps
2024-07-30 16:11:50 -05:00

42 lines
821 B
Go

package main
import (
"log"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/spf13/afero"
"tuxpa.in/a/pprofweb/pkg/pprofweb"
)
func main() {
filepath := os.Getenv("STORAGE_PATH")
if filepath == "" {
filepath = "./tmp"
}
s := pprofweb.NewServer(
afero.NewBasePathFs(afero.NewOsFs(), filepath),
pprofweb.Config{},
)
port := os.Getenv("PORT")
if port == "" {
port = "7443"
log.Printf("warning: %s not specified; using default %s", "PORT", port)
}
addr := ":" + port
log.Printf("listen addr %s (http://localhost:%s/)", addr, port)
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 {
panic(err)
}
}