add WithSkipEventFunc

This commit is contained in:
Yasuhiro Matsumoto
2024-07-13 18:07:36 +09:00
parent 80050ddbbf
commit 1d1d5408d4
2 changed files with 11 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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"
)
@@ -158,6 +159,7 @@ type Option func(*Options)
type Options struct {
perConnectionLimiter *rate.Limiter
skipEventFunc func(*nostr.Event) bool
}
func DefaultOptions() *Options {
@@ -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)