Implementing independent or platform-specific code
The best way to learn is to put what has been learned into practice. In this section, we’ll revisit the audiofile
CLI to implement a few new commands. In the code for the new features we’ll implement, the focus will be on the use of the os
and path
/filepath
packages.
Platform-independent code
Let’s now implement a few new features for the audiofile
CLI that will run independently of the operating system:
Delete
: This deletes stored metadata by IDSearch
: This searches stored metadata for a specific search string
The creation of each of these new feature commands was initiated with the cobra-CLI; however, the platform-specific code is isolated in the storage/flatfile.go
file, which is the flat file storage for the storage interface.
First, let’s show the Delete
method:
func (f FlatFile) Delete(id string) error { dirname, err := os.UserHomeDir() ...