CouchDB client
Install with:
go get github.com/tetsuo/couchdbThen use it like this:
package main
import (
"context"
"github.com/tetsuo/couchdb"
)
func main() {
client := couchdb.NewClient("http://localhost:5984")
// Create services
dbs := couchdb.NewDatabaseService(client) // or client.Databases()
docs := couchdb.Documents()
ctx := context.Background()
// Admin creates database
dbs.CreateDatabase(ctx, "users_db", nil,
couchdb.WithBasicAuth("admin", "adminpass"))
// User creates document
doc := map[string]any{
"name": "John Doe",
"email": "john@example.com",
}
docs.CreateDocument(ctx, "users_db", doc, nil,
couchdb.WithBasicAuth("john", "johnpass"))
// Different user with JWT token
docs.GetDocument(ctx, "users_db", "doc123", nil,
couchdb.WithJWTAuth("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))
}Supported authentication methods:
WithBasicAuth(username, password string)— HTTP Basic AuthWithJWTAuth(token string)— JWT Bearer tokenWithCookieAuth(cookie *http.Cookie)— Session cookieWithProxyAuth(username string, roles []string, token string)— Proxy auth
Tested with CouchDB v3.5.x, but should work with other 3.x versions as well.
Not yet. If you need a specific API that is not implemented, feel free to open an issue or contribute a PR. For example, cluster and replication APIs are not yet implemented.
Full API documentation is at pkg.go.dev.