Created
April 16, 2015 10:23
-
-
Save beefsack/d6cbea75e0f7e31f4a70 to your computer and use it in GitHub Desktop.
omitempty not working for empty time.Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "time" | |
| r "github.com/dancannon/gorethink" | |
| ) | |
| type Blah struct { | |
| Id string `gorethink:"id,omitempty"` | |
| Time time.Time `gorethink:"time,omitempty"` | |
| } | |
| func main() { | |
| s, err := r.Connect(r.ConnectOpts{ | |
| Address: "localhost:28015", | |
| }) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| // Ignore errors here for the sake of brevity. | |
| r.DbCreate("test").RunWrite(s) | |
| r.Db("test").TableCreate("blah").RunWrite(s) | |
| r.Db("test").Table("blah").Delete().RunWrite(s) | |
| log.Print("Testing insert with empty Time") | |
| wr, err := r.Db("test").Table("blah").Insert(Blah{}).RunWrite(s) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| id := wr.GeneratedKeys[0] | |
| log.Printf("Inserted with id %s", id) | |
| log.Print("Grabbing it back") | |
| cur, err := r.Db("test").Table("blah").Get(id).Run(s) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| b := Blah{} | |
| if err := cur.One(&b); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Got time %s", b.Time) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment