nak relay

This commit is contained in:
fiatjaf 2023-11-20 15:00:50 -03:00
parent 082be94614
commit 05f2275c9e
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 39 additions and 0 deletions

View File

@ -18,6 +18,7 @@ var app = &cli.App{
decode, decode,
encode, encode,
verify, verify,
relay,
}, },
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{

38
relay.go Normal file
View File

@ -0,0 +1,38 @@
package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/nbd-wtf/go-nostr/nip11"
"github.com/urfave/cli/v2"
)
var relay = &cli.Command{
Name: "relay",
Usage: "gets the relay information document for the given relay, as JSON",
Description: `example:
nak relay nostr.wine
`,
ArgsUsage: "<relay-url>",
Action: func(c *cli.Context) error {
url := c.Args().First()
if url == "" {
return fmt.Errorf("specify the <relay-url>")
}
if !strings.HasPrefix(url, "wss://") && !strings.HasPrefix(url, "ws://") {
url = "wss://" + url
}
info, err := nip11.Fetch(c.Context, url)
if err != nil {
return fmt.Errorf("failed to fetch '%s' information document: %w", url, err)
}
pretty, _ := json.MarshalIndent(info, "", " ")
fmt.Println(string(pretty))
return nil
},
}