mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-08 16:48:51 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f35cb4bd1d | ||
|
|
242b028656 | ||
|
|
f0d90b567c | ||
|
|
2d1e27f766 |
13
event.go
13
event.go
@@ -153,12 +153,12 @@ example:
|
|||||||
tags := make(nostr.Tags, 0, 5)
|
tags := make(nostr.Tags, 0, 5)
|
||||||
for _, tagFlag := range c.StringSlice("tag") {
|
for _, tagFlag := range c.StringSlice("tag") {
|
||||||
// tags are in the format key=value
|
// tags are in the format key=value
|
||||||
spl := strings.Split(tagFlag, "=")
|
tagName, tagValue, found := strings.Cut(tagFlag, "=")
|
||||||
if len(spl) == 2 && len(spl[0]) > 0 {
|
tag := []string{tagName}
|
||||||
tag := nostr.Tag{spl[0]}
|
if found {
|
||||||
// tags may also contain extra elements separated with a ";"
|
// tags may also contain extra elements separated with a ";"
|
||||||
spl2 := strings.Split(spl[1], ";")
|
tagValues := strings.Split(tagValue, ";")
|
||||||
tag = append(tag, spl2...)
|
tag = append(tag, tagValues...)
|
||||||
// ~
|
// ~
|
||||||
tags = append(tags, tag)
|
tags = append(tags, tag)
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,8 @@ example:
|
|||||||
ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
|
ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if err := relay.Publish(ctx, evt); err == nil {
|
err := relay.Publish(ctx, evt)
|
||||||
|
if err == nil {
|
||||||
// published fine
|
// published fine
|
||||||
log("success.\n")
|
log("success.\n")
|
||||||
continue nextline
|
continue nextline
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ func ExampleEventBasic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventComplex() {
|
func ExampleEventComplex() {
|
||||||
app.Run([]string{"nak", "event", "--ts", "1699485669", "-k", "11", "-c", "skjdbaskd", "--sec", "17", "-t", "t=spam", "-e", "36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c", "-t", "r=https://abc.def;nothing"})
|
app.Run([]string{"nak", "event", "--ts", "1699485669", "-k", "11", "-c", "skjdbaskd", "--sec", "17", "-t", "t=spam", "-e", "36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c", "-t", "r=https://abc.def?name=foobar;nothing"})
|
||||||
// Output:
|
// Output:
|
||||||
// {"id":"aec4de6d051a7c2b6ca2d087903d42051a31e07fb742f1240970084822de10a6","pubkey":"2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","created_at":1699485669,"kind":11,"tags":[["t","spam"],["r","https://abc.def","nothing"],["e","36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c"]],"content":"skjdbaskd","sig":"1165ac7a27d774d351ef19c8e918fb22f4005fcba193976c3d7edba6ef87ead7f14467f376a9e199f8371835368d86a8506f591e382528d00287fb168a7b8f38"}
|
// {"id":"19aba166dcf354bf5ef64f4afe69ada1eb851495001ee05e07d393ee8c8ea179","pubkey":"2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","created_at":1699485669,"kind":11,"tags":[["t","spam"],["r","https://abc.def?name=foobar","nothing"],["e","36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c"]],"content":"skjdbaskd","sig":"cf452def4a68341c897c3fc96fa34dc6895a5b8cc266d4c041bcdf758ec992ec5adb8b0179e98552aaaf9450526a26d7e62e413b15b1c57e0cfc8db6b29215d7"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleReq() {
|
func ExampleReq() {
|
||||||
|
|||||||
31
req.go
31
req.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mailru/easyjson"
|
"github.com/mailru/easyjson"
|
||||||
@@ -61,13 +62,13 @@ example:
|
|||||||
Usage: "shortcut for --tag p=<value>",
|
Usage: "shortcut for --tag p=<value>",
|
||||||
Category: CATEGORY_FILTER_ATTRIBUTES,
|
Category: CATEGORY_FILTER_ATTRIBUTES,
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.StringFlag{
|
||||||
Name: "since",
|
Name: "since",
|
||||||
Aliases: []string{"s"},
|
Aliases: []string{"s"},
|
||||||
Usage: "only accept events newer than this (unix timestamp)",
|
Usage: "only accept events newer than this (unix timestamp)",
|
||||||
Category: CATEGORY_FILTER_ATTRIBUTES,
|
Category: CATEGORY_FILTER_ATTRIBUTES,
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.StringFlag{
|
||||||
Name: "until",
|
Name: "until",
|
||||||
Aliases: []string{"u"},
|
Aliases: []string{"u"},
|
||||||
Usage: "only accept events older than this (unix timestamp)",
|
Usage: "only accept events older than this (unix timestamp)",
|
||||||
@@ -184,13 +185,27 @@ example:
|
|||||||
filter.Tags[tag[0]] = append(filter.Tags[tag[0]], tag[1])
|
filter.Tags[tag[0]] = append(filter.Tags[tag[0]], tag[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
if since := c.Int("since"); since != 0 {
|
if since := c.String("since"); since != "" {
|
||||||
ts := nostr.Timestamp(since)
|
if since == "now" {
|
||||||
filter.Since = &ts
|
ts := nostr.Now()
|
||||||
|
filter.Since = &ts
|
||||||
|
} else if i, err := strconv.Atoi(since); err == nil {
|
||||||
|
ts := nostr.Timestamp(i)
|
||||||
|
filter.Since = &ts
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("parse error: Invalid numeric literal %q", since)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if until := c.Int("until"); until != 0 {
|
if until := c.String("until"); until != "" {
|
||||||
ts := nostr.Timestamp(until)
|
if until == "now" {
|
||||||
filter.Until = &ts
|
ts := nostr.Now()
|
||||||
|
filter.Until = &ts
|
||||||
|
} else if i, err := strconv.Atoi(until); err == nil {
|
||||||
|
ts := nostr.Timestamp(i)
|
||||||
|
filter.Until = &ts
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("parse error: Invalid numeric literal %q", until)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if limit := c.Int("limit"); limit != 0 {
|
if limit := c.Int("limit"); limit != 0 {
|
||||||
filter.Limit = limit
|
filter.Limit = limit
|
||||||
|
|||||||
Reference in New Issue
Block a user