go-mstdn/ent/customemoji.go

92 lines
2.6 KiB
Go
Raw Normal View History

2023-09-26 05:29:10 +00:00
package ent
2023-09-26 04:21:46 +00:00
import (
"encoding/json"
"github.com/reiver/go-erorr"
"github.com/reiver/go-opt"
2023-09-26 04:21:46 +00:00
)
var _ json.Marshaler = CustomEmoji{}
// CustomEmoji represents a Mastodon API "CustomEmoji".
//
// See:
// https://docs.joinmastodon.org/entities/CustomEmoji/
type CustomEmoji struct {
ShortCode opt.Optional[string] `json:"shortcode"`
URL opt.Optional[string] `json:"url"`
StaticURL opt.Optional[string] `json:"static_url"`
VisibleInPicker opt.Optional[bool] `json:"visible_in_picker"`
Category opt.Optional[string] `json:"category"`
}
func (receiver CustomEmoji) MarshalJSON() ([]byte, error) {
2023-09-28 00:26:34 +00:00
var buffer []byte
buffer = append(buffer, "{"...)
2023-09-26 04:21:46 +00:00
{
2023-09-28 00:26:34 +00:00
buffer = append(buffer, `"shortcode":`...)
marshaled, err := json.Marshal(receiver.ShortCode)
if nil != err {
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.ShortCode as JSON: %w", err)
}
2023-09-26 04:21:46 +00:00
2023-09-28 00:26:34 +00:00
buffer = append(buffer, marshaled...)
2023-09-26 04:21:46 +00:00
}
2023-09-28 00:26:34 +00:00
2023-09-26 04:21:46 +00:00
{
2023-09-28 00:26:34 +00:00
buffer = append(buffer, `,"url":`...)
marshaled, err := json.Marshal(receiver.URL)
if nil != err {
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.URL as JSON: %w", err)
}
2023-09-26 04:21:46 +00:00
2023-09-28 00:26:34 +00:00
buffer = append(buffer, marshaled...)
2023-09-26 04:21:46 +00:00
}
2023-09-28 00:26:34 +00:00
2023-09-26 04:21:46 +00:00
{
2023-09-28 00:26:34 +00:00
buffer = append(buffer, `,"static_url":`...)
2023-09-26 04:21:46 +00:00
2023-09-28 00:26:34 +00:00
marshaled, err := json.Marshal(receiver.StaticURL)
if nil != err {
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.StaticURL as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
2023-09-26 04:21:46 +00:00
}
2023-09-28 00:26:34 +00:00
2023-09-26 04:21:46 +00:00
{
2023-09-28 00:26:34 +00:00
buffer = append(buffer, `,"visible_in_picker":`...)
2023-09-26 04:21:46 +00:00
2023-09-28 00:26:34 +00:00
marshaled, err := json.Marshal(receiver.VisibleInPicker)
if nil != err {
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.VisibleInPicker as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
2023-09-26 04:21:46 +00:00
}
2023-09-28 00:26:34 +00:00
2023-09-26 04:21:46 +00:00
{
2023-09-28 00:26:34 +00:00
if opt.Nothing[string]() != receiver.Category {
buffer = append(buffer, `,"category":`...)
marshaled, err := json.Marshal(receiver.Category)
if nil != err {
return nil, erorr.Errorf("mstdn/ent: could not marshal ent.CustomEmoji.Category as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
2023-09-26 04:21:46 +00:00
}
2023-09-28 00:26:34 +00:00
buffer = append(buffer, "}"...)
return buffer, nil
2023-09-26 04:21:46 +00:00
}