Files
digital-psychology/.ai/examples/good-handler.go
T
jackyu66gitandCursor 2fb1dfee14 chore: seal Design Vision v1 and monorepo scaffold
Archive the differentiated YuXinGu product docs, AI engineering system,
design contract, and Go/Vue scaffold. Next execution prioritizes Cece-parity
over early innovation (see .ai/product/STRATEGY.md).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 16:00:44 +08:00

55 lines
1.2 KiB
Go

//go:build ignore
// EXAMPLE — reference shape for AI. Not compiled into apps/api.
package examples
import (
"context"
"net/http"
"github.com/gin-gonic/gin"
)
type apiBody struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
type DecodeInput struct {
Year int
Month int
Day int
}
type DecodeOutput struct {
Summary string `json:"summary"`
}
type DecodeService interface {
Decode(ctx context.Context, in DecodeInput) (*DecodeOutput, error)
}
type DecodeHandler struct {
Svc DecodeService
}
// Decode handles POST /api/v1/reports/decode
func (h *DecodeHandler) Decode(c *gin.Context) {
var req struct {
Year int `json:"year" binding:"required"`
Month int `json:"month" binding:"required"`
Day int `json:"day" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, apiBody{Code: 10000, Message: "invalid request"})
return
}
out, err := h.Svc.Decode(c.Request.Context(), DecodeInput(req))
if err != nil {
c.JSON(http.StatusBadRequest, apiBody{Code: 30001, Message: err.Error()})
return
}
c.JSON(http.StatusOK, apiBody{Code: 0, Message: "success", Data: out})
}