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:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user