Add a func to read bookmark from stored toml file

Given a bookmark path and bookmark name, GetBookmark
returns a Bookmark object that corresponds to the
stored bookmark settings.

In next commits, we will use this method to read
stored bookmarks and create a db client.
This commit is contained in:
akarki15
2016-11-10 01:22:07 -05:00
parent f4fb5744ef
commit 0e88e3e1f4
2 changed files with 41 additions and 0 deletions

View File

@@ -75,3 +75,22 @@ func ReadAll(path string) (map[string]Bookmark, error) {
return results, nil
}
type ErrNonExistingBookmark string
func (e ErrNonExistingBookmark) Error() string {
return fmt.Sprintf("couldn't find a bookmark with name %s", e)
}
func GetBookmark(bookmarkPath string, bookmarkName string) (Bookmark, error) {
bookmarks, err := ReadAll(bookmarkPath)
if err != nil {
return Bookmark{}, err
}
bookmark, ok := bookmarks[bookmarkName]
if !ok {
return Bookmark{}, ErrNonExistingBookmark(bookmarkName)
}
return bookmark, nil
}