github.com/bububa/oceanengine/marketing-api@v0.0.0-20210315120513-0b953137f7a6/model/response.go (about)

     1  package model
     2  
     3  import "fmt"
     4  
     5  type Response interface {
     6  	IsError() bool
     7  	Error() string
     8  }
     9  
    10  type BaseResponse struct {
    11  	Code      int    `json:"code,omitempty"`
    12  	Message   string `json:"message,omitempty"`
    13  	RequestID string `json:"request_id,omitempty"`
    14  }
    15  
    16  func (r BaseResponse) IsError() bool {
    17  	return r.Code != 0
    18  }
    19  
    20  func (r BaseResponse) Error() string {
    21  	return fmt.Sprintf("%d:%s", r.Code, r.Message)
    22  }