-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.go
More file actions
47 lines (39 loc) · 1.2 KB
/
database.go
File metadata and controls
47 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gocouchlib
import (
"net/http"
)
type Database struct {
DbName string
Server *Server
}
func (db *Database) endpoint(api string) string {
return db.Server.FullUrl() + "/" + db.DbName + api
}
// Check whether the database exists
// HEAD /{db}
func (db *Database) Exists() (bool, *CouchResponse) {
couchResp, _ := httpClient.Head(db.endpoint("/"), nil)
return couchResp.StatusCode == http.StatusOK, couchResp
}
// Retrieves database information
// GET /{db}
func (db *Database) Info() (JsonObj, *CouchResponse) {
couchResp, _ := httpClient.Get(db.endpoint("/"), nil)
return couchResp.Json, couchResp
}
func (db *Database) Create() (bool, *CouchResponse) {
couchResp, _ := httpClient.Put(db.endpoint("/"), nil, nil)
return couchResp.StatusCode == http.StatusCreated, couchResp
}
// Deletes database
// DELETE /{db}
func (db *Database) Delete() (bool, *CouchResponse) {
couchResp, _ := httpClient.Delete(db.endpoint("/"))
return couchResp.StatusCode == http.StatusOK, couchResp
}
// Compact database
// POST /{db}/_compact
func (db *Database) Compact() (bool, *CouchResponse) {
couchResp, _ := httpClient.Post(db.endpoint("/_compact"), nil)
return couchResp.StatusCode == http.StatusAccepted, couchResp
}