mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-25 16:21:00 +02:00
Fix example compilation error (#50)
This commit is contained in:
parent
cc6ec2b886
commit
15370a9acd
21
README.md
21
README.md
@ -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>
|
<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
|
### Generating a key
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
sk, _ := nostr.GenerateKey()
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nbd-wtf/go-nostr"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
sk := nostr.GeneratePrivateKey()
|
||||||
pk, _ := nostr.GetPublicKey(sk)
|
pk, _ := nostr.GetPublicKey(sk)
|
||||||
nsec, _ := nip19.EncodePrivateKey(sk)
|
nsec, _ := nip19.EncodePrivateKey(sk)
|
||||||
npub, _ := nip19.EncodePublicKey(pk)
|
npub, _ := nip19.EncodePublicKey(pk)
|
||||||
|
|
||||||
fmt.Println("sk:", sk)
|
fmt.Println("sk:", sk)
|
||||||
fmt.Println("pk:", nostr.GetPublicKey(sk))
|
fmt.Println("pk:", pk)
|
||||||
fmt.Println(nsec)
|
fmt.Println(nsec)
|
||||||
fmt.Println(npub)
|
fmt.Println(npub)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Subscribing to a single relay
|
### Subscribing to a single relay
|
||||||
|
@ -62,7 +62,7 @@ func main() {
|
|||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
for ev := range sub.Events {
|
for ev := range sub.Events {
|
||||||
evs = append(evs, ev)
|
evs = append(evs, *ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := "example_output.json"
|
filename := "example_output.json"
|
||||||
@ -104,7 +104,7 @@ func main() {
|
|||||||
ev.CreatedAt = time.Now()
|
ev.CreatedAt = time.Now()
|
||||||
ev.Kind = 1
|
ev.Kind = 1
|
||||||
var content string
|
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 {
|
for {
|
||||||
if n, err := reader.Read(b[:]); err == nil {
|
if n, err := reader.Read(b[:]); err == nil {
|
||||||
content = fmt.Sprintf("%s%s", content, fmt.Sprintf("%s", b[:n]))
|
content = fmt.Sprintf("%s%s", content, fmt.Sprintf("%s", b[:n]))
|
||||||
|
@ -16,7 +16,7 @@ func TestFilterUnmarshal(t *testing.T) {
|
|||||||
t.Errorf("failed to parse filter json: %v", err)
|
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.Until != nil ||
|
||||||
f.Tags == nil || len(f.Tags) != 2 || !slices.Contains(f.Tags["something"], "bab") {
|
f.Tags == nil || len(f.Tags) != 2 || !slices.Contains(f.Tags["something"], "bab") {
|
||||||
t.Error("failed to parse filter correctly")
|
t.Error("failed to parse filter correctly")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user