mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-05 08:10:14 +02:00
fixing json filter json + marshaling filter tags.
This commit is contained in:
parent
c42059f4b4
commit
2695854e56
16
filter.go
16
filter.go
@ -9,14 +9,14 @@ import (
|
||||
type Filters []Filter
|
||||
|
||||
type Filter struct {
|
||||
IDs []string `json:"ids"`
|
||||
Kinds []int `json:"kinds"`
|
||||
Authors []string `json:"authors"`
|
||||
Tags TagMap `json:"-"`
|
||||
Since *Timestamp `json:"since"`
|
||||
Until *Timestamp `json:"until"`
|
||||
Limit int `json:"limit"`
|
||||
Search string `json:"search"`
|
||||
IDs []string `json:"ids,omitempty"`
|
||||
Kinds []int `json:"kinds,omitempty"`
|
||||
Authors []string `json:"authors,omitempty"`
|
||||
Tags TagMap `json:"-,omitempty"`
|
||||
Since *Timestamp `json:"since,omitempty"`
|
||||
Until *Timestamp `json:"until,omitempty"`
|
||||
Limit int `json:"limit,omitempty"`
|
||||
Search string `json:"search,omitempty"`
|
||||
}
|
||||
|
||||
type TagMap map[string][]string
|
||||
|
@ -170,12 +170,11 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
out.RawByte('{')
|
||||
first := true
|
||||
_ = first
|
||||
{
|
||||
if len(in.IDs) != 0 {
|
||||
const prefix string = ",\"ids\":"
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
if in.IDs == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
|
||||
out.RawString("null")
|
||||
} else {
|
||||
{
|
||||
out.RawByte('[')
|
||||
for v4, v5 := range in.IDs {
|
||||
if v4 > 0 {
|
||||
@ -186,12 +185,15 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
out.RawByte(']')
|
||||
}
|
||||
}
|
||||
{
|
||||
if len(in.Kinds) != 0 {
|
||||
const prefix string = ",\"kinds\":"
|
||||
out.RawString(prefix)
|
||||
if in.Kinds == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
|
||||
out.RawString("null")
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
{
|
||||
out.RawByte('[')
|
||||
for v6, v7 := range in.Kinds {
|
||||
if v6 > 0 {
|
||||
@ -202,12 +204,15 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
out.RawByte(']')
|
||||
}
|
||||
}
|
||||
{
|
||||
if len(in.Authors) != 0 {
|
||||
const prefix string = ",\"authors\":"
|
||||
out.RawString(prefix)
|
||||
if in.Authors == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
|
||||
out.RawString("null")
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
{
|
||||
out.RawByte('[')
|
||||
for v8, v9 := range in.Authors {
|
||||
if v8 > 0 {
|
||||
@ -218,34 +223,65 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
out.RawByte(']')
|
||||
}
|
||||
}
|
||||
{
|
||||
if in.Since != nil {
|
||||
const prefix string = ",\"since\":"
|
||||
out.RawString(prefix)
|
||||
if in.Since == nil {
|
||||
out.RawString("null")
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.Int64(int64(*in.Since))
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.Int64(int64(*in.Since))
|
||||
}
|
||||
{
|
||||
if in.Until != nil {
|
||||
const prefix string = ",\"until\":"
|
||||
out.RawString(prefix)
|
||||
if in.Until == nil {
|
||||
out.RawString("null")
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.Int64(int64(*in.Until))
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.Int64(int64(*in.Until))
|
||||
}
|
||||
{
|
||||
if in.Limit != 0 {
|
||||
const prefix string = ",\"limit\":"
|
||||
out.RawString(prefix)
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.Int(int(in.Limit))
|
||||
}
|
||||
{
|
||||
if in.Search != "" {
|
||||
const prefix string = ",\"search\":"
|
||||
out.RawString(prefix)
|
||||
if first {
|
||||
first = false
|
||||
out.RawString(prefix[1:])
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.String(string(in.Search))
|
||||
}
|
||||
for tag, values := range in.Tags {
|
||||
const prefix string = ",\"authors\":"
|
||||
if first {
|
||||
first = false
|
||||
out.RawString("\"#" + tag + "\":")
|
||||
} else {
|
||||
out.RawString(",\"#" + tag + "\":")
|
||||
}
|
||||
{
|
||||
out.RawByte('[')
|
||||
for i, v := range values {
|
||||
if i > 0 {
|
||||
out.RawByte(',')
|
||||
}
|
||||
out.String(string(v))
|
||||
}
|
||||
out.RawByte(']')
|
||||
}
|
||||
}
|
||||
out.RawByte('}')
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user