forked from bububa/oceanengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
38 lines (33 loc) · 834 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
package model
import (
"strconv"
"strings"
)
// 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 {
var builder strings.Builder
builder.WriteString(strconv.Itoa(r.Code))
builder.WriteString(":")
builder.WriteString(r.Message)
return builder.String()
}