Skip to content

Commit

Permalink
Merge pull request #117 from mattn/add-skipEventFunc
Browse files Browse the repository at this point in the history
add WithSkipEventFunc
  • Loading branch information
mattn authored Jul 14, 2024
2 parents 80050dd + 1d1d540 commit 7bd7458
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (s *Server) doReq(ctx context.Context, ws *WebSocket, request []json.RawMes
}
i := 0
for event := range events {
if s.options.skipEventFunc != nil && s.options.skipEventFunc(event) {
continue
}
ws.WriteJSON(nostr.EventEnvelope{SubscriptionID: &id, Event: *event})
i++
if i > filter.Limit {
Expand Down
8 changes: 8 additions & 0 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/fasthttp/websocket"
"github.com/nbd-wtf/go-nostr"
"github.com/rs/cors"
"golang.org/x/time/rate"
)
Expand Down Expand Up @@ -158,6 +159,7 @@ type Option func(*Options)

type Options struct {
perConnectionLimiter *rate.Limiter
skipEventFunc func(*nostr.Event) bool
}

func DefaultOptions() *Options {
Expand All @@ -170,6 +172,12 @@ func WithPerConnectionLimiter(rps rate.Limit, burst int) Option {
}
}

func WithSkipEventFunc(skipEventFunc func(*nostr.Event) bool) Option {
return func(o *Options) {
o.skipEventFunc = skipEventFunc
}
}

func defaultLogger(prefix string) Logger {
l := log.New(os.Stderr, "", log.LstdFlags|log.Lmsgprefix)
l.SetPrefix(prefix)
Expand Down

0 comments on commit 7bd7458

Please sign in to comment.