forked from azer/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
42 lines (33 loc) · 786 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
42
package atlas
import "encoding/json"
type Response struct {
Code int
Context interface{}
}
type SuccessResponseContext struct {
Result interface{} `json:"result"`
Ok bool `json:"ok"`
}
type ErrorResponseContext struct {
Error interface{} `json:"error"`
}
var NotFound = Error(404, "404 - Not found.")
func (response *Response) Stringify() string {
parsed, _ := json.MarshalIndent(response.Context, "", " ")
return string(parsed)
}
func Manual(code int, anything interface{}) *Response {
return &Response{code, anything}
}
func Success(anything interface{}) *Response {
return &Response{
200,
&SuccessResponseContext{anything, true},
}
}
func Error(code int, err interface{}) *Response {
return &Response{
code,
&ErrorResponseContext{err},
}
}