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:
sneak committed 2025-12-27 12:43:30 +07:00
1 parent fb347b96df
commit f7ab09c2c3
8 files changed
+474 -10

No files matched your search

+7
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