add csv reading, routing

This commit is contained in:
2026-03-30 21:42:52 +01:00
parent 153dc64f60
commit a98ef28055
5 changed files with 141 additions and 22 deletions
+26
View File
@@ -0,0 +1,26 @@
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.WriteHeader(redirect.StatusCode)
w.Header().Add("location", redirect.To)
} else {
statusCode := 404
srv.Log.Error().Int("result", statusCode).Msg(req.URL.Path)
w.WriteHeader(statusCode)
}
}