mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-20 19:17:54 +01:00
some stringifiers.
This commit is contained in:
11
filter.go
11
filter.go
@@ -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
|
||||||
|
|||||||
4
relay.go
4
relay.go
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user