package apiresp import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" ) type apiResponse struct { ErrCode int `json:"errCode"` ErrMsg string `json:"errMsg"` ErrDlt string `json:"errDlt"` Data any `json:"data,omitempty"` } func apiSuccess(data any) *apiResponse { return &apiResponse{ Data: data, } } func apiError(err error) *apiResponse { unwrap := errs.Unwrap(err) if codeErr, ok := unwrap.(errs.CodeError); ok { return &apiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()} } return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()} }