generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponse.go
38 lines (31 loc) · 947 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
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package dnspodcn
import "fmt"
// Response is an interface.
type Response interface {
// Error returns the error of the status of request.
Error() error
}
// StatusResponse contains the infomation of status field.
type StatusResponse struct {
Code string `json:"code"`
Message string `json:"message"`
CreatedAt string `json:"created_at"`
}
// Error returns the error of the response.
func (resp StatusResponse) Error() error {
if resp.Code == CodeSuccess {
return nil
}
return fmt.Errorf("%s, code %s", resp.Message, resp.Code)
}
// BasicResponse contains the basic fields of response.
type BasicResponse struct {
Status StatusResponse `json:"status"`
}
// Error returns the error of the response.
func (resp BasicResponse) Error() error {
return resp.Status.Error()
}