A demo of a Bluesky feed generator in Go

initial implementation of a demo bluesky feed generator

willdot.net b903c24a

+1098
+4
.env-example
··· 1 + FEED_DID_BASE="test" 2 + FEED_HOST_NAME="test" 3 + FEED_NAME="test-feed" 4 + SERVER_PORT="3000"
+1
.gitignore
··· 1 + .env
+116
consumer.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + "encoding/json" 6 + "strings" 7 + 8 + "fmt" 9 + "log/slog" 10 + "time" 11 + 12 + apibsky "github.com/bluesky-social/indigo/api/bsky" 13 + "github.com/bluesky-social/jetstream/pkg/client" 14 + "github.com/bluesky-social/jetstream/pkg/client/schedulers/sequential" 15 + "github.com/bluesky-social/jetstream/pkg/models" 16 + ) 17 + 18 + // JetstreamConsumer is responsible for consuming from a jetstream instance 19 + type JetstreamConsumer struct { 20 + cfg *client.ClientConfig 21 + handler *Handler 22 + logger *slog.Logger 23 + } 24 + 25 + func newJetstreamConsumer(jsAddr string, logger *slog.Logger, handler *Handler) *JetstreamConsumer { 26 + cfg := client.DefaultClientConfig() 27 + if jsAddr != "" { 28 + cfg.WebsocketURL = jsAddr 29 + } 30 + cfg.WantedCollections = []string{ 31 + "app.bsky.feed.post", 32 + } 33 + cfg.WantedDids = []string{} 34 + 35 + return &JetstreamConsumer{ 36 + cfg: cfg, 37 + logger: logger, 38 + handler: handler, 39 + } 40 + } 41 + 42 + // Consume will connect to a Jetstream client and start to consume and handle messages from it 43 + func (c *JetstreamConsumer) Consume(ctx context.Context) error { 44 + scheduler := sequential.NewScheduler("jetstream", c.logger, c.handler.HandleEvent) 45 + defer scheduler.Shutdown() 46 + 47 + client, err := client.NewClient(c.cfg, c.logger, scheduler) 48 + if err != nil { 49 + return fmt.Errorf("failed to create client: %w", err) 50 + } 51 + 52 + cursor := time.Now().Add(1 * -time.Minute).UnixMicro() 53 + 54 + if err := client.ConnectAndRead(ctx, &cursor); err != nil { 55 + return fmt.Errorf("connect and read: %w", err) 56 + } 57 + 58 + slog.Info("stopping consume") 59 + return nil 60 + } 61 + 62 + // Handler is responsible for handling a message consumed from Jetstream 63 + type Handler struct { 64 + store PostStore 65 + } 66 + 67 + // HandleEvent will handle an event based on the event's commit operation 68 + func (h *Handler) HandleEvent(ctx context.Context, event *models.Event) error { 69 + if event.Commit == nil { 70 + return nil 71 + } 72 + 73 + switch event.Commit.Operation { 74 + case models.CommitOperationCreate: 75 + return h.handleCreateEvent(ctx, event) 76 + // TODO: handle deletes too 77 + default: 78 + return nil 79 + } 80 + } 81 + 82 + func (h *Handler) handleCreateEvent(_ context.Context, event *models.Event) error { 83 + if event.Commit.Collection != "app.bsky.feed.post" { 84 + return nil 85 + } 86 + 87 + var bskyPost apibsky.FeedPost 88 + if err := json.Unmarshal(event.Commit.Record, &bskyPost); err != nil { 89 + // ignore this 90 + return nil 91 + } 92 + 93 + // look for any post that contains the #golang hashtag 94 + if !strings.Contains(strings.ToLower(bskyPost.Text), "#golang") { 95 + return nil 96 + } 97 + 98 + createdAt, err := time.Parse(time.RFC3339, bskyPost.CreatedAt) 99 + if err != nil { 100 + slog.Error("parsing createdAt time from post", "error", err, "timestamp", bskyPost.CreatedAt) 101 + createdAt = time.Now().UTC() 102 + } 103 + 104 + postURI := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", event.Did, event.Commit.RKey) 105 + post := Post{ 106 + RKey: event.Commit.RKey, 107 + PostURI: postURI, 108 + CreatedAt: createdAt.UnixMilli(), 109 + } 110 + err = h.store.CreatePost(post) 111 + if err != nil { 112 + slog.Error("error creating post in store", "error", err) 113 + return nil 114 + } 115 + return nil 116 + }
database.db

This is a binary file and will not be displayed.

