initial commits

master
Charles Iliya Krempeaux 2023-09-26 21:12:48 +09:00
parent 1e327c0bc4
commit dc72440189
1 changed files with 18 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"sourcecode.social/reiver/go-jsonint" "sourcecode.social/reiver/go-jsonint"
) )
var _ json.Marshaler = Role{}
var _ json.Unmarshaler = new(Role) var _ json.Unmarshaler = new(Role)
// Role represents a Mastodon API "Role". // Role represents a Mastodon API "Role".
@ -29,6 +30,23 @@ type role struct {
Highlighted opt.Optional[bool] `json:"Highlighted"` Highlighted opt.Optional[bool] `json:"Highlighted"`
} }
func (receiver Role) MarshalJSON() ([]byte, error) {
var src role
src.ID = receiver.ID
src.Name = receiver.Name
src.Permissions = receiver.Permissions
src.Highlighted = src.Highlighted
src.Color = receiver.Color
receiver.Color.WhenNothing(func(){
src.Color = opt.Something("")
})
return json.Marshal(src)
}
func (receiver *Role) UnmarshalJSON(data []byte) error { func (receiver *Role) UnmarshalJSON(data []byte) error {
if nil == receiver { if nil == receiver {
return errNilReceiver return errNilReceiver