gohttpserver/internal/models/models.go
sneak f7ab09c2c3 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
2025-12-27 12:43:30 +07:00

30 lines
706 B
Go

package models
import (
"time"
)
type Post struct {
ID int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Author string `json:"author"`
Published bool `json:"published"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type CreatePostRequest struct {
Title string `json:"title"`
Body string `json:"body"`
Author string `json:"author"`
Published bool `json:"published"`
}
type UpdatePostRequest struct {
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Author *string `json:"author,omitempty"`
Published *bool `json:"published,omitempty"`
}