Ensure @thing:id is int64 if whole number

This commit is contained in:
Tobie Morgan Hitchcock 2016-10-29 10:20:10 +01:00
parent 67c32e5eea
commit abf9c937be

View file

@ -455,9 +455,10 @@ func (this Thing) MarshalText() (data []byte, err error) {
func NewThing(TB string, ID interface{}) *Thing {
if str, ok := ID.(string); ok {
if cnv, err := strconv.ParseInt(str, 10, 64); err == nil {
return &Thing{TB: TB, ID: cnv}
} else if cnv, err := strconv.ParseFloat(str, 64); err == nil {
if cnv, err := strconv.ParseFloat(str, 64); err == nil {
if cnv == float64(int64(cnv)) {
return &Thing{TB: TB, ID: int64(cnv)}
}
return &Thing{TB: TB, ID: cnv}
} else if cnv, err := time.Parse(RFCDate, str); err == nil {
return &Thing{TB: TB, ID: cnv.UTC()}