Skip to content

Commit 0fbb8be

Browse files
committed
types: fix godoc and add compile-time interface assertion
1 parent 3f9d8c3 commit 0fbb8be

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type ID struct {
2424
Number int64
2525
}
2626

27+
// String implements fmt.Stringer.
28+
//
2729
// String returns a string representation of the ID.
2830
// The representation is non ambiguous, string forms are quoted, number forms
2931
// are preceded by a #.
@@ -38,7 +40,7 @@ func (id *ID) String() string {
3840
return "#" + strconv.FormatInt(id.Number, 10)
3941
}
4042

41-
// MarshalJSON implements json.MarshalJSON.
43+
// MarshalJSON implements json.Marshaler.
4244
func (id *ID) MarshalJSON() ([]byte, error) {
4345
if id.Name != "" {
4446
return json.Marshal(id.Name)
@@ -47,7 +49,7 @@ func (id *ID) MarshalJSON() ([]byte, error) {
4749
return json.Marshal(id.Number)
4850
}
4951

50-
// UnmarshalJSON implements json.UnmarshalJSON.
52+
// UnmarshalJSON implements json.Unmarshaler.
5153
func (id *ID) UnmarshalJSON(data []byte) error {
5254
*id = ID{}
5355
if err := json.Unmarshal(data, &id.Number); err == nil {
@@ -57,6 +59,9 @@ func (id *ID) UnmarshalJSON(data []byte) error {
5759
return json.Unmarshal(data, &id.Name)
5860
}
5961

62+
var _ json.Marshaler = (*ID)(nil)
63+
var _ json.Unmarshaler = (*ID)(nil)
64+
6065
// RawMessage mimic json.RawMessage
6166
// RawMessage is a raw encoded JSON value.
6267
// It implements Marshaler and Unmarshaler and can

0 commit comments

Comments
 (0)