Add Blog Posts CRUD with SQLite

- Add modernc.org/sqlite (pure Go, no CGO)
- Create models package with Post struct
- Implement SQLite connection and schema auto-creation
- Add CRUD methods to database package
- Create post handlers with JSON API
- Register API routes: GET/POST/PUT/DELETE /api/v1/posts
- Set default DBURL to file:./data.db with WAL mode
This commit is contained in:
2025-12-27 12:43:30 +07:00
parent fb347b96df
commit f7ab09c2c3
8 changed files with 474 additions and 10 deletions

View File

@@ -63,6 +63,13 @@ func (s *Server) SetupRoutes() {
s.router.Route("/api/v1", func(r chi.Router) {
r.Get("/now", s.h.HandleNow())
// Posts CRUD
r.Get("/posts", s.h.HandleListPosts())
r.Post("/posts", s.h.HandleCreatePost())
r.Get("/posts/{id}", s.h.HandleGetPost())
r.Put("/posts/{id}", s.h.HandleUpdatePost())
r.Delete("/posts/{id}", s.h.HandleDeletePost())
})
// if you want to use a general purpose middleware (http.Handler