github.com/emreu/go-swagger@v0.22.1/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 strfmt "github.com/go-openapi/strfmt" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/swag" 13 "github.com/go-openapi/validate" 14 ) 15 16 // Error Error Structure 17 // 18 // Contains all the properties any error response from the API will contain. 19 // Some properties are optional so might be empty most of the time 20 // 21 // swagger:model Error 22 type Error struct { 23 24 // the error code, this is not necessarily the http status code 25 // Required: true 26 Code *int32 `json:"code"` 27 28 // an optional url for getting more help about this error 29 // Format: uri 30 HelpURL strfmt.URI `json:"helpUrl,omitempty"` 31 32 // a human readable version of the error 33 // Required: true 34 Message *string `json:"message"` 35 } 36 37 // Validate validates this error 38 func (m *Error) Validate(formats strfmt.Registry) error { 39 var res []error 40 41 if err := m.validateCode(formats); err != nil { 42 res = append(res, err) 43 } 44 45 if err := m.validateHelpURL(formats); err != nil { 46 res = append(res, err) 47 } 48 49 if err := m.validateMessage(formats); err != nil { 50 res = append(res, err) 51 } 52 53 if len(res) > 0 { 54 return errors.CompositeValidationError(res...) 55 } 56 return nil 57 } 58 59 func (m *Error) validateCode(formats strfmt.Registry) error { 60 61 if err := validate.Required("code", "body", m.Code); err != nil { 62 return err 63 } 64 65 return nil 66 } 67 68 func (m *Error) validateHelpURL(formats strfmt.Registry) error { 69 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 // MarshalBinary interface implementation 91 func (m *Error) MarshalBinary() ([]byte, error) { 92 if m == nil { 93 return nil, nil 94 } 95 return swag.WriteJSON(m) 96 } 97 98 // UnmarshalBinary interface implementation 99 func (m *Error) UnmarshalBinary(b []byte) error { 100 var res Error 101 if err := swag.ReadJSON(b, &res); err != nil { 102 return err 103 } 104 *m = res 105 return nil 106 }