Documentation
¶
Overview ¶
Package couchdb provides a simple REST client for CouchDB
Index ¶
- type Auth
- type AuthInfo
- type AuthInfoResponse
- type BasicAuth
- type BulkDocument
- type BulkDocumentResult
- type Connection
- func (conn *Connection) AddUser(username string, password string, roles []string, auth Auth) (string, error)
- func (conn *Connection) CreateDB(name string, auth Auth) error
- func (conn *Connection) CreateSession(username string, password string) (*CookieAuth, error)
- func (conn *Connection) DeleteDB(name string, auth Auth) error
- func (conn *Connection) DeleteUser(username string, rev string, auth Auth) (string, error)
- func (conn *Connection) DestroySession(auth *CookieAuth) error
- func (conn *Connection) GetAuthInfo(auth Auth) (*AuthInfoResponse, error)
- func (conn *Connection) GetConfigOption(section string, option string, auth Auth) (string, error)
- func (conn *Connection) GetDBList() (dbList []string, err error)
- func (conn *Connection) GetUser(username string, userData interface{}, auth Auth) (string, error)
- func (conn *Connection) GrantRole(username string, role string, auth Auth) (string, error)
- func (conn *Connection) Ping() error
- func (conn *Connection) RevokeRole(username string, role string, auth Auth) (string, error)
- func (conn *Connection) SelectDB(dbName string, auth Auth) *Database
- func (conn *Connection) SetConfig(section string, option string, value string, auth Auth) error
- type ConnectionImpl
- type CookieAuth
- type Database
- func (db *Database) AddRole(role string, isAdmin bool) error
- func (db *Database) Compact() (resp string, e error)
- func (db *Database) Copy(fromId string, fromRev string, toId string) (string, error)
- func (db *Database) Delete(id string, rev string) (string, error)
- func (db *Database) DeleteAttachment(docId string, docRev string, attName string) (string, error)
- func (db *Database) GetAttachment(docId string, docRev string, attType string, attName string) (io.ReadCloser, error)
- func (db *Database) GetAttachmentByProxy(docId string, docRev string, attType string, attName string, r *http.Request, ...) error
- func (db *Database) GetList(designDoc string, list string, view string, results interface{}, ...) error
- func (db *Database) GetSecurity() (*Security, error)
- func (db *Database) GetView(designDoc string, view string, results interface{}, params *url.Values) error
- func (db *Database) NewBulkDocument() *BulkDocument
- func (db *Database) Read(id string, doc interface{}, params *url.Values) (string, error)
- func (db *Database) ReadMultiple(ids []string, results interface{}) error
- func (db *Database) RemoveRole(role string) error
- func (db *Database) Save(doc interface{}, id string, rev string) (string, error)
- func (db *Database) SaveAttachment(docId string, docRev string, attName string, attType string, ...) (string, error)
- func (db *Database) SaveDesignDoc(name string, designDoc interface{}, rev string) (string, error)
- func (db *Database) SaveSecurity(sec Security) error
- type Error
- type Members
- type PassThroughAuth
- type ProxyAuth
- type Security
- type UserContext
- type UserRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth interface { //Adds authentication headers to a request AddAuthHeaders(*http.Request) //Extracts Updated auth info from Couch Response UpdateAuth(*http.Response) //Sets updated auth (headers, cookies, etc.) in an http response //For the update function, the map keys are cookie and/or header names GetUpdatedAuth() map[string]string //Purely for debug purposes. Do not call, ever. DebugString() string }
Basic interface for Auth
type AuthInfoResponse ¶
type AuthInfoResponse struct { Info AuthInfo `json:"info"` Ok bool `json:"ok"` UserCtx UserContext `json:"userCtx"` }
type BasicAuth ¶
HTTP Basic Authentication support
func (*BasicAuth) AddAuthHeaders ¶
Adds Basic Authentication headers to an http request
func (*BasicAuth) DebugString ¶
func (*BasicAuth) GetUpdatedAuth ¶
Get Updated Auth Does nothing for BasicAuth
func (*BasicAuth) UpdateAuth ¶
do nothing for basic auth
type BulkDocument ¶
type BulkDocument struct {
// contains filtered or unexported fields
}
BulkDocument Bulk Document API http://docs.couchdb.org/en/1.6.1/api/database/bulk-api.html#db-bulk-docs
func (*BulkDocument) Commit ¶
func (b *BulkDocument) Commit() ([]BulkDocumentResult, error)
Commit POST /{db}/_bulk_docs
func (*BulkDocument) Delete ¶
func (b *BulkDocument) Delete(id, rev string) error
Delete Delete document
func (*BulkDocument) Save ¶
func (b *BulkDocument) Save(doc interface{}, id, rev string) error
Save Save document
type BulkDocumentResult ¶
type BulkDocumentResult struct { Ok bool `json:"ok"` ID string `json:"id"` Revision string `json:"rev"` Error *string `json:"error"` Reason *string `json:"reason"` }
BulkDocumentResult Bulk Document Response
type Connection ¶
type Connection struct{ *ConnectionImpl }
func NewConnection ¶
Creates a regular http ConnectionImpl. Timeout sets the timeout for the http Client
func NewSSLConnection ¶
Creates an https ConnectionImpl. Timeout sets the timeout for the http Client
func (*Connection) AddUser ¶
func (conn *Connection) AddUser(username string, password string, roles []string, auth Auth) (string, error)
AddUser creates a new CouchDB user. This is a convenience method for adding a simple user to CouchDB. If you need a User with custom fields, etc., you'll just have to use the ordinary document methods on the "_users" database.
func (*Connection) CreateDB ¶
func (conn *Connection) CreateDB(name string, auth Auth) error
CreateDB creates a new CouchDB Database.
func (*Connection) CreateSession ¶
func (conn *Connection) CreateSession(username string, password string) (*CookieAuth, error)
Creates a session using the Couchdb session api. Returns auth token on success
func (*Connection) DeleteDB ¶
func (conn *Connection) DeleteDB(name string, auth Auth) error
DeleteDB deletes a CouchDB Database.
func (*Connection) DeleteUser ¶
Delete a user.
func (*Connection) DestroySession ¶
func (conn *Connection) DestroySession(auth *CookieAuth) error
Destroys a session (user log out, etc.)
func (*Connection) GetAuthInfo ¶
func (conn *Connection) GetAuthInfo(auth Auth) (*AuthInfoResponse, error)
Returns auth information for a user
func (*Connection) GetConfigOption ¶
GetConfigOption gets a CouchDB configuration option
func (*Connection) GetDBList ¶
func (conn *Connection) GetDBList() (dbList []string, err error)
DATABASES. Return a list of all databases on the server
func (*Connection) GetUser ¶
func (conn *Connection) GetUser(username string, userData interface{}, auth Auth) (string, error)
Fetch a user record
func (*Connection) Ping ¶
func (conn *Connection) Ping() error
Use to check if database server is alive.
func (*Connection) RevokeRole ¶
RevokeRole removes a user role
type ConnectionImpl ¶
ConnectionImpl represents a couchdb connection implementation
type CookieAuth ¶
Cookie-based auth (for sessions)
func (*CookieAuth) AddAuthHeaders ¶
func (ca *CookieAuth) AddAuthHeaders(req *http.Request)
Adds session token to request
func (*CookieAuth) DebugString ¶
func (ca *CookieAuth) DebugString() string
func (*CookieAuth) GetUpdatedAuth ¶
func (ca *CookieAuth) GetUpdatedAuth() map[string]string
Set AuthSession Cookie
func (*CookieAuth) UpdateAuth ¶
func (ca *CookieAuth) UpdateAuth(resp *http.Response)
Couchdb returns updated AuthSession tokens
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func (*Database) Copy ¶
Copies a document into a new... document. Returns the revision of the newly created document
func (*Database) Delete ¶
Deletes a document. Or rather, tells CouchDB to mark the document as deleted. Yes, CouchDB will return a new revision, so this function returns it.
func (*Database) DeleteAttachment ¶
Deletes an attachment
func (*Database) GetAttachment ¶
func (db *Database) GetAttachment(docId string, docRev string, attType string, attName string) (io.ReadCloser, error)
Gets an attachment. Returns an io.Reader -- the onus is on the caller to close it. Please close it.
func (*Database) GetAttachmentByProxy ¶
func (db *Database) GetAttachmentByProxy(docId string, docRev string, attType string, attName string, r *http.Request, w http.ResponseWriter) error
Fetches an attachment and proxies the result
func (*Database) GetList ¶
func (db *Database) GetList(designDoc string, list string, view string, results interface{}, params *url.Values) error
Get the result of a list operation This assumes your list function in couchdb returns JSON
func (*Database) GetSecurity ¶
Returns the Security document from the database.
func (*Database) GetView ¶
func (db *Database) GetView(designDoc string, view string, results interface{}, params *url.Values) error
Get the results of a view.
func (*Database) NewBulkDocument ¶
func (db *Database) NewBulkDocument() *BulkDocument
NewBulkDocument New BulkDocument instance
func (*Database) Read ¶
Fetches a document from the database. Pass it a &struct to hold the contents of the fetched document (doc). Returns the current revision and/or error
func (*Database) ReadMultiple ¶
Fetches multiple documents in a single request given a set of arbitrary _ids
func (*Database) RemoveRole ¶
Security helper function. Removes a role from a database security doc.
func (*Database) Save ¶
Save a document to the database. If you're creating a new document, pass an empty string for rev. If updating, you must specify the current rev. Returns the revision number assigned to the doc by CouchDB.
func (*Database) SaveAttachment ¶
func (db *Database) SaveAttachment(docId string, docRev string, attName string, attType string, attContent io.Reader) (string, error)
Saves an attachment. docId and docRev refer to the parent document. attType is the MIME type of the attachment (ex: image/jpeg) or some such. attContent is a byte array containing the actual content.
func (*Database) SaveDesignDoc ¶
Save a design document. If creating a new design doc, set rev to "".
func (*Database) SaveSecurity ¶
Save a security document to the database.
type Error ¶
type PassThroughAuth ¶
type PassThroughAuth struct {
AuthHeader string
}
Pass-through Auth header
func (*PassThroughAuth) AddAuthHeaders ¶
func (pta *PassThroughAuth) AddAuthHeaders(req *http.Request)
Use if you already have an Authentication header you want to pass through to couchdb
func (*PassThroughAuth) DebugString ¶
func (pta *PassThroughAuth) DebugString() string
func (*PassThroughAuth) GetUpdatedAuth ¶
func (pta *PassThroughAuth) GetUpdatedAuth() map[string]string
Does nothing for PassThroughAuth
func (*PassThroughAuth) UpdateAuth ¶
func (pta *PassThroughAuth) UpdateAuth(resp *http.Response)
do nothing for pass through
type ProxyAuth ¶
Proxy authentication
func (*ProxyAuth) AddAuthHeaders ¶
func (*ProxyAuth) DebugString ¶
func (*ProxyAuth) GetUpdatedAuth ¶
do nothing for Proxy Auth
func (*ProxyAuth) UpdateAuth ¶
do nothing for proxy auth