Initial commit
This commit is contained in:
24
routes/capture.go
Normal file
24
routes/capture.go
Normal file
@ -0,0 +1,24 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"gitea.henriburau.de/haw-lan/cod4watcher/views/capture"
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
func (s *Server) HandleCapture(w http.ResponseWriter, r *http.Request) error {
|
||||
captureString := chi.URLParam(r, "captureID")
|
||||
captureID, err := strconv.Atoi(captureString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
foundCapture, err := s.cs.GetCaptureById(captureID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Render(w, r, capture.Capture(foundCapture))
|
||||
}
|
||||
12
routes/health.go
Normal file
12
routes/health.go
Normal file
@ -0,0 +1,12 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (s *Server) HandleHealth(w http.ResponseWriter, r *http.Request) error {
|
||||
fmt.Fprint(w, "Up and running!")
|
||||
|
||||
return nil
|
||||
}
|
||||
16
routes/home.go
Normal file
16
routes/home.go
Normal file
@ -0,0 +1,16 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.henriburau.de/haw-lan/cod4watcher/views/home"
|
||||
)
|
||||
|
||||
func (s *Server) HandleHome(w http.ResponseWriter, r *http.Request) error {
|
||||
captureList, err := s.cs.GetActiveCapures()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Render(w, r, home.Index(captureList))
|
||||
}
|
||||
27
routes/routes.go
Normal file
27
routes/routes.go
Normal file
@ -0,0 +1,27 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"gitea.henriburau.de/haw-lan/cod4watcher/services"
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
type HTTPHandler func(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func Make(h HTTPHandler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := h(w, r); err != nil {
|
||||
slog.Error("HTTP handler error", "err", err, "path", r.URL.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
cs *services.CaptureService
|
||||
}
|
||||
|
||||
func Render(w http.ResponseWriter, r *http.Request, c templ.Component) error {
|
||||
return c.Render(r.Context(), w)
|
||||
}
|
||||
Reference in New Issue
Block a user