uuid
uuid/uuid.go
Support XML marshaling/unmarshaling. Because why not? Just implement the methods necessary for XML support.
1.1 --- a/uuid.go Sat Sep 27 20:53:17 2014 -0400 1.2 +++ b/uuid.go Wed Dec 17 22:28:44 2014 -0500 1.3 @@ -4,6 +4,7 @@ 1.4 "database/sql/driver" 1.5 "encoding/hex" 1.6 "encoding/json" 1.7 + "encoding/xml" 1.8 "errors" 1.9 1.10 "code.google.com/p/go-uuid/uuid" 1.11 @@ -21,6 +22,10 @@ 1.12 return json.Marshal(id.String()) 1.13 } 1.14 1.15 +func (id ID) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 1.16 + return e.EncodeElement(id.String(), start) 1.17 +} 1.18 + 1.19 func (id ID) String() string { 1.20 return hex.EncodeToString([]byte(id)) 1.21 } 1.22 @@ -63,6 +68,20 @@ 1.23 return nil 1.24 } 1.25 1.26 +func (id *ID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 1.27 + var tmp string 1.28 + err := d.DecodeElement(&tmp, &start) 1.29 + if err != nil { 1.30 + return err 1.31 + } 1.32 + newID, err := Parse(tmp) 1.33 + if err != nil { 1.34 + return err 1.35 + } 1.36 + *id = append((*id)[:0], newID...) 1.37 + return nil 1.38 +} 1.39 + 1.40 func Parse(in string) (ID, error) { 1.41 b, err := hex.DecodeString(in) 1.42 if err != nil {