initial commits

master
Charles Iliya Krempeaux 2023-09-28 09:45:49 +09:00
parent 04f3882fff
commit d66b3b2734
1 changed files with 76 additions and 0 deletions

View File

@ -1,9 +1,13 @@
package admn package admn
import ( import (
"encoding/json"
"sourcecode.social/reiver/go-erorr"
"sourcecode.social/reiver/go-opt" "sourcecode.social/reiver/go-opt"
) )
var _ json.Marshaler = DimensionData{}
// DimensionData represents a Mastodon API "Admin::Dimension Data". // DimensionData represents a Mastodon API "Admin::Dimension Data".
// //
@ -16,3 +20,75 @@ type DimensionData struct {
Unit opt.Optional[string] `json:"unit"` Unit opt.Optional[string] `json:"unit"`
HumanValue opt.Optional[string] `json:"human_value"` HumanValue opt.Optional[string] `json:"human_value"`
} }
func (receiver DimensionData) MarshalJSON() ([]byte, error) {
var buffer []byte
buffer = append(buffer, "{"...)
{
buffer = append(buffer, `"key":`...)
marshaled, err := json.Marshal(receiver.Key)
if nil != err {
return nil, erorr.Errorf("mstdn/ent/admn: could not marshal admn.DimensionData.Key as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
{
buffer = append(buffer, `,"human_key":`...)
marshaled, err := json.Marshal(receiver.HumanKey)
if nil != err {
return nil, erorr.Errorf("mstdn/ent/admn: could not marshal admn.DimensionData.HumanKey as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
{
buffer = append(buffer, `,"value":`...)
marshaled, err := json.Marshal(receiver.Value)
if nil != err {
return nil, erorr.Errorf("mstdn/ent/admn: could not marshal admn.DimensionData.Value as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
{
if opt.Nothing[string]() != receiver.Unit {
buffer = append(buffer, `,"unit":`...)
marshaled, err := json.Marshal(receiver.Unit)
if nil != err {
return nil, erorr.Errorf("mstdn/ent/admn: could not marshal admn.DimensionData.Unit as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
}
{
if opt.Nothing[string]() != receiver.HumanValue {
buffer = append(buffer, `,"unit":`...)
marshaled, err := json.Marshal(receiver.HumanValue)
if nil != err {
return nil, erorr.Errorf("mstdn/ent/admn: could not marshal admn.DimensionData.HumanValue as JSON: %w", err)
}
buffer = append(buffer, marshaled...)
}
}
buffer = append(buffer, "}"...)
return buffer, nil
}