2024-11-17 18:46:14 -05:00
parent aa421dab8c
commit 2ff5b75954

18
main.go
View File

@@ -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 {