summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/main.go b/main.go
index e5ed1b0..131e8d1 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
- "fmt"
"log"
"os"
"os/signal"
@@ -22,6 +21,18 @@ type BlueskyPost struct {
} `json:"record"`
}
+func createNATSSubject(userID, postType string, timestamp time.Time) string {
+ parts := []string{"bsky", "feed", "post"}
+ if userID != "" {
+ parts = append(parts, "user", userID)
+ }
+ if postType != "" {
+ parts = append(parts, "type", postType)
+ }
+ parts = append(parts, "time", timestamp.Format("20060102"))
+ return strings.Join(parts, ".")
+}
+
func main() {
// Connect to NATS
nc, err := nats.Connect(nats.DefaultURL)
@@ -62,10 +73,7 @@ func main() {
}
// Create a more detailed NATS subject
- subject := fmt.Sprintf("bsky.feed.post.user.%s.type.%s.time.%s",
- userID,
- postType,
- post.Record.CreatedAt.Format("20060102"))
+ subject := createNATSSubject(userID, postType, post.Record.CreatedAt)
// Publish the JSON message to NATS with the detailed subject
if err := nc.Publish(subject, message); err != nil {