Documentation ¶
Index ¶
- func IsValidRelayURL(u string) bool
- type EventMessage
- type Relay
- func (r *Relay) Auth(c context.T, sign func(ev *event.T) error) error
- func (r *Relay) Close() error
- func (r *Relay) Connect(c context.T) error
- func (r *Relay) Context() context.T
- func (r *Relay) Count(c context.T, filters filters.T, opts ...SubscriptionOption) (int64, error)
- func (r *Relay) IsConnected() bool
- func (r *Relay) MessageReadLoop(conn *connection.C)
- func (r *Relay) PrepareSubscription(c context.T, filters filters.T, opts ...SubscriptionOption) *Subscription
- func (r *Relay) Publish(c context.T, ev *event.T) error
- func (r *Relay) QuerySync(c context.T, f filter.T, opts ...SubscriptionOption) ([]*event.T, error)
- func (r *Relay) String() string
- func (r *Relay) Subscribe(c context.T, filters filters.T, opts ...SubscriptionOption) (*Subscription, error)
- func (r *Relay) Write(msg []byte) <-chan error
- type RelayOption
- type Status
- type Subscription
- type SubscriptionOption
- type WithLabel
- type WithNoticeHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidRelayURL ¶
Types ¶
type EventMessage ¶
type Relay ¶
type Relay struct { URL string RequestHeader http.Header // e.g. for origin header Connection *connection.C Subscriptions *xsync.MapOf[string, *Subscription] ConnectionError error // custom things that aren't often used // AssumeValid bool // this will skip verifying signatures for events received from this relay // contains filtered or unexported fields }
func MustRelayConnect ¶
func NewRelay ¶
func NewRelay(c context.T, url string, opts ...RelayOption) *Relay
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func RelayConnect ¶
RelayConnect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func (*Relay) Auth ¶
Auth sends an "AUTH" command client->relay as in NIP-42 and waits for an OK response.
func (*Relay) Connect ¶
Connect tries to establish a websocket connection to r.URL. If the context expires before the connection is complete, an error is returned. Once successfully connected, context expiration has no effect: call r.Close to close the connection.
The underlying relay connection will use a background context. If you want to pass a custom context to the underlying relay connection, use NewRelay() and then Relay.Connect().
func (*Relay) Context ¶
Context retrieves the context that is associated with this relay connection.
func (*Relay) IsConnected ¶
IsConnected returns true if the connection to this relay seems to be active.
func (*Relay) MessageReadLoop ¶
func (r *Relay) MessageReadLoop(conn *connection.C)
func (*Relay) PrepareSubscription ¶
func (r *Relay) PrepareSubscription(c context.T, filters filters.T, opts ...SubscriptionOption) *Subscription
PrepareSubscription creates a subscription, but doesn't fire it.
Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.T` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.
func (*Relay) Publish ¶
Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.
func (*Relay) Subscribe ¶
func (r *Relay) Subscribe(c context.T, filters filters.T, opts ...SubscriptionOption) (*Subscription, error)
Subscribe sends a "REQ" command to the relay r as in NIP-01. Events are returned through the channel sub.Events. The subscription is closed when context ctx is cancelled ("CLOSE" in NIP-01).
Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.T` will be canceled at some point. Failure to do that will result in a huge number of halted goroutines being created.
type RelayOption ¶
type RelayOption interface {
IsRelayOption()
}
RelayOption is the type of the argument passed for that.
type Subscription ¶
type Subscription struct { Relay *Relay Filters filters.T // the Events channel emits all EVENTs that come in a Subscription // will be closed when the subscription ends Events chan *event.T // the EndOfStoredEvents channel gets closed when an EOSE comes for that subscription EndOfStoredEvents chan struct{} // the ClosedReason channel emits the reason when a CLOSED message is received ClosedReason chan string // Context will be .Done() when the subscription ends Context context.T // contains filtered or unexported fields }
func (*Subscription) Close ¶
func (sub *Subscription) Close()
Close just sends a CLOSE message. You probably want Unsub() instead.
func (*Subscription) Fire ¶
func (sub *Subscription) Fire() error
Fire sends the "REQ" command to the relay.
func (*Subscription) GetID ¶
func (sub *Subscription) GetID() string
GetID return the Nostr subscription ID as given to the Relay it is a concatenation of the label and a serial number.
func (*Subscription) Sub ¶
func (sub *Subscription) Sub(_ context.T, filters filters.T)
Sub sets sub.T and then calls sub.Fire(ctx). The subscription will be closed if the context expires.
func (*Subscription) Unsub ¶
func (sub *Subscription) Unsub()
Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01. Unsub() also closes the channel sub.Events and makes a new one.
type SubscriptionOption ¶
type SubscriptionOption interface {
IsSubscriptionOption()
}
When instantiating relay connections, some options may be passed. SubscriptionOption is the type of the argument passed for that. Some examples are WithLabel.
type WithLabel ¶
type WithLabel string
WithLabel puts a label on the subscription (it is prepended to the automatic id) that is sent to relays.
func (WithLabel) IsSubscriptionOption ¶
func (_ WithLabel) IsSubscriptionOption()
type WithNoticeHandler ¶
type WithNoticeHandler func(notice string)
WithNoticeHandler just takes notices and is expected to do something with them. when not given, defaults to logging the notices.
func (WithNoticeHandler) IsRelayOption ¶
func (_ WithNoticeHandler) IsRelayOption()