-
Notifications
You must be signed in to change notification settings - Fork 42
/
response.go
41 lines (35 loc) · 929 Bytes
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package model
import (
"strconv"
"github.com/bububa/oceanengine/marketing-api/util"
)
// Response api response interface
type Response interface {
// IsError 是否返回错误
IsError() bool
// Error implement error interface
Error() string
}
// BaseResponse shared api response data fields
type BaseResponse struct {
// Code 返回码
Code int `json:"code"`
// Message 返回信息
Message string `json:"message"`
// RequestID 请求的日志id,唯一标识一个请求
RequestID string `json:"request_id,omitempty"`
}
// IsError implement Response interface
func (r BaseResponse) IsError() bool {
return r.Code != 0
}
// Error implement Response interface
func (r BaseResponse) Error() string {
builder := util.GetStringsBuilder()
builder.WriteString(strconv.Itoa(r.Code))
builder.WriteString(":")
builder.WriteString(r.Message)
ret := builder.String()
util.PutStringsBuilder(builder)
return ret
}