feat: it works
This commit is contained in:
parent
6302dd62d6
commit
778d5ef146
25 changed files with 638 additions and 106 deletions
|
|
@ -22,19 +22,21 @@ func (s *Error) Encode(e *jx.Encoder) {
|
|||
|
||||
// encodeFields encodes fields.
|
||||
func (s *Error) encodeFields(e *jx.Encoder) {
|
||||
{
|
||||
e.FieldStart("code")
|
||||
e.Int(s.Code)
|
||||
}
|
||||
{
|
||||
e.FieldStart("message")
|
||||
e.Str(s.Message)
|
||||
}
|
||||
{
|
||||
if s.Details.Set {
|
||||
e.FieldStart("details")
|
||||
s.Details.Encode(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfError = [2]string{
|
||||
0: "code",
|
||||
1: "message",
|
||||
0: "message",
|
||||
1: "details",
|
||||
}
|
||||
|
||||
// Decode decodes Error from json.
|
||||
|
|
@ -46,20 +48,8 @@ func (s *Error) Decode(d *jx.Decoder) error {
|
|||
|
||||
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
||||
switch string(k) {
|
||||
case "code":
|
||||
requiredBitSet[0] |= 1 << 0
|
||||
if err := func() error {
|
||||
v, err := d.Int()
|
||||
s.Code = int(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"code\"")
|
||||
}
|
||||
case "message":
|
||||
requiredBitSet[0] |= 1 << 1
|
||||
requiredBitSet[0] |= 1 << 0
|
||||
if err := func() error {
|
||||
v, err := d.Str()
|
||||
s.Message = string(v)
|
||||
|
|
@ -70,6 +60,16 @@ func (s *Error) Decode(d *jx.Decoder) error {
|
|||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"message\"")
|
||||
}
|
||||
case "details":
|
||||
if err := func() error {
|
||||
s.Details.Reset()
|
||||
if err := s.Details.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"details\"")
|
||||
}
|
||||
default:
|
||||
return d.Skip()
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func (s *Error) Decode(d *jx.Decoder) error {
|
|||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00000011,
|
||||
0b00000001,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
|
|
@ -977,6 +977,41 @@ func (s *GetSubscriptionsOKSubscriptionsItemType) UnmarshalJSON(data []byte) err
|
|||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes string as json.
|
||||
func (o OptString) Encode(e *jx.Encoder) {
|
||||
if !o.Set {
|
||||
return
|
||||
}
|
||||
e.Str(string(o.Value))
|
||||
}
|
||||
|
||||
// Decode decodes string from json.
|
||||
func (o *OptString) Decode(d *jx.Decoder) error {
|
||||
if o == nil {
|
||||
return errors.New("invalid: unable to decode OptString to nil")
|
||||
}
|
||||
o.Set = true
|
||||
v, err := d.Str()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.Value = string(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements stdjson.Marshaler.
|
||||
func (s OptString) MarshalJSON() ([]byte, error) {
|
||||
e := jx.Encoder{}
|
||||
s.Encode(&e)
|
||||
return e.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements stdjson.Unmarshaler.
|
||||
func (s *OptString) UnmarshalJSON(data []byte) error {
|
||||
d := jx.DecodeBytes(data)
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode implements json.Marshaler.
|
||||
func (s *SubscribeSatelliteOK) Encode(e *jx.Encoder) {
|
||||
e.ObjStart()
|
||||
|
|
|
|||
|
|
@ -16,13 +16,8 @@ func (s *ErrorStatusCode) Error() string {
|
|||
|
||||
// Ref: #/components/schemas/Error
|
||||
type Error struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// GetCode returns the value of Code.
|
||||
func (s *Error) GetCode() int {
|
||||
return s.Code
|
||||
Message string `json:"message"`
|
||||
Details OptString `json:"details"`
|
||||
}
|
||||
|
||||
// GetMessage returns the value of Message.
|
||||
|
|
@ -30,9 +25,9 @@ func (s *Error) GetMessage() string {
|
|||
return s.Message
|
||||
}
|
||||
|
||||
// SetCode sets the value of Code.
|
||||
func (s *Error) SetCode(val int) {
|
||||
s.Code = val
|
||||
// GetDetails returns the value of Details.
|
||||
func (s *Error) GetDetails() OptString {
|
||||
return s.Details
|
||||
}
|
||||
|
||||
// SetMessage sets the value of Message.
|
||||
|
|
@ -40,6 +35,11 @@ func (s *Error) SetMessage(val string) {
|
|||
s.Message = val
|
||||
}
|
||||
|
||||
// SetDetails sets the value of Details.
|
||||
func (s *Error) SetDetails(val OptString) {
|
||||
s.Details = val
|
||||
}
|
||||
|
||||
// ErrorStatusCode wraps Error with StatusCode.
|
||||
type ErrorStatusCode struct {
|
||||
StatusCode int
|
||||
|
|
@ -412,6 +412,52 @@ func (s *GetSubscriptionsOKSubscriptionsItemType) UnmarshalText(data []byte) err
|
|||
}
|
||||
}
|
||||
|
||||
// NewOptString returns new OptString with value set to v.
|
||||
func NewOptString(v string) OptString {
|
||||
return OptString{
|
||||
Value: v,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
|
||||
// OptString is optional string.
|
||||
type OptString struct {
|
||||
Value string
|
||||
Set bool
|
||||
}
|
||||
|
||||
// IsSet returns true if OptString was set.
|
||||
func (o OptString) IsSet() bool { return o.Set }
|
||||
|
||||
// Reset unsets value.
|
||||
func (o *OptString) Reset() {
|
||||
var v string
|
||||
o.Value = v
|
||||
o.Set = false
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *OptString) SetTo(v string) {
|
||||
o.Set = true
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o OptString) Get() (v string, ok bool) {
|
||||
if !o.Set {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o OptString) Or(d string) string {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptUUID returns new OptUUID with value set to v.
|
||||
func NewOptUUID(v uuid.UUID) OptUUID {
|
||||
return OptUUID{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue