add csv reading, routing
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user