use fastjson to serialize and unmarshal/marshal events, remove need for special Time type.

This commit is contained in:
fiatjaf
2022-02-09 20:23:10 -03:00
parent 41955a0601
commit 9721ffa851
5 changed files with 264 additions and 184 deletions

49
tags.go
View File

@@ -1,49 +0,0 @@
package nostr
import (
"encoding/json"
"errors"
)
type Tags []Tag
type Tag []interface{}
func (t *Tags) Scan(src interface{}) error {
var jtags []byte = make([]byte, 0)
switch v := src.(type) {
case []byte:
jtags = v
case string:
jtags = []byte(v)
default:
return errors.New("couldn't scan tags, it's not a json string")
}
json.Unmarshal(jtags, &t)
return nil
}
func (tags Tags) ContainsAny(tagName string, values StringList) bool {
for _, tag := range tags {
if len(tag) < 2 {
continue
}
currentTagName, ok := tag[0].(string)
if !ok || currentTagName != tagName {
continue
}
currentTagValue, ok := tag[1].(string)
if !ok {
continue
}
if values.Contains(currentTagValue) {
return true
}
}
return false
}