33 lines
808 B
Go
33 lines
808 B
Go
package result
|
|
|
|
import (
|
|
"PCM/common/tool"
|
|
"context"
|
|
)
|
|
|
|
type ResponseSuccessBean struct {
|
|
Code uint32 `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data"`
|
|
TraceID string `json:"traceId,omitempty"`
|
|
}
|
|
type NullJson struct{}
|
|
|
|
func Success(data interface{}, ctx context.Context) *ResponseSuccessBean {
|
|
resp := ResponseSuccessBean{}
|
|
tool.Convert(data, resp)
|
|
traceID := traceIDFromContext(ctx)
|
|
return &ResponseSuccessBean{200, "OK", data, traceID}
|
|
}
|
|
|
|
type ResponseErrorBean struct {
|
|
Code uint32 `json:"code"`
|
|
Msg string `json:"msg"`
|
|
TraceID string `json:"traceId,omitempty"`
|
|
}
|
|
|
|
func Error(errCode uint32, errMsg string, ctx context.Context) *ResponseErrorBean {
|
|
traceID := traceIDFromContext(ctx)
|
|
return &ResponseErrorBean{errCode, errMsg, traceID}
|
|
}
|