add WithSkipEventFunc
This commit is contained in:
@@ -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 {
|
||||
|
||||
8
start.go
8
start.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user