blob: cccb4e10fe1ad9b3e5b4dc68146977932b9c0056 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package web
import (
"net/http"
"gitlab.com/mokhax/sparkled/app/controllers/health"
"gitlab.com/mokhax/sparkled/app/controllers/sparkles"
"gitlab.com/mokhax/sparkled/pkg/db"
)
type Server struct {
mux *http.ServeMux
}
func New(storage db.Repository) *Server {
mux := http.NewServeMux()
c := sparkles.New(storage)
mux.HandleFunc("GET /sparkles", c.Index)
mux.HandleFunc("POST /sparkles", c.Create)
mux.HandleFunc("GET /health", health.New().Index)
mux.Handle("GET /", http.FileServer(http.Dir("public")))
return &Server{mux: mux}
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.mux.ServeHTTP(w, r)
}
|