uuid
6:e0d83ad4145f Browse Files
Update uuid dependency, drop XML support. Drop our XML support (who likes XML? I hope they vendored.) Update the underlying implementation to use its new home on Github. While we're at it, change all the methods to use methods from the underlying implementation, where possible. Looks like the author got around to adding some of the nicer methods for implementing interfaces in the standard library.
1.1 --- a/uuid.go Thu Dec 03 10:55:00 2015 -0800 1.2 +++ b/uuid.go Mon Dec 14 03:47:41 2015 -0800 1.3 @@ -2,11 +2,9 @@ 1.4 1.5 import ( 1.6 "database/sql/driver" 1.7 - "encoding/json" 1.8 - "encoding/xml" 1.9 "errors" 1.10 1.11 - "code.google.com/p/go-uuid/uuid" 1.12 + "github.com/pborman/uuid" 1.13 ) 1.14 1.15 var InvalidIDError = errors.New("Invalid ID format.") 1.16 @@ -45,77 +43,19 @@ 1.17 } 1.18 1.19 func (id ID) MarshalJSON() ([]byte, error) { 1.20 - return json.Marshal(id.String()) 1.21 -} 1.22 - 1.23 -func (id ID) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 1.24 - return e.EncodeElement(id.String(), start) 1.25 + return uuid.ID(id).MarshalJSON() 1.26 } 1.27 1.28 func (id ID) Value() (driver.Value, error) { 1.29 - return id.String(), nil 1.30 + return uuid.ID(id).Value() 1.31 } 1.32 1.33 func (id *ID) Scan(src interface{}) error { 1.34 - if src == nil { 1.35 - id = nil 1.36 - return nil 1.37 - } 1.38 - switch src.(type) { 1.39 - case []byte: 1.40 - if len(src.([]byte)) == 0 { 1.41 - *id = (*id)[:0] 1.42 - return nil 1.43 - } 1.44 - newID, err := Parse(string(src.([]byte))) 1.45 - if err != nil { 1.46 - return err 1.47 - } 1.48 - *id = append((*id)[:0], newID...) 1.49 - return nil 1.50 - case string: 1.51 - if len(src.(string)) == 0 { 1.52 - *id = (*id)[:0] 1.53 - return nil 1.54 - } 1.55 - newID, err := Parse(src.(string)) 1.56 - if err != nil { 1.57 - return err 1.58 - } 1.59 - *id = append((*id)[:0], newID...) 1.60 - return nil 1.61 - default: 1.62 - return InvalidIDError 1.63 - } 1.64 - return nil 1.65 + return (*uuid.ID)(id).Scan(src) 1.66 } 1.67 1.68 func (id *ID) UnmarshalJSON(in []byte) error { 1.69 - var tmp string 1.70 - err := json.Unmarshal(in, &tmp) 1.71 - if err != nil { 1.72 - return err 1.73 - } 1.74 - newID, err := Parse(tmp) 1.75 - if err != nil { 1.76 - return err 1.77 - } 1.78 - *id = append((*id)[:0], newID...) 1.79 - return nil 1.80 -} 1.81 - 1.82 -func (id *ID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 1.83 - var tmp string 1.84 - err := d.DecodeElement(&tmp, &start) 1.85 - if err != nil { 1.86 - return err 1.87 - } 1.88 - newID, err := Parse(tmp) 1.89 - if err != nil { 1.90 - return err 1.91 - } 1.92 - *id = append((*id)[:0], newID...) 1.93 - return nil 1.94 + return (*uuid.ID)(id).UnmarshalJSON(in) 1.95 } 1.96 1.97 func Parse(in string) (ID, error) {