github.com/circl-dev/go-swagger@v0.31.0/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/circl-dev/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  //
    23  // swagger:model Error
    24  type Error struct {
    25  
    26  	// the error code, this is not necessarily the http status code
    27  	// Required: true
    28  	Code *int32 `json:"code"`
    29  
    30  	// an optional url for getting more help about this error
    31  	// Format: uri
    32  	HelpURL strfmt.URI `json:"helpUrl,omitempty"`
    33  
    34  	// a human readable version of the error
    35  	// Required: true
    36  	Message *string `json:"message"`
    37  }
    38  
    39  // Validate validates this error
    40  func (m *Error) Validate(formats strfmt.Registry) error {
    41  	var res []error
    42  
    43  	if err := m.validateCode(formats); err != nil {
    44  		res = append(res, err)
    45  	}
    46  
    47  	if err := m.validateHelpURL(formats); err != nil {
    48  		res = append(res, err)
    49  	}
    50  
    51  	if err := m.validateMessage(formats); err != nil {
    52  		res = append(res, err)
    53  	}
    54  
    55  	if len(res) > 0 {
    56  		return errors.CompositeValidationError(res...)
    57  	}
    58  	return nil
    59  }
    60  
    61  func (m *Error) validateCode(formats strfmt.Registry) error {
    62  
    63  	if err := validate.Required("code", "body", m.Code); err != nil {
    64  		return err
    65  	}
    66  
    67  	return nil
    68  }
    69  
    70  func (m *Error) validateHelpURL(formats strfmt.Registry) error {
    71  	if swag.IsZero(m.HelpURL) { // not required
    72  		return nil
    73  	}
    74  
    75  	if err := validate.FormatOf("helpUrl", "body", "uri", m.HelpURL.String(), formats); err != nil {
    76  		return err
    77  	}
    78  
    79  	return nil
    80  }
    81  
    82  func (m *Error) validateMessage(formats strfmt.Registry) error {
    83  
    84  	if err := validate.Required("message", "body", m.Message); err != nil {
    85  		return err
    86  	}
    87  
    88  	return nil
    89  }
    90  
    91  // ContextValidate validates this error based on context it is used
    92  func (m *Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    93  	return nil
    94  }
    95  
    96  // MarshalBinary interface implementation
    97  func (m *Error) MarshalBinary() ([]byte, error) {
    98  	if m == nil {
    99  		return nil, nil
   100  	}
   101  	return swag.WriteJSON(m)
   102  }
   103  
   104  // UnmarshalBinary interface implementation
   105  func (m *Error) UnmarshalBinary(b []byte) error {
   106  	var res Error
   107  	if err := swag.ReadJSON(b, &res); err != nil {
   108  		return err
   109  	}
   110  	*m = res
   111  	return nil
   112  }