some stringifiers.

This commit is contained in:
fiatjaf
2022-11-26 09:25:31 -03:00
parent b0ae497656
commit 67d8f26d8a
2 changed files with 15 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package nostr package nostr
import ( import (
"encoding/json"
"time" "time"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@@ -20,6 +21,11 @@ type Filter struct {
type TagMap map[string][]string type TagMap map[string][]string
func (eff Filters) String() string {
j, _ := json.Marshal(eff)
return string(j)
}
func (eff Filters) Match(event *Event) bool { func (eff Filters) Match(event *Event) bool {
for _, filter := range eff { for _, filter := range eff {
if filter.Matches(event) { if filter.Matches(event) {
@@ -29,6 +35,11 @@ func (eff Filters) Match(event *Event) bool {
return false return false
} }
func (ef Filter) String() string {
j, _ := json.Marshal(ef)
return string(j)
}
func (ef Filter) Matches(event *Event) bool { func (ef Filter) Matches(event *Event) bool {
if event == nil { if event == nil {
return false return false

View File

@@ -51,6 +51,10 @@ func RelayConnect(url string) (*Relay, error) {
return r, err return r, err
} }
func (r *Relay) String() string {
return r.URL
}
func (r *Relay) Connect() error { func (r *Relay) Connect() error {
if r.URL == "" { if r.URL == "" {
return fmt.Errorf("invalid relay URL '%s'", r.URL) return fmt.Errorf("invalid relay URL '%s'", r.URL)