Add Tags.Has and nip11.Self

This commit is contained in:
Jon Staab
2025-09-27 06:37:06 -07:00
committed by fiatjaf
parent 113657314e
commit 9ba61b56e6
2 changed files with 11 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ type RelayInformationDocument struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
PubKey *nostr.PubKey `json:"pubkey,omitempty"` PubKey *nostr.PubKey `json:"pubkey,omitempty"`
Self *nostr.PubKey `json:"self,omitempty"`
Contact string `json:"contact,omitempty"` Contact string `json:"contact,omitempty"`
SupportedNIPs []any `json:"supported_nips,omitempty"` SupportedNIPs []any `json:"supported_nips,omitempty"`
Software string `json:"software,omitempty"` Software string `json:"software,omitempty"`

10
tags.go
View File

@@ -19,6 +19,16 @@ func (tags Tags) GetD() string {
return "" return ""
} }
// Has returns true if a tag exists with the given key (whether or not it has a value)
func (tags Tags) Has(key string) bool {
for _, v := range tags {
if len(v) >= 1 && v[0] == key {
return true
}
}
return false
}
// Find returns the first tag with the given key/tagName that also has one value (i.e. at least 2 items) // Find returns the first tag with the given key/tagName that also has one value (i.e. at least 2 items)
func (tags Tags) Find(key string) Tag { func (tags Tags) Find(key string) Tag {
for _, v := range tags { for _, v := range tags {