Created
August 14, 2013 14:11
-
-
Save chritchens/6231402 to your computer and use it in GitHub Desktop.
An example of use of go-couchbase, a go driver for the NoSQL database Couchbase
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 "fmt" | |
| import "log" | |
| import "time" | |
| import "github.com/couchbaselabs/go-couchbase" | |
| type Person struct { | |
| Name string `json:name` | |
| Surname string `json:surname` | |
| Gender string `json:gender` | |
| Birthday time.Time `json:birthday` | |
| Location Geopoint | |
| } | |
| type Geopoint struct { | |
| Lat float64 `json:lat` | |
| Lon float64 `json:lon` | |
| } | |
| // absolutely casual | |
| var newyork = Geopoint{7.9,165.8} | |
| var russel = Person{"Bertrand", "Russel", "male", time.Now(), newyork} | |
| func main() { | |
| people, err := couchbase.GetBucket("http://localhost:8091/", "default", "people") | |
| if err != nil { | |
| log.Fatalf("Connection failed:", err) | |
| } | |
| ok, err := people.Add("russel", 0, russel) | |
| if ok != true { | |
| if err != nil { | |
| log.Fatalf("Failed adding Russel:", err) | |
| } | |
| log.Fatalf("Failed adding, but no error") | |
| } | |
| someone := new(Person) | |
| err = people.Get("russel", &someone) | |
| if err != nil { | |
| log.Fatalf("Failed to get Russel") | |
| } | |
| fmt.Println(someone) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment