add missing file

fix-typeof-id
Yasuhiro Matsumoto 2017-10-23 23:53:03 +09:00
parent 3274f13917
commit e03b8ccefb
1 changed files with 25 additions and 0 deletions

25
compat.go 100644
View File

@ -0,0 +1,25 @@
package mastodon
import (
"encoding/json"
"fmt"
)
type ID string
func (id *ID) UnmarshalJSON(data []byte) error {
if len(data) > 0 && data[0] == '"' && data[len(data)-1] == '"' {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
*id = ID(s)
return nil
}
var n int64
if err := json.Unmarshal(data, &n); err != nil {
return err
}
*id = ID(fmt.Sprint(n))
return nil
}