feat(server): NewServer + Routes (stdlib mux)
This commit is contained in:
parent
124784dd79
commit
4f68337899
1 changed files with 25 additions and 0 deletions
25
api/server.go
Normal file
25
api/server.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
store *Store
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewServer(db *sql.DB) *Server {
|
||||
return &Server{store: NewStore(db), db: db}
|
||||
}
|
||||
|
||||
func (s *Server) Routes() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /api/healthz", s.handleHealth)
|
||||
mux.HandleFunc("GET /api/posts", s.handleListPosts)
|
||||
mux.HandleFunc("POST /api/posts", s.handleCreatePost)
|
||||
mux.HandleFunc("GET /api/posts/{id}", s.handleGetPost)
|
||||
mux.HandleFunc("POST /api/posts/{id}/comments", s.handleCreateComment)
|
||||
return mux
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue