posts/server.go

28 lines
797 B
Go

package main
import (
"net/http"
)
// Server — the HTTP/MCP server. Both surfaces (REST on :8310, MCP on :8320)
// share the same Store.
type Server struct {
store *Store
}
func NewServer(store *Store) *Server {
return &Server{store: store}
}
// Routes — the REST API surface. Per docs/API.md.
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("POST /api/authors", s.handleUpsertAuthor)
mux.HandleFunc("POST /api/channels", s.handleUpsertChannel)
mux.HandleFunc("GET /api/posts/{id}", s.handleGetPost)
mux.HandleFunc("POST /api/posts/{id}/comments", s.handleCreateComment)
return mux
}