add middlewares
This commit is contained in:
@ -9,6 +9,11 @@ import (
|
||||
"time"
|
||||
|
||||
cacheproxy "git.jeffthecoder.xyz/guochao/cache-proxy"
|
||||
"git.jeffthecoder.xyz/guochao/cache-proxy/pkgs/middleware"
|
||||
"git.jeffthecoder.xyz/guochao/cache-proxy/pkgs/middleware/handlerlog"
|
||||
"git.jeffthecoder.xyz/guochao/cache-proxy/pkgs/middleware/httplog"
|
||||
"git.jeffthecoder.xyz/guochao/cache-proxy/pkgs/middleware/recover"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -115,9 +120,16 @@ func main() {
|
||||
|
||||
server := cacheproxy.NewServer(*config)
|
||||
|
||||
http.HandleFunc("GET /{path...}", server.HandleRequestWithCache)
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("GET /", server.HandleRequestWithCache)
|
||||
|
||||
slog.With("addr", ":8881").Info("serving app")
|
||||
if err := http.ListenAndServe(":8881", nil); err != nil {
|
||||
if err := http.ListenAndServe(":8881", middleware.Use(mux,
|
||||
recover.Recover(),
|
||||
handlerlog.FindHandler(mux),
|
||||
httplog.Log(httplog.Config{LogStart: true, LogFinish: true}),
|
||||
)); err != nil {
|
||||
slog.With("error", err).Error("failed to start server")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user