summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-26 15:24:33 +0200
committerPaul Buetow <paul@buetow.org>2025-02-26 15:24:33 +0200
commit547afd8c0921a7de16f0a5ce8b5d8d09bb2268c8 (patch)
tree8490aee787d4c6f9b3e025b67d888a5367def91e /internal/config
parente735b56a704b7328e7e84def46fd6d248c51e38d (diff)
introduce run interval
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/args.go33
-rw-r--r--internal/config/config.go (renamed from internal/config/secrets.go)36
2 files changed, 40 insertions, 29 deletions
diff --git a/internal/config/args.go b/internal/config/args.go
index e2b9dc1..d1a23b9 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -9,22 +9,23 @@ import (
)
type Args struct {
- GosDir string
- CacheDir string
- DryRun bool
- Platforms map[string]int // Platform and post size limits
- Target int
- MinQueued int
- MaxDaysQueued int
- PauseDays int
- Lookback time.Duration
- SecretsConfigPath string
- Secrets Secrets
- OAuth2Browser string
- GeminiSummaryFor []string
- GemtexterEnable bool
- GeminiCapsules []string
- ComposeMode bool
+ GosDir string
+ CacheDir string
+ DryRun bool
+ Platforms map[string]int // Platform and post size limits
+ Target int
+ MinQueued int
+ MaxDaysQueued int
+ PauseDays int
+ RunInterval time.Duration
+ Lookback time.Duration
+ ConfigPath string
+ Config Config
+ OAuth2Browser string
+ GeminiSummaryFor []string
+ GemtexterEnable bool
+ GeminiCapsules []string
+ ComposeMode bool
}
func (a *Args) ParsePlatforms(platformStrs string) error {
diff --git a/internal/config/secrets.go b/internal/config/config.go
index b4e629f..f865b67 100644
--- a/internal/config/secrets.go
+++ b/internal/config/config.go
@@ -5,12 +5,14 @@ import (
"fmt"
"io"
"os"
+ "path/filepath"
"codeberg.org/snonux/gos/internal/colour"
)
-// The config file containing all the secrets and credentials.
-type Secrets struct {
+// The config file containing all the secrets and credentials plus maybe more.
+type Config struct {
+ LastRunEpoch int64 `json:"LastRunEpoch,omitempty"`
MastodonURL string
MastodonAccessToken string
LinkedInClientID string
@@ -22,33 +24,41 @@ type Secrets struct {
LinkedInPersonID string `json:"LinkedInPersonID,omitempty"`
}
-func NewSecrets(configPath string, composeEntry bool) (Secrets, error) {
- var sec Secrets
- if composeEntry {
- // In compose mode, no need to read the secrets.
- return sec, nil
+func New(configPath string, composeEntry bool) (Config, error) {
+ var conf Config
+
+ _, err := os.Stat(configPath)
+ if os.IsNotExist(err) {
+ if !composeEntry {
+ return conf, fmt.Errorf("No config file %s", configPath)
+ }
+ // Create empty new config for compose mode.
+ return conf, conf.WriteToDisk(configPath)
}
file, err := os.Open(configPath)
if err != nil {
- return sec, fmt.Errorf("failed to open file: %w", err)
+ return conf, fmt.Errorf("failed to open file: %w", err)
}
defer file.Close()
bytes, err := io.ReadAll(file)
if err != nil {
- return sec, fmt.Errorf("failed to read file: %w", err)
+ return conf, fmt.Errorf("failed to read file: %w", err)
}
- if err := json.Unmarshal(bytes, &sec); err != nil {
- return sec, fmt.Errorf("failed to unmarshal JSON: %w", err)
+ if err := json.Unmarshal(bytes, &conf); err != nil {
+ return conf, fmt.Errorf("failed to unmarshal JSON: %w", err)
}
- return sec, nil
+ return conf, nil
}
-func (s Secrets) WriteToDisk(configPath string) error {
+func (s Config) WriteToDisk(configPath string) error {
colour.Infoln("Writing", configPath)
+ if err := os.MkdirAll(filepath.Dir(configPath), os.ModePerm); err != nil {
+ return err
+ }
bytes, err := json.MarshalIndent(s, "", " ")
if err != nil {