github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/authentication/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
    18  //
    19  // swagger:model error
    20  type Error struct {
    21  
    22  	// code
    23  	Code int64 `json:"code,omitempty"`
    24  
    25  	// fields
    26  	Fields string `json:"fields,omitempty"`
    27  
    28  	// message
    29  	// Required: true
    30  	Message *string `json:"message"`
    31  }
    32  
    33  // Validate validates this error
    34  func (m *Error) Validate(formats strfmt.Registry) error {
    35  	var res []error
    36  
    37  	if err := m.validateMessage(formats); err != nil {
    38  		res = append(res, err)
    39  	}
    40  
    41  	if len(res) > 0 {
    42  		return errors.CompositeValidationError(res...)
    43  	}
    44  	return nil
    45  }
    46  
    47  func (m *Error) validateMessage(formats strfmt.Registry) error {
    48  
    49  	if err := validate.Required("message", "body", m.Message); err != nil {
    50  		return err
    51  	}
    52  
    53  	return nil
    54  }
    55  
    56  // ContextValidate validates this error based on context it is used
    57  func (m *Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    58  	return nil
    59  }
    60  
    61  // MarshalBinary interface implementation
    62  func (m *Error) MarshalBinary() ([]byte, error) {
    63  	if m == nil {
    64  		return nil, nil
    65  	}
    66  	return swag.WriteJSON(m)
    67  }
    68  
    69  // UnmarshalBinary interface implementation
    70  func (m *Error) UnmarshalBinary(b []byte) error {
    71  	var res Error
    72  	if err := swag.ReadJSON(b, &res); err != nil {
    73  		return err
    74  	}
    75  	*m = res
    76  	return nil
    77  }