1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-02 12:20:03 +08:00

commands: Safer type coercion when choosing marshaller

This commit is contained in:
Matt Bell
2014-11-03 23:08:41 -08:00
committed by Juan Batiz-Benet
parent 0149f65c6c
commit 33ad56e6d0

View File

@ -120,11 +120,12 @@ func (r *response) Marshal() ([]byte, error) {
return []byte{}, nil
}
enc, ok := r.req.Option(EncShort)
if !ok || enc.(string) == "" {
enc, found := r.req.Option(EncShort)
encStr, ok := enc.(string)
if !found || !ok || encStr == "" {
return nil, fmt.Errorf("No encoding type was specified")
}
encType := EncodingType(strings.ToLower(enc.(string)))
encType := EncodingType(strings.ToLower(encStr))
marshaller, ok := marshallers[encType]
if !ok {