github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/models/error.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/strfmt" 13 "github.com/go-openapi/swag" 14 "github.com/go-openapi/validate" 15 ) 16 17 // Error Error Structure 18 // 19 // Contains all the properties any error response from the API will contain. 20 // Some properties are optional so might be empty most of the time 21 // 22 // swagger:model Error 23 type Error struct { 24 25 // the error code, this is not necessarily the http status code 26 // Required: true 27 Code *int32 `json:"code"` 28 29 // an optional url for getting more help about this error 30 // Format: uri 31 HelpURL strfmt.URI `json:"helpUrl,omitempty"` 32 33 // a human readable version of the error 34 // Required: true 35 Message *string `json:"message"` 36 } 37 38 // Validate validates this error 39 func (m *Error) Validate(formats strfmt.Registry) error { 40 var res []error 41 42 if err := m.validateCode(formats); err != nil { 43 res = append(res, err) 44 } 45 46 if err := m.validateHelpURL(formats); err != nil { 47 res = append(res, err) 48 } 49 50 if err := m.validateMessage(formats); err != nil { 51 res = append(res, err) 52 } 53 54 if len(res) > 0 { 55 return errors.CompositeValidationError(res...) 56 } 57 return nil 58 } 59 60 func (m *Error) validateCode(formats strfmt.Registry) error { 61 62 if err := validate.Required("code", "body", m.Code); err != nil { 63 return err 64 } 65 66 return nil 67 } 68 69 func (m *Error) validateHelpURL(formats strfmt.Registry) error { 70 if swag.IsZero(m.HelpURL) { // not required 71 return nil 72 } 73 74 if err := validate.FormatOf("helpUrl", "body", "uri", m.HelpURL.String(), formats); err != nil { 75 return err 76 } 77 78 return nil 79 } 80 81 func (m *Error) validateMessage(formats strfmt.Registry) error { 82 83 if err := validate.Required("message", "body", m.Message); err != nil { 84 return err 85 } 86 87 return nil 88 } 89 90 // ContextValidate validates this error based on context it is used 91 func (m *Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 92 return nil 93 } 94 95 // MarshalBinary interface implementation 96 func (m *Error) MarshalBinary() ([]byte, error) { 97 if m == nil { 98 return nil, nil 99 } 100 return swag.WriteJSON(m) 101 } 102 103 // UnmarshalBinary interface implementation 104 func (m *Error) UnmarshalBinary(b []byte) error { 105 var res Error 106 if err := swag.ReadJSON(b, &res); err != nil { 107 return err 108 } 109 *m = res 110 return nil 111 }