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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
package response
import "fmt"
type no struct {
tag string
err error
items []Item
}
func No(withTag ...string) *no {
var tag string
if len(withTag) > 0 {
tag = withTag[0]
} else {
tag = "*"
}
return &no{
tag: tag,
}
}
func (r *no) WithItems(items ...Item) *no {
r.items = append(r.items, items...)
return r
}
func (r *no) WithError(err error) *no {
r.err = err
return r
}
func (r *no) Send(s Session) error {
return s.WriteResponse(r.String())
}
func (r *no) String() (res string) {
parts := []string{r.tag, "NO"}
if len(r.items) > 0 {
var items []string
for _, item := range r.items {
items = append(items, item.String())
}
parts = append(parts, fmt.Sprintf("[%v]", join(items)))
}
if r.err != nil {
parts = append(parts, r.err.Error())
}
return join(parts)
}
func (r *no) Error() string {
return r.err.Error()
}
|