mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-26 17:51:49 +01:00
implement nip-11, relay information document.
This commit is contained in:
parent
809f8030db
commit
8cc12a6bd9
23
handlers.go
23
handlers.go
@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fiatjaf/go-nostr"
|
||||
"github.com/fiatjaf/go-nostr/nip11"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
@ -193,3 +194,25 @@ func handleWebsocket(relay Relay) func(http.ResponseWriter, *http.Request) {
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func handleNIP11(relay Relay) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
info := nip11.RelayInformationDocument{
|
||||
Name: relay.Name(),
|
||||
Description: "relay powered by the relayer framework",
|
||||
PubKey: "~",
|
||||
Contact: "~",
|
||||
SupportedNIPs: []int{9, 15, 16},
|
||||
Software: "https://github.com/fiatjaf/relayer",
|
||||
Version: "~",
|
||||
}
|
||||
|
||||
if ifmer, ok := relay.(Informationer); ok {
|
||||
info = ifmer.GetNIP11InformationDocument()
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(info)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package relayer
|
||||
|
||||
import (
|
||||
"github.com/fiatjaf/go-nostr"
|
||||
"github.com/fiatjaf/go-nostr/nip11"
|
||||
)
|
||||
|
||||
var Log = log
|
||||
@ -16,3 +17,7 @@ type Relay interface {
|
||||
type Injector interface {
|
||||
InjectEvents() chan nostr.Event
|
||||
}
|
||||
|
||||
type Informationer interface {
|
||||
GetNIP11InformationDocument() nip11.RelayInformationDocument
|
||||
}
|
||||
|
9
start.go
9
start.go
@ -16,8 +16,10 @@ type Settings struct {
|
||||
Port string `envconfig:"PORT" default:"7447"`
|
||||
}
|
||||
|
||||
var s Settings
|
||||
var log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
var (
|
||||
s Settings
|
||||
log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
)
|
||||
|
||||
var Router = mux.NewRouter()
|
||||
|
||||
@ -33,6 +35,9 @@ func Start(relay Relay) {
|
||||
// catch the websocket call before anything else
|
||||
Router.Path("/").Headers("Upgrade", "websocket").HandlerFunc(handleWebsocket(relay))
|
||||
|
||||
// nip-11, relay information
|
||||
Router.Path("/").Headers("Accept", "application/nostr+json").HandlerFunc(handleNIP11(relay))
|
||||
|
||||
// allow implementations to do initialization stuff
|
||||
if err := relay.Init(); err != nil {
|
||||
Log.Fatal().Err(err).Msg("failed to start")
|
||||
|
Loading…
x
Reference in New Issue
Block a user