From 67d8f26d8a8637a3b2b673977f81b4faa932e6c9 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 26 Nov 2022 09:25:31 -0300 Subject: [PATCH] some stringifiers. --- filter.go | 11 +++++++++++ relay.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/filter.go b/filter.go index 8bc42a6..14d270a 100644 --- a/filter.go +++ b/filter.go @@ -1,6 +1,7 @@ package nostr import ( + "encoding/json" "time" "golang.org/x/exp/slices" @@ -20,6 +21,11 @@ type Filter struct { type TagMap map[string][]string +func (eff Filters) String() string { + j, _ := json.Marshal(eff) + return string(j) +} + func (eff Filters) Match(event *Event) bool { for _, filter := range eff { if filter.Matches(event) { @@ -29,6 +35,11 @@ func (eff Filters) Match(event *Event) bool { return false } +func (ef Filter) String() string { + j, _ := json.Marshal(ef) + return string(j) +} + func (ef Filter) Matches(event *Event) bool { if event == nil { return false diff --git a/relay.go b/relay.go index 2b4ce47..530ee37 100644 --- a/relay.go +++ b/relay.go @@ -51,6 +51,10 @@ func RelayConnect(url string) (*Relay, error) { return r, err } +func (r *Relay) String() string { + return r.URL +} + func (r *Relay) Connect() error { if r.URL == "" { return fmt.Errorf("invalid relay URL '%s'", r.URL)