2026-03-30 21:42:52 +01:00
|
|
|
package internal
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type HttpServer struct {
|
|
|
|
|
CLI *CLI
|
|
|
|
|
Log zerolog.Logger
|
|
|
|
|
Redirects Redirects
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (srv *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
redirect := srv.Redirects.Find(req.URL.Path)
|
|
|
|
|
if redirect != nil {
|
|
|
|
|
srv.Log.Info().Int("result", redirect.StatusCode).Msg(req.URL.Path)
|
|
|
|
|
w.Header().Add("location", redirect.To)
|
2026-03-30 22:04:50 +01:00
|
|
|
w.WriteHeader(redirect.StatusCode)
|
2026-03-30 21:42:52 +01:00
|
|
|
} else {
|
|
|
|
|
statusCode := 404
|
|
|
|
|
srv.Log.Error().Int("result", statusCode).Msg(req.URL.Path)
|
|
|
|
|
w.WriteHeader(statusCode)
|
|
|
|
|
}
|
|
|
|
|
}
|