iloom/shared/pkg/response/response.go
Chever John 9c39c8cbd7
init: iloom WMS monorepo with K8s deployment manifests
Go workspace (go.work) with 5 microservices + shared library:
- gateway (8080), auth-service (8081), purchaser-service (8082)
- textile-service (8083), washing-service (8084)
- shared: proto definitions, common packages

Infrastructure: docker-compose for local dev, K8s manifests for
K3s cluster deployment (mysql/redis/etcd + traefik ingress).

Frontend (iloom-flatten) added as git submodule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 11:33:31 +08:00

66 lines
1.4 KiB
Go

package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
Meta *Meta `json:"meta,omitempty"`
}
type Meta struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int `json:"total"`
HasMore bool `json:"has_more"`
}
func OK(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: ErrCodeSuccess,
Message: "success",
Data: data,
})
}
func OKWithMeta(c *gin.Context, data interface{}, meta *Meta) {
c.JSON(http.StatusOK, Response{
Code: ErrCodeSuccess,
Message: "success",
Data: data,
Meta: meta,
})
}
func Error(c *gin.Context, httpCode int, code int, message string) {
c.JSON(httpCode, Response{
Code: code,
Message: message,
})
}
func BadRequest(c *gin.Context, message string) {
Error(c, http.StatusBadRequest, ErrCodeBadRequest, message)
}
func Unauthorized(c *gin.Context, message string) {
Error(c, http.StatusUnauthorized, ErrCodeUnauthorized, message)
}
func Forbidden(c *gin.Context, message string) {
Error(c, http.StatusForbidden, ErrCodeForbidden, message)
}
func NotFound(c *gin.Context, message string) {
Error(c, http.StatusNotFound, ErrCodeNotFound, message)
}
func InternalError(c *gin.Context, message string) {
Error(c, http.StatusInternalServerError, ErrCodeInternal, message)
}