Fix example compilation error (#50)

This commit is contained in:
Kevin Lee 2023-02-03 22:36:21 +08:00 committed by GitHub
parent cc6ec2b886
commit 15370a9acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 11 deletions

View File

@ -7,18 +7,35 @@ A set of useful things for [Nostr Protocol](https://github.com/nostr-protocol/no
<a href="https://godoc.org/github.com/nbd-wtf/go-nostr"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
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

View File

@ -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]))

View File

@ -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")