mirror of
https://git.robbyzambito.me/bluesky-nats-proxy/
synced 2025-12-21 00:34:50 +00:00
Perplexity is struggling
https://www.perplexity.ai/search/write-a-go-program-that-will-p-YxH8FdyoRESJ0lyPEvthqw
This commit is contained in:
18
main.go
18
main.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -22,6 +21,18 @@ type BlueskyPost struct {
|
|||||||
} `json:"record"`
|
} `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() {
|
func main() {
|
||||||
// Connect to NATS
|
// Connect to NATS
|
||||||
nc, err := nats.Connect(nats.DefaultURL)
|
nc, err := nats.Connect(nats.DefaultURL)
|
||||||
@@ -62,10 +73,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a more detailed NATS subject
|
// Create a more detailed NATS subject
|
||||||
subject := fmt.Sprintf("bsky.feed.post.user.%s.type.%s.time.%s",
|
subject := createNATSSubject(userID, postType, post.Record.CreatedAt)
|
||||||
userID,
|
|
||||||
postType,
|
|
||||||
post.Record.CreatedAt.Format("20060102"))
|
|
||||||
|
|
||||||
// Publish the JSON message to NATS with the detailed subject
|
// Publish the JSON message to NATS with the detailed subject
|
||||||
if err := nc.Publish(subject, message); err != nil {
|
if err := nc.Publish(subject, message); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user