initial commits

master
Charles Iliya Krempeaux 2023-09-28 09:26:34 +09:00
parent fcfa76fb74
commit 31ab372cb5
4 changed files with 2069 additions and 49 deletions

View File

@ -388,7 +388,6 @@ func (receiver Account) MarshalJSON() ([]byte, error) {
}
}
buffer = append(buffer, "}"...)
return buffer, nil

File diff suppressed because it is too large Load Diff

View File

@ -9,13 +9,6 @@ import (
var _ json.Marshaler = CustomEmoji{}
const (
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no shortcode set")
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no url set")
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no static_url set")
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal ent.CustomEmoji to JSON — no visible_in_picker set")
)
// CustomEmoji represents a Mastodon API "CustomEmoji".
//
// See:
@ -30,45 +23,69 @@ type CustomEmoji struct {
func (receiver CustomEmoji) MarshalJSON() ([]byte, error) {
data := map[string]interface{}{}
var buffer []byte
buffer = append(buffer, "{"...)
{
value, found := receiver.ShortCode.Get()
if !found {
return nil, errCannotMashalCustomEmojiAsJSONNoShortCode
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)
}
buffer = append(buffer, marshaled...)
}
{
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)
}
buffer = append(buffer, marshaled...)
}
{
buffer = append(buffer, `,"static_url":`...)
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...)
}
{
buffer = append(buffer, `,"visible_in_picker":`...)
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...)
}
{
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...)
}
data["shortcode"] = value
}
{
value, found := receiver.URL.Get()
if !found {
return nil, errCannotMashalCustomEmojiAsJSONNoURL
}
data["url"] = value
}
{
value, found := receiver.StaticURL.Get()
if !found {
return nil, errCannotMashalCustomEmojiAsJSONNoStaticURL
}
data["static_url"] = value
}
{
value, found := receiver.VisibleInPicker.Get()
if !found {
return nil, errCannotMashalCustomEmojiAsJSONNoVisibleInPicker
}
data["visible_in_picker"] = value
}
{
receiver.Category.WhenSomething(func(value string){
data["category"] = value
})
}
return json.Marshal(data)
buffer = append(buffer, "}"...)
return buffer, nil
}

View File

@ -25,8 +25,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
Expected:
"{" +"\n"+
"\t"+ `"shortcode":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"url":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
"}" +"\n",
},
@ -43,8 +43,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
Expected:
"{" +"\n"+
"\t"+ `"shortcode":` +`"bananas"` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"url":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
"}" +"\n",
},
@ -58,8 +58,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
Expected:
"{" +"\n"+
"\t"+ `"shortcode":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"url":` +`"https://example.com/emoji/cracra"` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
"}" +"\n",
},
@ -73,8 +73,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
Expected:
"{" +"\n"+
"\t"+ `"shortcode":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`"https://static.example.com/img/emoji/cracra.png"` +"," +"\n"+
"\t"+ `"url":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`"https://static.example.com/img/emoji/cracra.png"` +"," +"\n"+
"\t"+ `"visible_in_picker":` +`false` +"" +"\n"+
"}" +"\n",
},
@ -88,8 +88,8 @@ func TestCustomEmoji_MarshalJSON(t *testing.T) {
Expected:
"{" +"\n"+
"\t"+ `"shortcode":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"url":` +`""` +"," +"\n"+
"\t"+ `"static_url":` +`""` +"," +"\n"+
"\t"+ `"visible_in_picker":` +`true` +"" +"\n"+
"}" +"\n",
},