fixing json filter json + marshaling filter tags.

This commit is contained in:
fiatjaf 2023-04-16 16:19:24 -03:00
parent c42059f4b4
commit 2695854e56
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 70 additions and 34 deletions

View File

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

View File

@ -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.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.RawString(prefix)
}
out.Int64(int64(*in.Until))
}
}
{
if in.Limit != 0 {
const prefix string = ",\"limit\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int(int(in.Limit))
}
{
if in.Search != "" {
const prefix string = ",\"search\":"
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('}')
}