Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 6cb8cee

Browse files
committed
added Delete to delete db doc
1 parent 2795724 commit 6cb8cee

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func getHost() (host string) {
2828
host = "https://na1.staticbackend.com"
2929
case RegionLocalDev, "":
3030
host = "http://localhost:8099"
31+
default:
32+
// for self-hosted instance
33+
host = Region
3134
}
3235
return
3336
}
@@ -111,3 +114,8 @@ func Put(token, url string, body interface{}, v interface{}) error {
111114
buf := bytes.NewReader(b)
112115
return request(token, "PUT", url, "application/json", buf, v)
113116
}
117+
118+
func del(token, url string) error {
119+
var v interface{}
120+
return request(token, http.MethodDelete, url, "application/json", nil, v)
121+
}

db.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ func Update(token, repo, id string, body interface{}, v interface{}) error {
129129
return Put(token, fmt.Sprintf("/db/%s/%s", repo, id), body, v)
130130
}
131131

132+
// Delete permanently delets a document
133+
func Delete(token, repo, id string) error {
134+
return del(token, fmt.Sprintf("/db/%s/%s", repo, id))
135+
}
136+
132137
// SudoCreate adds a new document to a repository and returns the created document.
133138
func SudoCreate(token, repo string, body interface{}, v interface{}) error {
134139
return Post(token, fmt.Sprintf("/sudo/%s", repo), body, v)

db_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,3 @@ type Voter struct {
100100
ProductID string `json:"productId"`
101101
UserID string `json:"userId"`
102102
}
103-
104-
func TestWTH(t *testing.T) {
105-
backend.PublicKey = "5fc640ff4eea8b872b907f8d"
106-
107-
products := make([]Product, 0)
108-
meta, err := backend.List("", "pub_posts_744_", &products, nil)
109-
if err != nil {
110-
t.Fatal(err)
111-
} else if meta.Total == 0 {
112-
t.Errorf("total is %d expected > 0", meta.Total)
113-
} else if meta.Results == nil {
114-
t.Error("Results is nil")
115-
}
116-
}

storage_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ func TestUploadFile(t *testing.T) {
1515
t.Fatal(err)
1616
}
1717

18-
u, err := backend.StoreFile(token, "unittest.go", f)
18+
res, err := backend.StoreFile(token, "unittest.go", f)
1919
if err != nil {
2020
t.Error(err)
21-
} else if strings.HasPrefix(u, "/_servefile_/") == false {
22-
t.Errorf("expected URL to have http as prefix got %s", u)
21+
} else if strings.HasPrefix(res.URL, "/_servefile_/") == false {
22+
t.Errorf("expected URL to have http as prefix got %s", res.URL)
2323
}
2424

2525
orig, err := ioutil.ReadAll(f)
2626
if err != nil {
2727
t.Fatal(err)
2828
}
2929

30-
buf, err := backend.DownloadFile(token, "http://localhost:8099"+u)
30+
buf, err := backend.DownloadFile(token, "http://localhost:8099"+res.URL)
3131
if err != nil {
3232
t.Error(err)
3333
} else if len(orig) != len(buf) {

0 commit comments

Comments
 (0)