@cryptotaxi247 / kubo / commits / e5e121a6b

commands: Made Request#Option also return an existence bool

Matt Bell committed Oct 15, 2014 at 21:20 UTC e5e121a6b19cccc92e6e31459e14412a3023fac1
2 files changed +5 -4
commands/request.go
+3 -2
@@ -21,8 +21,9 @@ func (r *Request) SetPath(path []string) {
21 r.path = path
22 }
23
24 -func (r *Request) Option(name string) interface{} {
25 - return r.options[name]
24 +func (r *Request) Option(name string) (interface{}, bool) {
25 + val, ok := r.options[name]
26 + return val, ok
27 }
28
29 func (r *Request) SetOption(name string, value interface{}) {
commands/response.go
+2 -2
@@ -57,8 +57,8 @@ func (r *Response) Marshal() ([]byte, error) {
57 return nil, fmt.Errorf("No error or value set, there is nothing to marshal")
58 }
59
60 - enc := r.req.Option("enc")
61 - if enc == nil {
60 + enc, ok := r.req.Option("enc")
61 + if !ok || enc.(string) == "" {
62 return nil, fmt.Errorf("No encoding type was specified")
63 }
64 encType := EncodingType(strings.ToLower(enc.(string)))