-
Notifications
You must be signed in to change notification settings - Fork 244
/
api.go
56 lines (45 loc) · 1.53 KB
/
api.go
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
48
49
50
51
52
53
54
55
56
package browsers
import (
"context"
"github.com/ethereum/go-ethereum/log"
)
func NewAPI(db *Database) *API {
return &API{db: db}
}
// API is class with methods available over RPC.
type API struct {
db *Database
}
func (api *API) AddBrowser(ctx context.Context, browser Browser) error {
return api.db.InsertBrowser(browser)
}
func (api *API) GetBrowsers(ctx context.Context) ([]*Browser, error) {
return api.db.GetBrowsers()
}
func (api *API) DeleteBrowser(ctx context.Context, id string) error {
return api.db.DeleteBrowser(id)
}
func (api *API) GetBookmarks(ctx context.Context) ([]*Bookmark, error) {
log.Debug("call to get bookmarks")
rst, err := api.db.GetBookmarks()
log.Debug("result from database for bookmarks", "len", len(rst))
return rst, err
}
func (api *API) StoreBookmark(ctx context.Context, bookmark Bookmark) (Bookmark, error) {
log.Debug("call to create a bookmark")
bookmarkResult, err := api.db.StoreBookmark(bookmark)
log.Debug("result from database for creating a bookmark", "err", err)
return bookmarkResult, err
}
func (api *API) UpdateBookmark(ctx context.Context, originalURL string, bookmark Bookmark) error {
log.Debug("call to update a bookmark")
err := api.db.UpdateBookmark(originalURL, bookmark)
log.Debug("result from database for updating a bookmark", "err", err)
return err
}
func (api *API) DeleteBookmark(ctx context.Context, url string) error {
log.Debug("call to remove a bookmark")
err := api.db.DeleteBookmark(url)
log.Debug("result from database for remove a bookmark", "err", err)
return err
}