From 8d302e422cf96c7b2e86fc45ec8a12fe1d21f903 Mon Sep 17 00:00:00 2001 From: Ivan Stefanov Date: Thu, 24 Jul 2014 16:30:29 +0300 Subject: [PATCH] Support any type that implements fmt.Stringer in ObjectIdHex and IsObjectIdHex instead of simple string --- bson/bson.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bson/bson.go b/bson/bson.go index 3ebfd8438..70dac0792 100644 --- a/bson/bson.go +++ b/bson/bson.go @@ -168,8 +168,8 @@ type ObjectId string // ObjectIdHex returns an ObjectId from the provided hex representation. // Calling this function with an invalid hex representation will // cause a runtime panic. See the IsObjectIdHex function. -func ObjectIdHex(s string) ObjectId { - d, err := hex.DecodeString(s) +func ObjectIdHex(s fmt.Stringer) ObjectId { + d, err := hex.DecodeString(s.String()) if err != nil || len(d) != 12 { panic(fmt.Sprintf("Invalid input to ObjectIdHex: %q", s)) } @@ -178,11 +178,11 @@ func ObjectIdHex(s string) ObjectId { // IsObjectIdHex returns whether s is a valid hex representation of // an ObjectId. See the ObjectIdHex function. -func IsObjectIdHex(s string) bool { - if len(s) != 24 { +func IsObjectIdHex(s fmt.Stringer) bool { + if len(s.String()) != 24 { return false } - _, err := hex.DecodeString(s) + _, err := hex.DecodeString(s.String()) return err == nil }