forked from fiatjaf/nak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relay.go
39 lines (33 loc) · 866 Bytes
/
relay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 {
for url := range getStdinLinesOrArguments(c.Args()) {
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 {
lineProcessingError(c, "failed to fetch '%s' information document: %w", url, err)
continue
}
pretty, _ := json.MarshalIndent(info, "", " ")
stdout(string(pretty))
}
return nil
},
}