From fdb1591d2f93bbbbc0fc9f59704f7f21a72fccdb Mon Sep 17 00:00:00 2001 From: Patrick Dewey
Date: Sat, 23 May 2026 18:16:51 -0400 Subject: [PATCH] refactor: use `slices.Clone` in jetstream listener --- jetstream/jetstream.go | 13 +++++++------ public.go | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jetstream/jetstream.go b/jetstream/jetstream.go index 06fd035..b993c84 100644 --- a/jetstream/jetstream.go +++ b/jetstream/jetstream.go @@ -25,6 +25,7 @@ import ( "encoding/json" "fmt" "net/url" + "slices" "sync" "sync/atomic" "time" @@ -194,8 +195,8 @@ func (c *Config) readDeadline() time.Duration { // optionsUpdateMessage is the jetstream control frame for runtime filter // updates. See https://github.com/bluesky-social/jetstream for the schema. type optionsUpdateMessage struct { - Type string `json:"type"` - Payload optionsUpdatePayload `json:"payload"` + Type string `json:"type"` + Payload optionsUpdatePayload `json:"payload"` } type optionsUpdatePayload struct { @@ -251,8 +252,8 @@ func New(cfg *Config, handler Handler) *Consumer { handler: handler, stopCh: make(chan struct{}), zstdDecoder: decoder, - wantedCollections: append([]string(nil), cfg.WantedCollections...), - wantedDIDs: append([]string(nil), cfg.WantedDIDs...), + wantedCollections: slices.Clone(cfg.WantedCollections), + wantedDIDs: slices.Clone(cfg.WantedDIDs), } c.currentEndpoint.Store("") @@ -309,8 +310,8 @@ func (c *Consumer) Stats() (eventsReceived, bytesReceived int64) { // Passing nil slices is equivalent to passing empty slices: the filter is // cleared and the relay delivers all events for that dimension. func (c *Consumer) UpdateOptions(wantedCollections, wantedDIDs []string) error { - collsCopy := append([]string(nil), wantedCollections...) - didsCopy := append([]string(nil), wantedDIDs...) + collsCopy := slices.Clone(wantedCollections) + didsCopy := slices.Clone(wantedDIDs) c.optMu.Lock() c.wantedCollections = collsCopy diff --git a/public.go b/public.go index 1911bb5..3757329 100644 --- a/public.go +++ b/public.go @@ -22,7 +22,6 @@ var PublicAPIBase = "https://public.api.bsky.app" // This is a variable so tests can override it. var PLCDirectory = "https://plc.directory" - // ErrSSRFBlocked is returned when a request is blocked due to a private/internal destination. var ErrSSRFBlocked = errors.New("request blocked: potential SSRF detected") @@ -373,7 +372,7 @@ func (c *PublicClient) ListAllRecords(ctx context.Context, did, collection strin var all []Record cursor := "" - for page := 0; page < maxPages; page++ { + for range maxPages { records, next, err := c.ListPublicRecords(ctx, did, collection, ListPublicRecordsOpts{ Limit: pageSize, Cursor: cursor, -- 2.51.2