navigaid
3/13/2019 - 10:14 AM

couchdb.go

// example adapted from https://github.com/go-kivik/kivik
package main

import (
        "context"
        "fmt"

        // "github.com/flimzy/kivik" // Stable version of Kivik
        _ "github.com/go-kivik/couchdb" // The CouchDB driver
        "github.com/go-kivik/kivik"     // Development version of Kivik
)

func main() {
        client, err := kivik.New("couch", "http://localhost:5986/")
        if err != nil {
                panic(err)
        }

        if err := client.CreateDB(context.TODO(), "animals"); err != nil {
                panic(err)
        }

        db := client.DB(context.TODO(), "animals")
        /*
                db, err := client.DB(context.TODO(), "animals")
                if err != nil {
                        panic(err)
                }
        */

        doc := map[string]interface{}{
                "_id":      "cow",
                "feet":     4,
                "greeting": "moo",
        }

        rev, err := db.Put(context.TODO(), "cow", doc)
        if err != nil {
                panic(err)
        }
        fmt.Printf("Cow inserted with revision %s\n", rev)
}
docker run -it -p 5986:5986 couchdb