Documentation
¶
Index ¶
- type Admission
- type Fees
- type InformationDocument
- type InternetIdentifier
- type Limitations
- type Options
- type Relay
- func (rl *Relay) HandleErrorFunc(fn func(error))
- func (rl *Relay) HandleInformationDocumentFunc(fn func() (*InformationDocument, error))
- func (rl *Relay) HandleInternetIdentifierFunc(fn func(string) (*InternetIdentifier, error))
- func (rl *Relay) HandleMessageFunc(fn func(message.Message))
- func (rl *Relay) SendMessage(ctx context.Context, msg message.Message)
- func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admission ¶ added in v0.5.0
type Admission struct { Kinds []int `json:"kinds,omitempty"` // Kinds specifies the types of events allowed. Amount int `json:"amount,omitempty"` // Amount indicates the payment required for accessing paid relays. Unit []string `json:"unit,omitempty"` // Unit denotes the currency unit used for payment. }
Admission represents the admission requirements for accessing a Nostr relay.
type Fees ¶ added in v0.5.0
type Fees struct {
Admission *Admission `json:"admission,omitempty"` // Admission represents the admission fee for an operation, if applicable.
}
Fees is a struct that contains information about the fees associated with an operation.
type InformationDocument ¶ added in v0.5.0
type InformationDocument struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` PubKey string `json:"pub_key,omitempty"` Contact string `json:"contact,omitempty"` SupportedNIPs string `json:"supported_nips,omitempty"` Software string `json:"software,omitempty"` Version string `json:"version,omitempty"` Limitations *Limitations `json:"limitations,omitempty"` LanguageTags []string `json:"language_tags,omitempty"` RelayCountries []string `json:"relay_countries,omitempty"` Tags []tag.Tag `json:"tags,omitempty"` PostingPolicy string `json:"posting_policy,omitempty"` PaymentsURL string `json:"payments_url,omitempty"` Fees *Fees `json:"fees,omitempty"` }
InformationDocument contains information about a Nostr relay.
type InternetIdentifier ¶ added in v0.5.0
type Limitations ¶ added in v0.5.0
type Limitations struct { AuthRequired bool `json:"auth_required,omitempty"` // Indicates if authentication is required. MaxContentLength int `json:"max_content_length,omitempty"` // Maximum content length. MaxEventTags int `json:"max_event_tags,omitempty"` // Maximum number of event tags. MaxFilters int `json:"max_filters,omitempty"` // Maximum number of filters. MaxLimit int `json:"max_limit,omitempty"` // Maximum limit for query results. MaxMessageLength int `json:"max_message_length,omitempty"` // Maximum length of a message. MaxSubIDLength int `json:"max_subid_length,omitempty"` // Maximum length of a subscription ID. MaxSubscriptions int `json:"max_subscriptions,omitempty"` // Maximum number of subscriptions. MinPowDifficulty int `json:"min_pow_difficulty,omitempty"` // Minimum proof-of-work difficulty. MinPrefix int `json:"min_prefix,omitempty"` // Minimum prefix length. PaymentRequired bool `json:"payment_required,omitempty"` // Indicates if payment is required. }
Limitations represents various limits and constraints imposed by a Nostr server.
type Options ¶
type Options struct { Name string Description string PubKey string Contact string Origin string SupportedNIPs []int Software string Version string Limitations *Limitations }
Options holds the configuration options for a Relay instance. This includes the name, description, public key, contact, origin, supported NIPs, software, version, and limitations for the relay instance.
type Relay ¶
type Relay struct { *Options // contains filtered or unexported fields }
Relay represents a websocket relay server. It holds options, a map of connections, handlers for errors and messages, mutex for concurrent access, and a ServeMux for HTTP request routing.
func New ¶
New creates a new Relay instance with the provided Options. If no options are provided, it will create default options. If the Origin in options is not set, it sets it to "*". This function also initializes a map for connections, sets error and message handlers to default functions, and sets two HTTP handlers for ".well-known/nostr.json" and "/" routes.
func (*Relay) HandleErrorFunc ¶ added in v0.5.0
HandleErrorFunc registers a function that will handle errors. This function is called when an error occurs.
func (*Relay) HandleInformationDocumentFunc ¶ added in v0.10.0
func (rl *Relay) HandleInformationDocumentFunc(fn func() (*InformationDocument, error))
HandleInformationDocumentFunc registers a function that will handle the generation of an information document. This function is expected to return an InformationDocument instance or an error.
func (*Relay) HandleInternetIdentifierFunc ¶ added in v0.5.0
func (rl *Relay) HandleInternetIdentifierFunc(fn func(string) (*InternetIdentifier, error))
HandleInternetIdentifierFunc registers a function that will handle the internet identifier. This function is expected to return an InternetIdentifier instance or an error given a string input.
func (*Relay) HandleMessageFunc ¶
HandleMessageFunc registers a function that will handle messages. This function is called with a Message as a parameter whenever a message is received.
func (*Relay) SendMessage ¶ added in v0.10.0
SendMessage sends the provided Message to all connected clients. If an error occurs while marshalling the message, it calls the registered error handler function.