Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(55)

Unified Diff: version/version.go

Issue 6493125: mstate: implement agent tools methods
Patch Set: mstate: implement agent tools methods Created 12 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mstate/unit.go ('k') | version/version_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: version/version.go
=== modified file 'version/version.go'
--- version/version.go 2012-08-17 15:34:45 +0000
+++ version/version.go 2012-09-17 11:04:58 +0000
@@ -5,6 +5,7 @@
import (
"fmt"
"io/ioutil"
+ "labix.org/v2/mgo/bson"
"os"
"path/filepath"
"regexp"
@@ -57,6 +58,28 @@
return fmt.Sprintf("%v-%s-%s", v.Number, v.Series, v.Arch)
}
+// GetBSON turns v into a bson.Getter so it can be saved directly
+// on a MongoDB database with mgo.
+func (v Binary) GetBSON() (interface{}, error) {
+ return v.String(), nil
+}
+
+// SetBSON turns v into a bson.Setter so it can be loaded directly
+// from a MongoDB database with mgo.
+func (vp *Binary) SetBSON(raw bson.Raw) error {
+ var s string
+ err := raw.Unmarshal(&s)
+ if err != nil {
+ return err
+ }
+ v, err := ParseBinary(s)
+ if err != nil {
+ return err
+ }
+ *vp = v
+ return nil
+}
+
var (
binaryPat = regexp.MustCompile(`^(\d{1,9})\.(\d{1,9})\.(\d{1,9})-([^-]+)-([^-]+)$`)
numberPat = regexp.MustCompile(`^(\d{1,9})\.(\d{1,9})\.(\d{1,9})$`)
@@ -140,6 +163,28 @@
return false
}
+// GetBSON turns v into a bson.Getter so it can be saved directly
+// on a MongoDB database with mgo.
+func (v Number) GetBSON() (interface{}, error) {
+ return v.String(), nil
+}
+
+// SetBSON turns v into a bson.Setter so it can be loaded directly
+// from a MongoDB database with mgo.
+func (vp *Number) SetBSON(raw bson.Raw) error {
+ var s string
+ err := raw.Unmarshal(&s)
+ if err != nil {
+ return err
+ }
+ v, err := Parse(s)
+ if err != nil {
+ return err
+ }
+ *vp = v
+ return nil
+}
+
func isOdd(x int) bool {
return x%2 != 0
}
« no previous file with comments | « mstate/unit.go ('k') | version/version_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b