Documentation ¶
Index ¶
- Constants
- func BroadcastEvent(evt *event.T)
- func GetListeningFilters() *filters.T
- func NewServer(rl relay.I, dbPath S, opts ...Option) (*Server, E)
- type B
- type Ctx
- type E
- type Listener
- type N
- type Notice
- type Option
- type Options
- type S
- type Server
- func (s *Server) HandleNIP11(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request)
- func (s *Server) Router() *http.ServeMux
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Shutdown(c context.Context)
- func (s *Server) Start(host S, port int, adminHost S, adminPort int, started ...chan bool) E
Constants ¶
const AUTH_CONTEXT_KEY = iota
const ChallengeHRP = "nchal"
const ChallengeLength = 16
Variables ¶
This section is empty.
Functions ¶
func BroadcastEvent ¶
func GetListeningFilters ¶
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func DefaultOptions ¶
func DefaultOptions() *Options
type Server ¶
type Server struct {
Addr, AdminAddr S
// contains filtered or unexported fields
}
Server is a base for package users to implement nostr relays. It can serve HTTP requests and websockets, passing control over to a relay implementation.
To implement a relay, it is enough to satisfy [Relay] interface. Other interfaces are [Informationer], [CustomWebSocketHandler], [ShutdownAware] and AdvancedXxx types. See their respective doc comments.
The basic usage is to call Start or StartConf, which starts serving immediately. For a more fine-grained control, use NewServer.
func (*Server) HandleNIP11 ¶
func (s *Server) HandleNIP11(w http.ResponseWriter, r *http.Request)
func (*Server) HandleWebsocket ¶
func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request)
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface.
func (*Server) Shutdown ¶
Shutdown sends a websocket close control message to all connected clients.
If the realy is ShutdownAware, Shutdown calls its OnShutdown, passing the context as is. Note that the HTTP server make some time to shutdown and so the context deadline, if any, may have been shortened by the time OnShutdown is called.