A Content Management System API with JWT authentication, category, news, comment, and custom page management.
internal/model/— Data models and interfacesinternal/repository/— Database access logicinternal/usecase/— Business logicinternal/delivery/http/— HTTP handlers (Gin)internal/cmd/— Application entrypoints
- Configure your database in
config.yaml. - Run migrations:
go run main.go migrate
- Start the server:
go run main.go httpsrv
GET /v1/categories— List categoriesGET /v1/categories/:id— Get category detailPOST /v1/categories— Create category (auth required)PUT /v1/categories/:id— Update category (auth required)DELETE /v1/categories/:id— Delete category (auth required)
GET /v1/news— List newsGET /v1/news/:id— Get news detailPOST /v1/news— Create news (auth required)PUT /v1/news/:id— Update news (auth required)DELETE /v1/news/:id— Delete news (auth required)
POST /v1/comments— Create comment (auth optional, anonymous allowed)- Request:
{ "news_id": int, "comment": string } - Response:
{ "data": { ...comment }, "message": "Comment created successfully" }
- Request:
DELETE /v1/comments/:id— Delete comment- Response:
{ "message": "Comment deleted successfully" }
- Response:
GET /v1/pages— List all custom pagesGET /v1/pages/:id— Get custom page by IDGET /v1/pages/url/:url— Get custom page by URLPOST /v1/pages— Create new custom page- Request:
{ "title": string, "url": string, "content": string } - Response:
{ "data": page_id, "message": "Custom page created successfully" }
- Request:
PUT /v1/pages/:id— Update custom page- Request:
{ "title": string, "url": string, "content": string } - Response:
{ "message": "Custom page updated successfully" }
- Request:
DELETE /v1/pages/:id— Delete custom page- Response:
{ "message": "Custom page deleted successfully" }
- Response:
All endpoints return JSON. Standard response:
{
"data": ..., // optional
"message": "...", // optional
"error": "..." // only on error
}- All error messages and response fields are consistently named (
error,message). - HTTP status codes follow REST conventions (200 OK, 201 Created, 400 Bad Request, 404 Not Found, 500 Internal Server Error).
- All panic sources in comment POST have been fixed with proper error handling and type assertion.
For more details, see the code in each respective directory.