Documentation ¶
Index ¶
- Constants
- func FilterEqual(a EventFilter, b EventFilter) bool
- func GeneratePrivateKey() string
- func GetPublicKey(sk string) (string, error)
- func NormalizeURL(u string) string
- type Connection
- type Event
- type EventFilter
- type EventFilters
- type EventMessage
- type IntList
- type NoticeMessage
- type PublishStatus
- type RelayPool
- type RelayPoolPolicy
- type SimplePolicy
- type StringList
- type Subscription
- type Tag
- type Tags
Constants ¶
View Source
const ( KindSetMetadata int = 0 KindTextNote int = 1 KindRecommendServer int = 2 KindContactList int = 3 KindEncryptedDirectMessage int = 4 KindDeletion int = 5 )
View Source
const ( PublishStatusSent = 0 PublishStatusFailed = -1 PublishStatusSucceeded = 1 )
Variables ¶
This section is empty.
Functions ¶
func FilterEqual ¶
func FilterEqual(a EventFilter, b EventFilter) bool
func GeneratePrivateKey ¶
func GeneratePrivateKey() string
func GetPublicKey ¶
func NormalizeURL ¶
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(socket *websocket.Conn) *Connection
func (*Connection) Close ¶
func (c *Connection) Close() error
func (*Connection) WriteJSON ¶
func (c *Connection) WriteJSON(v interface{}) error
func (*Connection) WriteMessage ¶
func (c *Connection) WriteMessage(messageType int, data []byte) error
type Event ¶
type Event struct { ID string `json:"id"` // it's the hash of the serialized event PubKey string `json:"pubkey"` CreatedAt uint32 `json:"created_at"` Kind int `json:"kind"` Tags Tags `json:"tags"` Content string `json:"content"` Sig string `json:"sig"` }
func (Event) CheckSignature ¶
CheckSignature checks if the signature is valid for the id (which is a hash of the serialized event content). returns an error if the signature itself is invalid.
type EventFilter ¶
type EventFilter struct { IDs StringList `json:"ids,omitempty"` Kinds IntList `json:"kinds,omitempty"` Authors StringList `json:"authors,omitempty"` Since uint32 `json:"since,omitempty"` Until uint32 `json:"until,omitempty"` TagE StringList `json:"#e,omitempty"` TagP StringList `json:"#p,omitempty"` }
func (EventFilter) Matches ¶
func (ef EventFilter) Matches(event *Event) bool
type EventFilters ¶
type EventFilters []EventFilter
func (EventFilters) Match ¶
func (eff EventFilters) Match(event *Event) bool
type EventMessage ¶
type NoticeMessage ¶
type PublishStatus ¶
type RelayPool ¶
type RelayPool struct { SecretKey *string Relays map[string]RelayPoolPolicy Notices chan *NoticeMessage // contains filtered or unexported fields }
func (*RelayPool) Add ¶
func (r *RelayPool) Add(url string, policy RelayPoolPolicy) error
Add adds a new relay to the pool, if policy is nil, it will be a simple read+write policy.
func (*RelayPool) PublishEvent ¶
func (r *RelayPool) PublishEvent(evt *Event) (*Event, chan PublishStatus, error)
func (*RelayPool) Sub ¶
func (r *RelayPool) Sub(filters EventFilters) *Subscription
type RelayPoolPolicy ¶
type RelayPoolPolicy interface { ShouldRead(EventFilters) bool ShouldWrite(*Event) bool }
type SimplePolicy ¶
func (SimplePolicy) ShouldRead ¶
func (s SimplePolicy) ShouldRead(_ EventFilters) bool
func (SimplePolicy) ShouldWrite ¶
func (s SimplePolicy) ShouldWrite(_ *Event) bool
type StringList ¶
type StringList []string
func (StringList) Contains ¶
func (haystack StringList) Contains(needle string) bool
func (StringList) Equals ¶
func (as StringList) Equals(bs StringList) bool
type Subscription ¶
type Subscription struct { Events chan EventMessage UniqueEvents chan Event // contains filtered or unexported fields }
func (Subscription) Sub ¶
func (subscription Subscription) Sub()
func (Subscription) Unsub ¶
func (subscription Subscription) Unsub()
Source Files ¶
Click to show internal directories.
Click to hide internal directories.