well-goknown/vendor/github.com/nbd-wtf/go-nostr/event_extra.go

69 lines
1.2 KiB
Go
Raw Permalink Normal View History

package nostr
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt *Event) SetExtra(key string, value any) {
if evt.extra == nil {
evt.extra = make(map[string]any)
}
evt.extra[key] = value
}
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt *Event) RemoveExtra(key string) {
if evt.extra == nil {
return
}
delete(evt.extra, key)
}
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt Event) GetExtra(key string) any {
ival, _ := evt.extra[key]
return ival
}
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt Event) GetExtraString(key string) string {
ival, ok := evt.extra[key]
if !ok {
return ""
}
val, ok := ival.(string)
if !ok {
return ""
}
return val
}
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt Event) GetExtraNumber(key string) float64 {
ival, ok := evt.extra[key]
if !ok {
return 0
}
switch val := ival.(type) {
case float64:
return val
case int:
return float64(val)
case int64:
return float64(val)
}
return 0
}
2024-10-29 00:11:29 +00:00
// Deprecated: this was never a good idea, stop using.
func (evt Event) GetExtraBoolean(key string) bool {
ival, ok := evt.extra[key]
if !ok {
return false
}
val, ok := ival.(bool)
if !ok {
return false
}
return val
}