summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-09-28 11:26:17 +0300
committerPaul Buetow <paul@buetow.org>2024-09-28 11:26:17 +0300
commit262af22115291863609319b6b0f313873891e15f (patch)
tree4b62032a5f3e8076a14e536df094433017de8ed5
parent6865389682c865717bb28f19943c09d0610a7981 (diff)
add Validation
-rw-r--r--cmd/gos/main.go4
-rw-r--r--internal/config/args.go18
-rw-r--r--internal/schedule/stats.go1
3 files changed, 21 insertions, 2 deletions
diff --git a/cmd/gos/main.go b/cmd/gos/main.go
index 1248239..2a457d4 100644
--- a/cmd/gos/main.go
+++ b/cmd/gos/main.go
@@ -29,6 +29,10 @@ func main() {
Lookback: time.Duration(*lookback) * time.Hour * 24,
}
+ if err := args.Validate(); err != nil {
+ log.Fatal(err)
+ }
+
if *version {
fmt.Printf("This is Gos version %s; (C) by Paul Buetow\n", versionStr)
fmt.Println("https://codeberg.org/snonux/gos")
diff --git a/internal/config/args.go b/internal/config/args.go
index b71c53e..78b55de 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -1,6 +1,13 @@
package config
-import "time"
+import (
+ "fmt"
+ "slices"
+ "strings"
+ "time"
+)
+
+var validPlatforms = []string{"mastodon", "linkedin"}
type Args struct {
GosDir string
@@ -8,3 +15,12 @@ type Args struct {
Platforms []string
Lookback time.Duration
}
+
+func (a Args) Validate() error {
+ for _, platform := range a.Platforms {
+ if !slices.Contains(validPlatforms, strings.ToLower(platform)) {
+ return fmt.Errorf("Platform %s not supported", platform)
+ }
+ }
+ return nil
+}
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go
index d6cbf20..a969272 100644
--- a/internal/schedule/stats.go
+++ b/internal/schedule/stats.go
@@ -52,7 +52,6 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error {
)
var errs []error
- // TODO: Maybe refactor to include in ReadDirFilter filter
for filePath := range ch {
entryTime, err := parseEntryPath(filePath)
if err != nil {