aicra/api/response.go

31 lines
550 B
Go
Raw Normal View History

2018-10-07 09:23:00 +00:00
package api
2018-06-01 08:51:51 +00:00
import (
2018-07-05 17:15:57 +00:00
"git.xdrm.io/go/aicra/err"
2018-06-01 08:51:51 +00:00
)
2018-09-13 08:21:35 +00:00
// New creates an empty response
2018-10-07 09:23:00 +00:00
func NewResponse() *Response {
2018-06-01 08:51:51 +00:00
return &Response{
data: make(map[string]interface{}),
Err: err.Success,
}
}
2018-09-13 08:21:35 +00:00
// Set adds/overrides a new response field
2018-06-01 08:51:51 +00:00
func (i *Response) Set(name string, value interface{}) {
i.data[name] = value
}
2018-10-07 09:14:54 +00:00
// Get gets a response field
2018-06-01 08:51:51 +00:00
func (i *Response) Get(name string) interface{} {
value, _ := i.data[name]
return value
}
2018-09-13 08:21:35 +00:00
// Dump gets all key/value pairs
2018-06-01 08:51:51 +00:00
func (i *Response) Dump() map[string]interface{} {
return i.data
}