+118
database.go
··· 1 + package main 2 + 3 + import ( 4 + "database/sql" 5 + "errors" 6 + "fmt" 7 + "log/slog" 8 + "os" 9 + 10 + _ "github.com/glebarez/go-sqlite" 11 + ) 12 + 13 + // Database is a sqlite database 14 + type Database struct { 15 + db *sql.DB 16 + } 17 + 18 + func newDatabase(dbPath string) (*Database, error) { 19 + if dbPath != ":memory:" { 20 + err := createDbFile(dbPath) 21 + if err != nil { 22 + return nil, fmt.Errorf("create db file: %w", err) 23 + } 24 + } 25 + 26 + db, err := sql.Open("sqlite", dbPath) 27 + if err != nil { 28 + return nil, fmt.Errorf("open database: %w", err) 29 + } 30 + 31 + err = db.Ping() 32 + if err != nil { 33 + return nil, fmt.Errorf("ping db: %w", err) 34 + } 35 + 36 + err = createPostsTable(db) 37 + if err != nil { 38 + return nil, fmt.Errorf("creating posts table: %w", err) 39 + } 40 + 41 + return &Database{db: db}, nil 42 + } 43 + 44 + func (d *Database) close() { 45 + err := d.db.Close() 46 + if err != nil { 47 + slog.Error("failed to close db", "error", err) 48 + } 49 + } 50 + 51 + func createDbFile(dbFilename string) error { 52 + if _, err := os.Stat(dbFilename); !errors.Is(err, os.ErrNotExist) { 53 + return nil 54 + } 55 + 56 + f, err := os.Create(dbFilename) 57 + if err != nil { 58 + return fmt.Errorf("create db file : %w", err) 59 + } 60 + f.Close() 61 + return nil 62 + } 63 + 64 + func createPostsTable(db *sql.DB) error { 65 + createTableSQL := `CREATE TABLE IF NOT EXISTS posts ( 66 + "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, 67 + "postRKey" TEXT, 68 + "postURI" TEXT, 69 + "createdAt" integer NOT NULL, 70 + UNIQUE(postRKey) 71 + );` 72 + 73 + slog.Info("Create posts table...") 74 + statement, err := db.Prepare(createTableSQL) 75 + if err != nil { 76 + return fmt.Errorf("prepare DB statement to create posts table: %w", err) 77 + } 78 + _, err = statement.Exec() 79 + if err != nil { 80 + return fmt.Errorf("exec sql statement to create posts table: %w", err) 81 + } 82 + slog.Info("posts table created") 83 + 84 + return nil 85 + } 86 + 87 + // CreatePost will insert a post into a database 88 + func (d *Database) CreatePost(post Post) error { 89 + sql := `INSERT INTO posts (postRKey, postURI, createdAt) VALUES (?, ?, ?) ON CONFLICT(postRKey) DO NOTHING;` 90 + _, err := d.db.Exec(sql, post.RKey, post.PostURI, post.CreatedAt) 91 + if err != nil { 92 + return fmt.Errorf("exec insert post: %w", err) 93 + } 94 + return nil 95 + } 96 + 97 + // GetFeedPosts return a slice of posts 98 + func (d *Database) GetFeedPosts(cursor, limit int) ([]Post, error) { 99 + sql := `SELECT id, postRKey, postURI, createdAt FROM posts 100 + WHERE createdAt < ? 101 + ORDER BY createdAt DESC LIMIT ?;` 102 + rows, err := d.db.Query(sql, cursor, limit) 103 + if err != nil { 104 + return nil, fmt.Errorf("run query to get feed posts: %w", err) 105 + } 106 + defer rows.Close() 107 + 108 + posts := make([]Post, 0) 109 + for rows.Next() { 110 + var post Post 111 + if err := rows.Scan(&post.ID, &post.RKey, &post.PostURI, &post.CreatedAt); err != nil { 112 + return nil, fmt.Errorf("scan row: %w", err) 113 + } 114 + posts = append(posts, post) 115 + } 116 + 117 + return posts, nil 118 + }
+72
feedgenerator.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + "log/slog" 7 + "strconv" 8 + ) 9 + 10 + // Post describes a Bluesky post 11 + type Post struct { 12 + ID int 13 + RKey string 14 + PostURI string 15 + UserDID string 16 + CreatedAt int64 17 + } 18 + 19 + // PostStore defines the interactions with a store 20 + type PostStore interface { 21 + GetFeedPosts(cursor, limit int) ([]Post, error) 22 + CreatePost(post Post) error 23 + } 24 + 25 + // FeedGenerator is responsible for generating a feed 26 + type FeedGenerator struct { 27 + store PostStore 28 + } 29 + 30 + func newFeedGenerator(store PostStore) *FeedGenerator { 31 + return &FeedGenerator{ 32 + store: store, 33 + } 34 + } 35 + 36 + // GetFeed will fetch a feed and build up a response that can be returned 37 + func (f *FeedGenerator) GetFeed(ctx context.Context, feed, cursor string, limit int) (FeedSkeletonReponse, error) { 38 + resp := FeedSkeletonReponse{ 39 + Feed: make([]FeedSkeletonPost, 0), 40 + } 41 + 42 + cursorInt, err := strconv.Atoi(cursor) 43 + if err != nil && cursor != "" { 44 + slog.Error("convert cursor to int", "error", err, "cursor value", cursor) 45 + } 46 + if cursorInt == 0 { 47 + // if no cursor provided use a date waaaaay in the future to start the less than query 48 + cursorInt = 9999999999999 49 + } 50 + 51 + posts, err := f.store.GetFeedPosts(cursorInt, limit) 52 + if err != nil { 53 + return resp, fmt.Errorf("get feed from DB: %w", err) 54 + } 55 + 56 + usersFeed := make([]FeedSkeletonPost, 0, len(posts)) 57 + for _, post := range posts { 58 + usersFeed = append(usersFeed, FeedSkeletonPost{ 59 + Post: post.PostURI, 60 + }) 61 + } 62 + 63 + resp.Feed = usersFeed 64 + 65 + // only set the return cursor if there was at least 1 record returned and that the len of records 66 + // being returned is the same as the limit 67 + if len(posts) > 0 && len(posts) == limit { 68 + lastPost := posts[len(posts)-1] 69 + resp.Cursor = fmt.Sprintf("%d", lastPost.CreatedAt) 70 + } 71 + return resp, nil 72 + }
+85
go.mod
··· 1 + module tangled.sh/willdot.net/feed-demo-go 2 + 3 + go 1.25.0 4 + 5 + require ( 6 + github.com/avast/retry-go/v4 v4.6.1 7 + github.com/bluesky-social/indigo v0.0.0-20250813051257-8be102876fb7 8 + github.com/bluesky-social/jetstream v0.0.0-20250815235753-306e46369336 9 + github.com/glebarez/go-sqlite v1.22.0 10 + github.com/golang-jwt/jwt/v5 v5.3.0 11 + github.com/joho/godotenv v1.5.1 12 + ) 13 + 14 + require ( 15 + github.com/beorn7/perks v1.0.1 // indirect 16 + github.com/carlmjohnson/versioninfo v0.22.5 // indirect 17 + github.com/cespare/xxhash/v2 v2.3.0 // indirect 18 + github.com/dustin/go-humanize v1.0.1 // indirect 19 + github.com/felixge/httpsnoop v1.0.4 // indirect 20 + github.com/go-logr/logr v1.4.1 // indirect 21 + github.com/go-logr/stdr v1.2.2 // indirect 22 + github.com/goccy/go-json v0.10.2 // indirect 23 + github.com/gogo/protobuf v1.3.2 // indirect 24 + github.com/google/uuid v1.6.0 // indirect 25 + github.com/gorilla/websocket v1.5.1 // indirect 26 + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 27 + github.com/hashicorp/go-retryablehttp v0.7.5 // indirect 28 + github.com/hashicorp/golang-lru v1.0.2 // indirect 29 + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect 30 + github.com/ipfs/bbloom v0.0.4 // indirect 31 + github.com/ipfs/go-block-format v0.2.0 // indirect 32 + github.com/ipfs/go-cid v0.4.1 // indirect 33 + github.com/ipfs/go-datastore v0.6.0 // indirect 34 + github.com/ipfs/go-ipfs-blockstore v1.3.1 // indirect 35 + github.com/ipfs/go-ipfs-ds-help v1.1.1 // indirect 36 + github.com/ipfs/go-ipfs-util v0.0.3 // indirect 37 + github.com/ipfs/go-ipld-cbor v0.1.0 // indirect 38 + github.com/ipfs/go-ipld-format v0.6.0 // indirect 39 + github.com/ipfs/go-log v1.0.5 // indirect 40 + github.com/ipfs/go-log/v2 v2.5.1 // indirect 41 + github.com/ipfs/go-metrics-interface v0.0.1 // indirect 42 + github.com/jbenet/goprocess v0.1.4 // indirect 43 + github.com/klauspost/compress v1.17.9 // indirect 44 + github.com/klauspost/cpuid/v2 v2.2.7 // indirect 45 + github.com/mattn/go-isatty v0.0.20 // indirect 46 + github.com/minio/sha256-simd v1.0.1 // indirect 47 + github.com/mr-tron/base58 v1.2.0 // indirect 48 + github.com/multiformats/go-base32 v0.1.0 // indirect 49 + github.com/multiformats/go-base36 v0.2.0 // indirect 50 + github.com/multiformats/go-multibase v0.2.0 // indirect 51 + github.com/multiformats/go-multihash v0.2.3 // indirect 52 + github.com/multiformats/go-varint v0.0.7 // indirect 53 + github.com/ncruces/go-strftime v0.1.9 // indirect 54 + github.com/opentracing/opentracing-go v1.2.0 // indirect 55 + github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect 56 + github.com/prometheus/client_golang v1.19.1 // indirect 57 + github.com/prometheus/client_model v0.6.1 // indirect 58 + github.com/prometheus/common v0.54.0 // indirect 59 + github.com/prometheus/procfs v0.15.1 // indirect 60 + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect 61 + github.com/spaolacci/murmur3 v1.1.0 // indirect 62 + github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e // indirect 63 + gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b // indirect 64 + gitlab.com/yawning/tuplehash v0.0.0-20230713102510-df83abbf9a02 // indirect 65 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect 66 + go.opentelemetry.io/otel v1.21.0 // indirect 67 + go.opentelemetry.io/otel/metric v1.21.0 // indirect 68 + go.opentelemetry.io/otel/trace v1.21.0 // indirect 69 + go.uber.org/atomic v1.11.0 // indirect 70 + go.uber.org/multierr v1.11.0 // indirect 71 + go.uber.org/zap v1.26.0 // indirect 72 + golang.org/x/crypto v0.41.0 // indirect 73 + golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 // indirect 74 + golang.org/x/net v0.43.0 // indirect 75 + golang.org/x/sys v0.35.0 // indirect 76 + golang.org/x/time v0.5.0 // indirect 77 + golang.org/x/tools v0.36.0 // indirect 78 + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect 79 + google.golang.org/protobuf v1.34.2 // indirect 80 + lukechampine.com/blake3 v1.2.1 // indirect 81 + modernc.org/libc v1.66.3 // indirect 82 + modernc.org/mathutil v1.7.1 // indirect 83 + modernc.org/memory v1.11.0 // indirect 84 + modernc.org/sqlite v1.38.2 // indirect 85 + )
+299
go.sum
··· 1 + github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 + github.com/avast/retry-go/v4 v4.6.1 h1:VkOLRubHdisGrHnTu89g08aQEWEgRU7LVEop3GbIcMk= 3 + github.com/avast/retry-go/v4 v4.6.1/go.mod h1:V6oF8njAwxJ5gRo1Q7Cxab24xs5NCWZBeaHHBklR8mA= 4 + github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 5 + github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 6 + github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 7 + github.com/bluesky-social/indigo v0.0.0-20250813051257-8be102876fb7 h1:FyoGfQFw/cTkDHdUTIYIHxfyUDgRS12K4o1mYC3ovRs= 8 + github.com/bluesky-social/indigo v0.0.0-20250813051257-8be102876fb7/go.mod h1:n6QE1NDPFoi7PRbMUZmc2y7FibCqiVU4ePpsvhHUBR8= 9 + github.com/bluesky-social/jetstream v0.0.0-20250815235753-306e46369336 h1:NM3wfeFUrdjCE/xHLXQorwQvEKlI9uqnWl7L0Y9KA8U= 10 + github.com/bluesky-social/jetstream v0.0.0-20250815235753-306e46369336/go.mod h1:3ihWQCbXeayg41G8lQ5DfB/3NnEhl0XX24eZ3mLpf7Q= 11 + github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc= 12 + github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8= 13 + github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= 14 + github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 15 + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 16 + github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 17 + github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 18 + github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 19 + github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= 20 + github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= 21 + github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= 22 + github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= 23 + github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ= 24 + github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc= 25 + github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 26 + github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= 27 + github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 28 + github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 29 + github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 30 + github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= 31 + github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= 32 + github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= 33 + github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 34 + github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 35 + github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo= 36 + github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= 37 + github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 38 + github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 39 + github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= 40 + github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= 41 + github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 42 + github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 43 + github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 44 + github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= 45 + github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 46 + github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= 47 + github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= 48 + github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= 49 + github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= 50 + github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= 51 + github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= 52 + github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= 53 + github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= 54 + github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= 55 + github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 56 + github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= 57 + github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= 58 + github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= 59 + github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= 60 + github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= 61 + github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= 62 + github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= 63 + github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= 64 + github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= 65 + github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= 66 + github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= 67 + github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= 68 + github.com/ipfs/go-ipfs-blockstore v1.3.1 h1:cEI9ci7V0sRNivqaOr0elDsamxXFxJMMMy7PTTDQNsQ= 69 + github.com/ipfs/go-ipfs-blockstore v1.3.1/go.mod h1:KgtZyc9fq+P2xJUiCAzbRdhhqJHvsw8u2Dlqy2MyRTE= 70 + github.com/ipfs/go-ipfs-ds-help v1.1.1 h1:B5UJOH52IbcfS56+Ul+sv8jnIV10lbjLF5eOO0C66Nw= 71 + github.com/ipfs/go-ipfs-ds-help v1.1.1/go.mod h1:75vrVCkSdSFidJscs8n4W+77AtTpCIAdDGAwjitJMIo= 72 + github.com/ipfs/go-ipfs-util v0.0.3 h1:2RFdGez6bu2ZlZdI+rWfIdbQb1KudQp3VGwPtdNCmE0= 73 + github.com/ipfs/go-ipfs-util v0.0.3/go.mod h1:LHzG1a0Ig4G+iZ26UUOMjHd+lfM84LZCrn17xAKWBvs= 74 + github.com/ipfs/go-ipld-cbor v0.1.0 h1:dx0nS0kILVivGhfWuB6dUpMa/LAwElHPw1yOGYopoYs= 75 + github.com/ipfs/go-ipld-cbor v0.1.0/go.mod h1:U2aYlmVrJr2wsUBU67K4KgepApSZddGRDWBYR0H4sCk= 76 + github.com/ipfs/go-ipld-format v0.6.0 h1:VEJlA2kQ3LqFSIm5Vu6eIlSxD/Ze90xtc4Meten1F5U= 77 + github.com/ipfs/go-ipld-format v0.6.0/go.mod h1:g4QVMTn3marU3qXchwjpKPKgJv+zF+OlaKMyhJ4LHPg= 78 + github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= 79 + github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= 80 + github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= 81 + github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= 82 + github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= 83 + github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= 84 + github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= 85 + github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= 86 + github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= 87 + github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= 88 + github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= 89 + github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 90 + github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 91 + github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 92 + github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 93 + github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 94 + github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= 95 + github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= 96 + github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= 97 + github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 98 + github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 99 + github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 100 + github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 101 + github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 102 + github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 103 + github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 104 + github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 105 + github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 106 + github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 107 + github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 108 + github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= 109 + github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= 110 + github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= 111 + github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= 112 + github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= 113 + github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= 114 + github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= 115 + github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= 116 + github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= 117 + github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= 118 + github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= 119 + github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= 120 + github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= 121 + github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= 122 + github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= 123 + github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= 124 + github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= 125 + github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= 126 + github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 127 + github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 128 + github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 129 + github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f h1:VXTQfuJj9vKR4TCkEuWIckKvdHFeJH/huIFJ9/cXOB0= 130 + github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= 131 + github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= 132 + github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= 133 + github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= 134 + github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= 135 + github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8= 136 + github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ= 137 + github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= 138 + github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= 139 + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= 140 + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= 141 + github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 142 + github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= 143 + github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= 144 + github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 145 + github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 146 + github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= 147 + github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= 148 + github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= 149 + github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= 150 + github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= 151 + github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 152 + github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 153 + github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 154 + github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 155 + github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 156 + github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 157 + github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 158 + github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 159 + github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 160 + github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ= 161 + github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= 162 + github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e h1:28X54ciEwwUxyHn9yrZfl5ojgF4CBNLWX7LR0rvBkf4= 163 + github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e/go.mod h1:pM99HXyEbSQHcosHc0iW7YFmwnscr+t9Te4ibko05so= 164 + github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 165 + github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 166 + github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 167 + gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b h1:CzigHMRySiX3drau9C6Q5CAbNIApmLdat5jPMqChvDA= 168 + gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b/go.mod h1:/y/V339mxv2sZmYYR64O07VuCpdNZqCTwO8ZcouTMI8= 169 + gitlab.com/yawning/tuplehash v0.0.0-20230713102510-df83abbf9a02 h1:qwDnMxjkyLmAFgcfgTnfJrmYKWhHnci3GjDqcZp1M3Q= 170 + gitlab.com/yawning/tuplehash v0.0.0-20230713102510-df83abbf9a02/go.mod h1:JTnUj0mpYiAsuZLmKjTx/ex3AtMowcCgnE7YNyCEP0I= 171 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24= 172 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo= 173 + go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= 174 + go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= 175 + go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= 176 + go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= 177 + go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= 178 + go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= 179 + go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= 180 + go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 181 + go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= 182 + go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= 183 + go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= 184 + go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= 185 + go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= 186 + go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= 187 + go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= 188 + go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= 189 + go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= 190 + go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= 191 + go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= 192 + go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= 193 + go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= 194 + go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= 195 + golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 196 + golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 197 + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 198 + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 199 + golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= 200 + golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= 201 + golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4= 202 + golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc= 203 + golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 204 + golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 205 + golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 206 + golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 207 + golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 208 + golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= 209 + golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= 210 + golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 211 + golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 212 + golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 213 + golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 214 + golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 215 + golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= 216 + golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= 217 + golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= 218 + golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 219 + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 220 + golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 221 + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 222 + golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= 223 + golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 224 + golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 225 + golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 226 + golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 227 + golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 228 + golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 229 + golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 230 + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 231 + golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 232 + golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 233 + golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= 234 + golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 235 + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 236 + golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 237 + golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 238 + golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= 239 + golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 240 + golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 241 + golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 242 + golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 243 + golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 244 + golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 245 + golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 246 + golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 247 + golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 248 + golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 249 + golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= 250 + golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= 251 + golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= 252 + golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 253 + golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 254 + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 255 + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 256 + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= 257 + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= 258 + google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= 259 + google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= 260 + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 261 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 262 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 263 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 264 + gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 265 + gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 266 + gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 267 + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 268 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 269 + gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 270 + gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 271 + honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 272 + lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= 273 + lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= 274 + modernc.org/cc/v4 v4.26.2 h1:991HMkLjJzYBIfha6ECZdjrIYz2/1ayr+FL8GN+CNzM= 275 + modernc.org/cc/v4 v4.26.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= 276 + modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU= 277 + modernc.org/ccgo/v4 v4.28.0/go.mod h1:JygV3+9AV6SmPhDasu4JgquwU81XAKLd3OKTUDNOiKE= 278 + modernc.org/fileutil v1.3.8 h1:qtzNm7ED75pd1C7WgAGcK4edm4fvhtBsEiI/0NQ54YM= 279 + modernc.org/fileutil v1.3.8/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc= 280 + modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI= 281 + modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito= 282 + modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks= 283 + modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI= 284 + modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ= 285 + modernc.org/libc v1.66.3/go.mod h1:XD9zO8kt59cANKvHPXpx7yS2ELPheAey0vjIuZOhOU8= 286 + modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= 287 + modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= 288 + modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= 289 + modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= 290 + modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8= 291 + modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns= 292 + modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= 293 + modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= 294 + modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek= 295 + modernc.org/sqlite v1.38.2/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E= 296 + modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= 297 + modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= 298 + modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= 299 + modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
+217
handlers.go
··· 1 + package main 2 + 3 + import ( 4 + "encoding/json" 5 + "fmt" 6 + "log/slog" 7 + "net/http" 8 + "net/url" 9 + "strconv" 10 + "strings" 11 + 12 + "github.com/bluesky-social/indigo/atproto/identity" 13 + "github.com/bluesky-social/indigo/atproto/syntax" 14 + "github.com/golang-jwt/jwt/v5" 15 + ) 16 + 17 + const ( 18 + defaultLimit = 50 19 + ES256K = "ES256K" 20 + ES256 = "ES256" 21 + ) 22 + 23 + // FeedSkeletonReponse describes a response that will contain a skeleton feed 24 + type FeedSkeletonReponse struct { 25 + Cursor string `json:"cursor"` 26 + Feed []FeedSkeletonPost `json:"feed"` 27 + } 28 + 29 + // FeedSkeletonPost describes an individual post which is just the post URI 30 + type FeedSkeletonPost struct { 31 + Post string `json:"post"` 32 + FeedContext string `json:"feedContext"` 33 + } 34 + 35 + // HandleGetFeedSkeleton is the handler that will build up and return a feed response 36 + func (s *Server) HandleGetFeedSkeleton(w http.ResponseWriter, r *http.Request) { 37 + slog.Debug("got request for feed skeleton", "host", r.RemoteAddr) 38 + 39 + // if you need to get a feed based on the user making the request you can use this to get the callers DID 40 + // _, err = getRequestUserDID(r) 41 + // if err != nil { 42 + // slog.Error("validate users auth", "error", err) 43 + // http.Error(w, "validate auth", http.StatusUnauthorized) 44 + // return 45 + // } 46 + 47 + params := r.URL.Query() 48 + 49 + feed := params.Get("feed") 50 + if feed == "" { 51 + slog.Error("missing feed query param", "host", r.RemoteAddr) 52 + http.Error(w, "missing feed query param", http.StatusBadRequest) 53 + return 54 + } 55 + slog.Debug("request for feed", "feed", feed) 56 + 57 + limit, err := limitFromParams(params) 58 + if err != nil { 59 + slog.Error("get limit from params", "error", err) 60 + http.Error(w, "invalid limit query param", http.StatusBadRequest) 61 + return 62 + } 63 + if limit < 1 || limit > 100 { 64 + limit = defaultLimit 65 + } 66 + 67 + cursor := params.Get("cursor") 68 + 69 + resp, err := s.feeder.GetFeed(r.Context(), feed, cursor, limit) 70 + if err != nil { 71 + slog.Error("get feed", "error", err, "feed", feed) 72 + http.Error(w, "error getting feed", http.StatusInternalServerError) 73 + return 74 + } 75 + 76 + b, err := json.Marshal(resp) 77 + if err != nil { 78 + slog.Error("marshall error", "error", err, "host", r.RemoteAddr) 79 + http.Error(w, "failed to encode resp", http.StatusInternalServerError) 80 + return 81 + } 82 + 83 + w.Header().Set("Content-Type", "application/json") 84 + 85 + _, _ = w.Write(b) 86 + } 87 + 88 + // DescribeFeedResponse is what's returned when the 'app.bsky.feed.describeFeedGenerator' endpoint is called 89 + type DescribeFeedResponse struct { 90 + DID string `json:"did"` 91 + Feeds []Feed `json:"feeds"` 92 + } 93 + 94 + // Feed describes the feed URI 95 + type Feed struct { 96 + URI string `json:"uri"` 97 + } 98 + 99 + // HandleDescribeFeedGenerator handles the describe feed generator endpoint 100 + func (s *Server) HandleDescribeFeedGenerator(w http.ResponseWriter, r *http.Request) { 101 + slog.Debug("got request for describe feed", "host", r.RemoteAddr) 102 + resp := DescribeFeedResponse{ 103 + DID: fmt.Sprintf("did:web:%s", s.feedHost), 104 + Feeds: []Feed{ 105 + { 106 + URI: fmt.Sprintf("at://%s/app.bsky.feed.generator/%s", s.feedDidBase, s.feedName), 107 + }, 108 + }, 109 + } 110 + 111 + b, err := json.Marshal(resp) 112 + if err != nil { 113 + http.Error(w, "failed to encode resp", http.StatusInternalServerError) 114 + return 115 + } 116 + 117 + _, _ = w.Write(b) 118 + } 119 + 120 + // WellKnownResponse is what's returned on a well-known endpoint 121 + type WellKnownResponse struct { 122 + Context []string `json:"@context"` 123 + Id string `json:"id"` 124 + Service []WellKnownService `json:"service"` 125 + } 126 + 127 + // WellKnownService describes the service returned on a well-known endpoint 128 + type WellKnownService struct { 129 + Id string `json:"id"` 130 + Type string `json:"type"` 131 + ServiceEndpoint string `json:"serviceEndpoint"` 132 + } 133 + 134 + // HandleWellKnown handles returning a well-known endpoint 135 + func (s *Server) HandleWellKnown(w http.ResponseWriter, r *http.Request) { 136 + slog.Debug("got request for well known", "host", r.RemoteAddr) 137 + resp := WellKnownResponse{ 138 + Context: []string{"https://www.w3.org/ns/did/v1"}, 139 + Id: fmt.Sprintf("did:web:%s", s.feedHost), 140 + Service: []WellKnownService{ 141 + { 142 + Id: "#bsky_fg", 143 + Type: "BskyFeedGenerator", 144 + ServiceEndpoint: fmt.Sprintf("https://%s", s.feedHost), 145 + }, 146 + }, 147 + } 148 + 149 + b, err := json.Marshal(resp) 150 + if err != nil { 151 + http.Error(w, "failed to encode resp", http.StatusInternalServerError) 152 + return 153 + } 154 + 155 + _, _ = w.Write(b) 156 + } 157 + 158 + func limitFromParams(params url.Values) (int, error) { 159 + limitStr := params.Get("limit") 160 + if limitStr == "" { 161 + return 0, nil 162 + } 163 + limit, err := strconv.Atoi(limitStr) 164 + if err != nil { 165 + return 0, fmt.Errorf("parsing limit param: %w", err) 166 + } 167 + return limit, nil 168 + } 169 + 170 + func checkUserAuth(r *http.Request) (string, error) { 171 + usersDID, err := getRequestUserDID(r) 172 + if err != nil { 173 + return "", fmt.Errorf("getting users did from request: %w", err) 174 + } 175 + return usersDID, nil 176 + } 177 + 178 + func getRequestUserDID(r *http.Request) (string, error) { 179 + headerValues := r.Header["Authorization"] 180 + 181 + if len(headerValues) != 1 { 182 + return "", fmt.Errorf("missing authorization header") 183 + } 184 + token := strings.TrimSpace(strings.Replace(headerValues[0], "Bearer ", "", 1)) 185 + 186 + keyfunc := func(token *jwt.Token) (any, error) { 187 + did := syntax.DID(token.Claims.(jwt.MapClaims)["iss"].(string)) 188 + identity, err := identity.DefaultDirectory().LookupDID(r.Context(), did) 189 + if err != nil { 190 + return nil, fmt.Errorf("unable to resolve did %s: %s", did, err) 191 + } 192 + key, err := identity.PublicKey() 193 + if err != nil { 194 + return nil, fmt.Errorf("signing key not found for did %s: %s", did, err) 195 + } 196 + return key, nil 197 + } 198 + 199 + validMethods := jwt.WithValidMethods([]string{ES256, ES256K}) 200 + 201 + parsedToken, err := jwt.ParseWithClaims(token, jwt.MapClaims{}, keyfunc, validMethods) 202 + if err != nil { 203 + return "", fmt.Errorf("invalid token: %s", err) 204 + } 205 + 206 + claims, ok := parsedToken.Claims.(jwt.MapClaims) 207 + if !ok { 208 + return "", fmt.Errorf("token contained no claims") 209 + } 210 + 211 + issVal, ok := claims["iss"].(string) 212 + if !ok { 213 + return "", fmt.Errorf("iss claim missing") 214 + } 215 + 216 + return string(syntax.DID(issVal)), nil 217 + }
+128
main.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + "errors" 6 + "fmt" 7 + "log" 8 + "log/slog" 9 + "os" 10 + "os/signal" 11 + "path" 12 + "strconv" 13 + "syscall" 14 + 15 + "github.com/avast/retry-go/v4" 16 + "github.com/joho/godotenv" 17 + ) 18 + 19 + const ( 20 + defaultJetstreamAddr = "wss://jetstream.atproto.tools/subscribe" 21 + defaultServerPort = 3000 22 + ) 23 + 24 + func main() { 25 + err := run() 26 + if err != nil { 27 + log.Fatal(err) 28 + } 29 + } 30 + 31 + func run() error { 32 + err := godotenv.Load() 33 + if err != nil && !os.IsNotExist(err) { 34 + return fmt.Errorf("Error loading .env file") 35 + } 36 + 37 + signals := make(chan os.Signal, 1) 38 + signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT) 39 + 40 + feedDidBase := os.Getenv("FEED_DID_BASE") 41 + if feedDidBase == "" { 42 + return fmt.Errorf("FEED_DID_BASE not set") 43 + } 44 + feedHost := os.Getenv("FEED_HOST_NAME") 45 + if feedHost == "" { 46 + return fmt.Errorf("FEED_HOST_NAME not set") 47 + } 48 + feedName := os.Getenv("FEED_NAME") 49 + if feedHost == "" { 50 + return fmt.Errorf("FEED_NAME not set") 51 + } 52 + serverPort, err := getServerPort() 53 + if err != nil { 54 + return err 55 + } 56 + dbPath := os.Getenv("DATABASE_PATH") 57 + if dbPath == "" { 58 + dbPath = "./" 59 + } 60 + 61 + dbFilename := path.Join(dbPath, "database.db") 62 + database, err := newDatabase(dbFilename) 63 + if err != nil { 64 + return fmt.Errorf("create new store: %w", err) 65 + } 66 + defer database.close() 67 + 68 + feeder := newFeedGenerator(database) 69 + 70 + ctx, cancel := context.WithCancel(context.Background()) 71 + defer cancel() 72 + 73 + go consumeLoop(ctx, database) 74 + 75 + server, err := NewServer(serverPort, feedHost, feedDidBase, feedName, feeder) 76 + if err != nil { 77 + return fmt.Errorf("create new server: %w", err) 78 + } 79 + go func() { 80 + <-signals 81 + cancel() 82 + _ = server.Stop(context.Background()) 83 + }() 84 + 85 + server.Run() 86 + return nil 87 + } 88 + 89 + func consumeLoop(ctx context.Context, database *Database) { 90 + handler := Handler{ 91 + store: database, 92 + } 93 + 94 + jsServerAddr := os.Getenv("JS_SERVER_ADDR") 95 + if jsServerAddr == "" { 96 + jsServerAddr = defaultJetstreamAddr 97 + } 98 + 99 + consumer := newJetstreamConsumer(jsServerAddr, slog.Default(), &handler) 100 + 101 + _ = retry.Do(func() error { 102 + err := consumer.Consume(ctx) 103 + if err != nil { 104 + // if the context has been cancelled then it's time to exit 105 + if errors.Is(err, context.Canceled) { 106 + return nil 107 + } 108 + slog.Error("consume loop", "error", err) 109 + return err 110 + } 111 + return nil 112 + }, retry.Attempts(0)) // retry indefinitly until context canceled 113 + 114 + slog.Warn("exiting consume loop") 115 + } 116 + 117 + func getServerPort() (int, error) { 118 + portStr := os.Getenv("SERVER_PORT") 119 + if portStr == "" { 120 + return defaultServerPort, nil 121 + } 122 + 123 + port, err := strconv.Atoi(portStr) 124 + if err != nil { 125 + return 0, fmt.Errorf("invalid port specified: %w", err) 126 + } 127 + return port, nil 128 + }
+58
server.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + _ "embed" 6 + "fmt" 7 + "log/slog" 8 + "net/http" 9 + ) 10 + 11 + // Feeder describes building up a feed 12 + type Feeder interface { 13 + GetFeed(ctx context.Context, feed, cursor string, limit int) (FeedSkeletonReponse, error) 14 + } 15 + 16 + // Server is the feed server that will be called when a user requests to view a feed 17 + type Server struct { 18 + httpsrv *http.Server 19 + feeder Feeder 20 + feedHost string 21 + feedDidBase string 22 + feedName string 23 + } 24 + 25 + // NewServer builds a server - call the Run function to start the server 26 + func NewServer(port int, feedHost, feedDidBase, feedName string, feeder Feeder) (*Server, error) { 27 + srv := &Server{ 28 + feedHost: feedHost, 29 + feedDidBase: feedDidBase, 30 + feedName: feedName, 31 + feeder: feeder, 32 + } 33 + 34 + mux := http.NewServeMux() 35 + mux.HandleFunc("/xrpc/app.bsky.feed.getFeedSkeleton", srv.HandleGetFeedSkeleton) 36 + mux.HandleFunc("/xrpc/app.bsky.feed.describeFeedGenerator", srv.HandleDescribeFeedGenerator) 37 + mux.HandleFunc("/.well-known/did.json", srv.HandleWellKnown) 38 + addr := fmt.Sprintf("0.0.0.0:%d", port) 39 + 40 + srv.httpsrv = &http.Server{ 41 + Addr: addr, 42 + Handler: mux, 43 + } 44 + return srv, nil 45 + } 46 + 47 + // Run will start the server - it is a blocking function 48 + func (s *Server) Run() { 49 + err := s.httpsrv.ListenAndServe() 50 + if err != nil { 51 + slog.Error("listen and serve", "error", err) 52 + } 53 + } 54 + 55 + // Stop will shutdown the server 56 + func (s *Server) Stop(ctx context.Context) error { 57 + return s.httpsrv.Shutdown(ctx) 58 + }