From 15370a9acdafb2a5328560a460cc0aedca51bb05 Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Fri, 3 Feb 2023 22:36:21 +0800 Subject: [PATCH] Fix example compilation error (#50) --- README.md | 33 +++++++++++++++++++++++++-------- example/example.go | 4 ++-- filter_test.go | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c2f0aa2..7045316 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,35 @@ A set of useful things for [Nostr Protocol](https://github.com/nostr-protocol/no GoDoc +Install go-nostr: + +```bash +go get github.com/nbd-wtf/go-nostr +``` + ### Generating a key ``` go -sk, _ := nostr.GenerateKey() -pk, _ := nostr.GetPublicKey(sk) -nsec, _ := nip19.EncodePrivateKey(sk) -npub, _ := nip19.EncodePublicKey(pk) +package main -fmt.Println("sk:", sk) -fmt.Println("pk:", nostr.GetPublicKey(sk)) -fmt.Println(nsec) -fmt.Println(npub) +import ( + "fmt" + + "github.com/nbd-wtf/go-nostr" + "github.com/nbd-wtf/go-nostr/nip19" +) + +func main() { + sk := nostr.GeneratePrivateKey() + pk, _ := nostr.GetPublicKey(sk) + nsec, _ := nip19.EncodePrivateKey(sk) + npub, _ := nip19.EncodePublicKey(pk) + + fmt.Println("sk:", sk) + fmt.Println("pk:", pk) + fmt.Println(nsec) + fmt.Println(npub) +} ``` ### Subscribing to a single relay diff --git a/example/example.go b/example/example.go index 3682e34..6eed9c0 100644 --- a/example/example.go +++ b/example/example.go @@ -62,7 +62,7 @@ func main() { cancel() }() for ev := range sub.Events { - evs = append(evs, ev) + evs = append(evs, *ev) } filename := "example_output.json" @@ -104,7 +104,7 @@ func main() { ev.CreatedAt = time.Now() ev.Kind = 1 var content string - fmt.Fprintln(os.Stderr, "enter content of note, ending with an empty newline:") + fmt.Fprintln(os.Stderr, "enter content of note, ending with an empty newline (ctrl+d):") for { if n, err := reader.Read(b[:]); err == nil { content = fmt.Sprintf("%s%s", content, fmt.Sprintf("%s", b[:n])) diff --git a/filter_test.go b/filter_test.go index e65507f..28e32ba 100644 --- a/filter_test.go +++ b/filter_test.go @@ -16,7 +16,7 @@ func TestFilterUnmarshal(t *testing.T) { t.Errorf("failed to parse filter json: %v", err) } - if f.Since == nil || f.Since.Format("2006-01-02") != "2022-02-07" || + if f.Since == nil || f.Since.UTC().Format("2006-01-02") != "2022-02-07" || f.Until != nil || f.Tags == nil || len(f.Tags) != 2 || !slices.Contains(f.Tags["something"], "bab") { t.Error("failed to parse filter correctly")