nak/relay.go

40 lines
866 B
Go
Raw Normal View History

2023-11-20 13:00:50 -05:00
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`,
2023-11-20 13:00:50 -05:00
ArgsUsage: "<relay-url>",
Action: func(c *cli.Context) error {
for url := range getStdinLinesOrArguments(c.Args()) {
if url == "" {
return fmt.Errorf("specify the <relay-url>")
}
2023-11-20 13:00:50 -05:00
if !strings.HasPrefix(url, "wss://") && !strings.HasPrefix(url, "ws://") {
url = "wss://" + url
}
2023-11-20 13:00:50 -05:00
info, err := nip11.Fetch(c.Context, url)
if err != nil {
lineProcessingError(c, "failed to fetch '%s' information document: %w", url, err)
continue
}
2023-11-20 13:00:50 -05:00
pretty, _ := json.MarshalIndent(info, "", " ")
stdout(string(pretty))
}
2023-11-20 13:00:50 -05:00
return nil
},
}