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) (int, 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) (ch chan error)
- type WithNoticeHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidRelayURL ¶
Types ¶
type Option ¶
type Option interface {
IsRelayOption()
}
Option is the type of the argument passed for that.
type T ¶
type T struct { RequestHeader http.Header // e.g. for origin header Connection *connection.C Subscriptions *xsync.MapOf[string, *subscription.T] ConnectionError error ConnectionContext context.T // will be canceled when connection closes ConnectionContextCancel context.F AuthRequired chan struct{} // custom things that aren't often used // AssumeValid bool // skip verifying signatures of events from this relay // contains filtered or unexported fields }
func Connect ¶
Connect returns a relay object connected to url. Once successfully connected, cancelling ctx has no effect. To close the connection, call r.Close().
func ConnectWithAuth ¶
ConnectWithAuth auths with the relay, checks if its NIP-11 says auth-required and uses the provided sec to sign the auth challenge.
func MustConnect ¶
func NewRelay ¶
NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
func (*T) Auth ¶
Auth sends an "AUTH" command client->relay as in NIP-42 and waits for an OK response.
func (*T) 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 (*T) IsConnected ¶
IsConnected returns true if the connection to this relay seems to be active.
func (*T) MessageReadLoop ¶
func (r *T) MessageReadLoop(conn *connection.C)
func (*T) PrepareSubscription ¶
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 ¶
Publish sends an "EVENT" command to the relay r as in NIP-01 and waits for an OK response.
func (*T) Subscribe ¶
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()