Compare commits
No commits in common. "7dabefe14b4fe34380efd4bc1741d31684f4685f" and "686fae85989385d1cbf66b4c39fd825333d075f3" have entirely different histories.
7dabefe14b
...
686fae8598
|
@ -10,10 +10,10 @@ import (
|
||||||
var _ json.Marshaler = CustomEmoji{}
|
var _ json.Marshaler = CustomEmoji{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no ‘shortcode’ set")
|
errCannotMashalCustomEmojiAsJSONNoShortCode = erorr.Error("cannot marshal mstdn.Emoji to JSON — no ‘shortcode’ set")
|
||||||
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no ‘url’ set")
|
errCannotMashalCustomEmojiAsJSONNoURL = erorr.Error("cannot marshal mstdn.Emoji to JSON — no ‘url’ set")
|
||||||
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no ‘static_url’ set")
|
errCannotMashalCustomEmojiAsJSONNoStaticURL = erorr.Error("cannot marshal mstdn.Emoji to JSON — no ‘static_url’ set")
|
||||||
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal mstdn.CustomEmoji to JSON — no ‘visible_in_picker’ set")
|
errCannotMashalCustomEmojiAsJSONNoVisibleInPicker = erorr.Error("cannot marshal mstdn.Emoji to JSON — no ‘visible_in_picker’ set")
|
||||||
)
|
)
|
||||||
|
|
||||||
// CustomEmoji represents a Mastodon API "CustomEmoji".
|
// CustomEmoji represents a Mastodon API "CustomEmoji".
|
||||||
|
|
37
field.go
37
field.go
|
@ -3,7 +3,6 @@ package mstdn
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"sourcecode.social/reiver/go-erorr"
|
|
||||||
"sourcecode.social/reiver/go-opt"
|
"sourcecode.social/reiver/go-opt"
|
||||||
"sourcecode.social/reiver/go-nul"
|
"sourcecode.social/reiver/go-nul"
|
||||||
)
|
)
|
||||||
|
@ -11,11 +10,6 @@ import (
|
||||||
var _ json.Marshaler = Field{}
|
var _ json.Marshaler = Field{}
|
||||||
var _ json.Unmarshaler = &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".
|
// Field represents a Mastodon API "Field".
|
||||||
//
|
//
|
||||||
// See:
|
// See:
|
||||||
|
@ -43,34 +37,13 @@ func FieldVerifiedNameValue(when string, name string, value string) Field {
|
||||||
|
|
||||||
func (receiver Field) MarshalJSON() ([]byte, error) {
|
func (receiver Field) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
var data = map[string]interface{}{}
|
duplicate := receiver
|
||||||
|
|
||||||
{
|
duplicate.VerifiedAt.WhenNothing(func(){
|
||||||
val, found := receiver.Name.Get()
|
duplicate.VerifiedAt = nul.Null[string]()
|
||||||
if !found {
|
})
|
||||||
return nil, errCannotMashalFieldAsJSONNoName
|
|
||||||
}
|
|
||||||
|
|
||||||
data["name"] = val
|
return json.Marshal(duplicate)
|
||||||
}
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *Field) UnmarshalJSON(data []byte) error {
|
func (receiver *Field) UnmarshalJSON(data []byte) error {
|
||||||
|
|
Loading…
Reference in New Issue