package handler import ( "encoding/json" "errors" "strconv" "github.com/gin-gonic/gin" "github.com/sundynix/pets-be/internal/service" "github.com/sundynix/pets-be/pkg/errcode" "github.com/sundynix/pets-be/pkg/response" ) // uintParam 解析路径参数为 uint func uintParam(c *gin.Context, key string) uint { v, _ := strconv.ParseUint(c.Param(key), 10, 64) return uint(v) } // jsonMarshal 便捷序列化 func jsonMarshal(v any) ([]byte, error) { return json.Marshal(v) } // respondErr 统一错误响应:区分 not found 与内部错误 func respondErr(c *gin.Context, err error) { if errors.Is(err, service.ErrNotFound) { response.Fail(c, errcode.ErrNotFound, "") return } response.FailErr(c, err) }