From 2ff5b759540d8437b52689436a2d64273754cb2f Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 17 Nov 2024 18:46:14 -0500 Subject: Perplexity is struggling https://www.perplexity.ai/search/write-a-go-program-that-will-p-YxH8FdyoRESJ0lyPEvthqw --- main.go | 18 +++++++++++++----- 1 file 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 { -- cgit