mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-05 12:40:56 +02:00
move stuff back from nostr package to top level.
because otherwise the path must be specified as github.com/fiatjaf/go-nostr/nostr, which is annoying.
This commit is contained in:
33
connection.go
Normal file
33
connection.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
socket *websocket.Conn
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func NewConnection(socket *websocket.Conn) *Connection {
|
||||
return &Connection{
|
||||
socket: socket,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Connection) WriteJSON(v interface{}) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
return c.socket.WriteJSON(v)
|
||||
}
|
||||
|
||||
func (c *Connection) WriteMessage(messageType int, data []byte) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
return c.socket.WriteMessage(messageType, data)
|
||||
}
|
||||
|
||||
func (c *Connection) Close() error {
|
||||
return c.socket.Close()
|
||||
}
|
Reference in New Issue
Block a user