35 lines
738 B
Go
35 lines
738 B
Go
package service
|
|
|
|
import (
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
http2 "net/http"
|
|
)
|
|
|
|
// BaseService order 公共方法
|
|
type BaseService struct {
|
|
}
|
|
|
|
type BaseResponse struct {
|
|
Code int `json:"code"`
|
|
Data interface{} `json:"data"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// ResponseOK 返回 json 成功
|
|
func (b *BaseService) ResponseOK(ctx http.Context, data interface{}) error {
|
|
return ctx.JSON(http2.StatusOK, &BaseResponse{
|
|
Code: http2.StatusOK,
|
|
Data: data,
|
|
Message: "",
|
|
})
|
|
}
|
|
|
|
// ResponseError 返回 json 错误
|
|
func (b *BaseService) ResponseError(ctx http.Context, error string) error {
|
|
return ctx.JSON(http2.StatusOK, &BaseResponse{
|
|
Code: 4001,
|
|
Data: nil,
|
|
Message: error,
|
|
})
|
|
}
|