Browse Source

types: compile type assertions to avoid sneaky runtime surprises

Ensure that the types in result.go implement both
json.Marshaler and json.Unmarshaler
and thus avoid any accidental deletions of their respective
methods which would then cause surprises at runtime.
pull/1780/head
Emmanuel Odeke 7 years ago
parent
commit
7167d4e4c7
No known key found for this signature in database GPG Key ID: 1CA47A292F89DD40
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      types/result.go

+ 16
- 0
types/result.go View File

@ -2,6 +2,7 @@ package types
import (
"bytes"
"encoding/json"
"fmt"
"github.com/gogo/protobuf/jsonpb"
@ -137,3 +138,18 @@ func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*ResponseCommit)(nil)
var _ jsonRoundTripper = (*ResponseQuery)(nil)
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
var _ jsonRoundTripper = (*ResponseSetOption)(nil)

Loading…
Cancel
Save