Compare commits

..

No commits in common. "7dabefe14b4fe34380efd4bc1741d31684f4685f" and "686fae85989385d1cbf66b4c39fd825333d075f3" have entirely different histories.

2 changed files with 9 additions and 36 deletions

View File

@ -10,10 +10,10 @@ import (
var _ json.Marshaler = CustomEmoji{}
const (
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no shortcode set")
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no url set")
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no static_url set")
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no visible_in_picker set")
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal mstdn.Emoji to JSON — no shortcode set")
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal mstdn.Emoji to JSON — no url set")
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal mstdn.Emoji to JSON — no static_url set")
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal mstdn.Emoji to JSON — no visible_in_picker set")
)
// CustomEmoji represents a Mastodon API "CustomEmoji".

View File

@ -3,7 +3,6 @@ package mstdn
import (
"encoding/json"
"sourcecode.social/reiver/go-erorr"
"sourcecode.social/reiver/go-opt"
"sourcecode.social/reiver/go-nul"
)
@ -11,11 +10,6 @@ import (
var _ json.Marshaler = Field{}
var _ json.Unmarshaler = &Field{}
const (
errCannotMashalFieldAsJSONNoName = erorr.Error("cannot marshal mstdn.Field to JSON — no name set")
errCannotMashalFieldAsJSONNoValue = erorr.Error("cannot marshal mstdn.Field to JSON — no value set")
)
// Field represents a Mastodon API "Field".
//
// See:
@ -43,34 +37,13 @@ func FieldVerifiedNameValue(when string, name string, value string) Field {
func (receiver Field) MarshalJSON() ([]byte, error) {
var data = map[string]interface{}{}
duplicate := receiver
{
val, found := receiver.Name.Get()
if !found {
return nil, errCannotMashalFieldAsJSONNoName
}
duplicate.VerifiedAt.WhenNothing(func(){
duplicate.VerifiedAt = nul.Null[string]()
})
data["name"] = val
}
{
val, found := receiver.Value.Get()
if !found {
return nil, errCannotMashalFieldAsJSONNoValue
}
data["value"] = val
}
{
val, found := receiver.VerifiedAt.Get()
if !found {
data["verified_at"] = nil
} else {
data["verified_at"] = val
}
}
return json.Marshal(data)
return json.Marshal(duplicate)
}
func (receiver *Field) UnmarshalJSON(data []byte) error {