mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 23:32:47 +01:00
26 lines
336 B
Go
26 lines
336 B
Go
package busdb
|
|
|
|
import "encoding/json"
|
|
|
|
type Keyed[T any] struct {
|
|
Key string
|
|
Doc *T
|
|
}
|
|
|
|
func (p *Keyed[T]) MarshalJSON() ([]byte, error) {
|
|
b, err := json.Marshal(p.Doc)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var m map[string]any
|
|
err = json.Unmarshal(b, &m)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
m["_key"] = p.Key
|
|
|
|
return json.Marshal(m)
|
|
}
|