20 lines
614 B
Go
20 lines
614 B
Go
// Package model 定义请求/响应的数据结构。
|
|
package model
|
|
|
|
// Response 统一 API 响应格式,所有接口均返回此结构。
|
|
type Response struct {
|
|
Code int `json:"code"` // 业务状态码,0 表示成功
|
|
Message string `json:"message"` // 状态描述
|
|
Data any `json:"data,omitempty"` // 响应数据,错误时省略
|
|
}
|
|
|
|
// OK 构造成功响应。
|
|
func OK(data any) Response {
|
|
return Response{Code: 0, Message: "ok", Data: data}
|
|
}
|
|
|
|
// Fail 构造错误响应。
|
|
func Fail(code int, msg string) Response {
|
|
return Response{Code: code, Message: msg}
|
|
}
|