summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-12-13 21:39:53 -0500
committersiddharth <s@ricketyspace.net>2021-12-13 21:39:53 -0500
commit6683d9089d0de13c0709f4092f95592c3046a67d (patch)
treef97c71a2af4bc264d331869a7985033ba98b3680
parent9575ec614a5b0b0a0536e644fb426955ead01f08 (diff)
config/config.go: add docs.
-rw-r--r--config/config.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/config/config.go b/config/config.go
index 360d9a6..6d9ceaf 100644
--- a/config/config.go
+++ b/config/config.go
@@ -14,12 +14,18 @@ import (
"ricketyspace.net/fern/file"
)
+// Represents the fern config
type FernConfig struct {
- YDLPath string `json:"ydl-path"`
- DumpDir string `json:"dump-dir"`
- Feeds []feed.Feed `json:"feeds"`
+ YDLPath string `json:"ydl-path"` // Path to the youtube-dl program.
+ DumpDir string `json:"dump-dir"` // Path where media needs to be downloaded to.
+ Feeds []feed.Feed `json:"feeds"` // Feeds to download.
}
+// Tries to reads the fern config at `$HOME/.config/fern/fern.json`
+// and unmarshals it into `FernConfig`
+//
+// Returns point to `FernConfig` on success. On error, the returned
+// config is `nil` and the returned error is non-nil.
func Read() (*FernConfig, error) {
// Construct config file path.
h, err := os.UserHomeDir()
@@ -55,6 +61,9 @@ func Read() (*FernConfig, error) {
return config, nil
}
+// Validates the FernConfig.
+//
+// Returns nil if validation succeeds; error otherwise.
func (config *FernConfig) validate() error {
// Validate 'ydl-path' in config.
if len(config.YDLPath) == 0 {