some stringifiers.

This commit is contained in:
fiatjaf 2022-11-26 09:25:31 -03:00
parent b0ae497656
commit 67d8f26d8a
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 15 additions and 0 deletions

View File

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

View File

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