summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-04 10:31:35 +0300
committerPaul Buetow <paul@buetow.org>2024-10-04 10:31:35 +0300
commit68b2a1ba2615c19642c8417d1350b9c6b867b1bb (patch)
treeb298e4c4c0c313c5b8ade72986e2865f18706639 /internal
parentd5edaafc454dffd50cac1fed3cf03fbe9a05c50c (diff)
initial secrets config and initial mastodon
Diffstat (limited to 'internal')
-rw-r--r--internal/config/args.go1
-rw-r--r--internal/config/secrets.go33
-rw-r--r--internal/platforms/mastodon/mastodon.go42
3 files changed, 76 insertions, 0 deletions
diff --git a/internal/config/args.go b/internal/config/args.go
index 39e6762..b380dcd 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -15,6 +15,7 @@ type Args struct {
Platforms []string
Target int
Lookback time.Duration
+ Secrets Secrets
}
func (a Args) Validate() error {
diff --git a/internal/config/secrets.go b/internal/config/secrets.go
new file mode 100644
index 0000000..bd35fb7
--- /dev/null
+++ b/internal/config/secrets.go
@@ -0,0 +1,33 @@
+package config
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+)
+
+type Secrets struct {
+ MastodonURL string
+ MastodonAccessToken string
+}
+
+func NewSecrets(configPath string) (Secrets, error) {
+ var sec Secrets
+ file, err := os.Open(configPath)
+ if err != nil {
+ return sec, 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)
+ }
+
+ if err := json.Unmarshal(bytes, &sec); err != nil {
+ return sec, fmt.Errorf("failed to unmarshal JSON: %w", err)
+ }
+
+ return sec, nil
+}
diff --git a/internal/platforms/mastodon/mastodon.go b/internal/platforms/mastodon/mastodon.go
new file mode 100644
index 0000000..e31947c
--- /dev/null
+++ b/internal/platforms/mastodon/mastodon.go
@@ -0,0 +1,42 @@
+package mastodon
+
+import (
+ "context"
+
+ "codeberg.org/snonux/gos/internal/config"
+ "codeberg.org/snonux/gos/internal/entry"
+)
+
+func Post(ctx context.Context, args config.Args, ent entry.Entry) error {
+ // payload := map[string]string{"status": status}
+ // payloadBytes, err := json.Marshal(payload)
+ // if err != nil {
+ // return fmt.Errorf("failed to marshal payload: %w", err)
+ // }
+
+ // // Create the HTTP request
+ // req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes))
+ // if err != nil {
+ // return fmt.Errorf("failed to create request: %w", err)
+ // }
+
+ // // Set headers
+ // req.Header.Set("Authorization", "Bearer "+config.AccessToken)
+ // req.Header.Set("Content-Type", "application/json")
+
+ // // Execute the request
+ // client := &http.Client{}
+ // resp, err := client.Do(req)
+ // if err != nil {
+ // return fmt.Errorf("request failed: %w", err)
+ // }
+ // defer resp.Body.Close()
+
+ // // Check for HTTP errors
+ // if resp.StatusCode != http.StatusOK {
+ // return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
+ // }
+
+ // fmt.Println("Message posted to Mastodon successfully")
+ return nil
+}