aboutsummaryrefslogtreecommitdiffstats
path: root/api/dto/response.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/dto/response.go')
-rw-r--r--api/dto/response.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/api/dto/response.go b/api/dto/response.go
index 43f98bd..2c13218 100644
--- a/api/dto/response.go
+++ b/api/dto/response.go
@@ -2,20 +2,37 @@ package dto
import "fmt"
+type Response interface {
+ Error() string
+ Status() int
+}
+
type OkResponse struct {
Code int `json:"code"`
Data interface{} `json:"data,omitempty"`
}
+var _ Response = (*OkResponse)(nil)
+
type ErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}
+var _ Response = (*ErrorResponse)(nil)
+
+func (r *OkResponse) Status() int {
+ return r.Code
+}
+
func (r *OkResponse) Error() string {
return fmt.Sprintf("HTTP status %d", r.Code)
}
+func (r *ErrorResponse) Status() int {
+ return r.Code
+}
+
func (r *ErrorResponse) Error() string {
return fmt.Sprintf("HTTP status %d: %s", r.Code, r.Message)
}