Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// APIResponse is the unified response structure for all API endpoints.
|
||||
// Pattern follows Chatwoot's JSON response format in controllers.
|
||||
type APIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Error *ErrorBody `json:"error,omitempty"`
|
||||
Meta *MetaBody `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
type ErrorBody struct {
|
||||
Code ErrorCode `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
type MetaBody struct {
|
||||
Page int `json:"page,omitempty"`
|
||||
PerPage int `json:"per_page,omitempty"`
|
||||
TotalCount int64 `json:"total_count,omitempty"`
|
||||
}
|
||||
|
||||
// OK sends a successful response with data
|
||||
func OK(c *gin.Context, data interface{}) {
|
||||
c.JSON(http.StatusOK, APIResponse{
|
||||
Success: true,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// OKWithMeta sends a successful paginated response
|
||||
func OKWithMeta(c *gin.Context, data interface{}, page, perPage int, total int64) {
|
||||
c.JSON(http.StatusOK, APIResponse{
|
||||
Success: true,
|
||||
Data: data,
|
||||
Meta: &MetaBody{
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
TotalCount: total,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Created sends a 201 response
|
||||
func Created(c *gin.Context, data interface{}) {
|
||||
c.JSON(http.StatusCreated, APIResponse{
|
||||
Success: true,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// NoContent sends a 204 response
|
||||
func NoContent(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// AbortWithError sends an error response and aborts the Gin context
|
||||
func AbortWithError(c *gin.Context, appErr *AppError) {
|
||||
c.AbortWithStatusJSON(appErr.Status, APIResponse{
|
||||
Success: false,
|
||||
Error: &ErrorBody{
|
||||
Code: appErr.Code,
|
||||
Message: appErr.Message,
|
||||
Detail: appErr.Detail,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// AbortWithStatusError sends a generic error with just HTTP status and message
|
||||
func AbortWithStatusError(c *gin.Context, status int, code ErrorCode, message string) {
|
||||
c.AbortWithStatusJSON(status, APIResponse{
|
||||
Success: false,
|
||||
Error: &ErrorBody{
|
||||
Code: code,
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user