Documentation ¶
Index ¶
- func IsValidRelayURL(u string) bool
- type Option
- type Status
- type T
- func (r *T) Auth(c context.T, sign func(ev *event.T) error) error
- func (r *T) Close() error
- func (r *T) Connect(c context.T) (err error)
- func (r *T) Context() context.T
- func (r *T) Count(c context.T, filters filters.T, opts ...subscriptionoption.I) (int64, error)
- func (r *T) Delete(key string)
- func (r *T) IsConnected() bool
- func (r *T) MessageReadLoop(conn *connection.C)
- func (r *T) PrepareSubscription(c context.T, f filters.T, opts ...subscriptionoption.I) *subscription.T
- func (r *T) Publish(c context.T, ev *event.T) error
- func (r *T) QuerySync(c context.T, f *filter.T, opts ...subscriptionoption.I) ([]*event.T, error)
- func (r *T) String() string
- func (r *T) Subscribe(c context.T, f filters.T, opts ...subscriptionoption.I) (*subscription.T, error)
- func (r *T) URL() string
- func (r *T) Write(msg []byte) <-chan error
- type WithNoticeHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidRelayURL ¶ added in v1.0.11
Types ¶
type Option ¶
type Option interface {
IsRelayOption()
}
Option is the type of the argument passed for that.
type T ¶ added in v1.0.11
type T struct { RequestHeader http.Header // e.g. for origin header Connection *connection.C Subscriptions *xsync.MapOf[string, *subscription.T] 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 Connect ¶ added in v1.0.11
Connect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func MustConnect ¶ added in v1.0.11
func NewRelay ¶ added in v1.0.11
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func (*T) Auth ¶ added in v1.0.11
Auth sends an "AUTH" command client->relay as in NIP-42 and waits for an OK response.
func (*T) Connect ¶ added in v1.0.11
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 (*T) Context ¶ added in v1.0.11
Context retrieves the context that is associated with this relay connection.
func (*T) IsConnected ¶ added in v1.0.11
IsConnected returns true if the connection to this relay seems to be active.
func (*T) MessageReadLoop ¶ added in v1.0.11
func (r *T) MessageReadLoop(conn *connection.C)
func (*T) PrepareSubscription ¶ added in v1.0.11
func (r *T) PrepareSubscription(c context.T, f filters.T, opts ...subscriptionoption.I) *subscription.T
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 (*T) Publish ¶ added in v1.0.11
Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.
func (*T) Subscribe ¶ added in v1.0.11
func (r *T) Subscribe(c context.T, f filters.T, opts ...subscriptionoption.I) (*subscription.T, 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 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()