github.com/johnlanni/go-swagger@v0.19.0/examples/generated/models/order.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  // Order order
    17  // swagger:model Order
    18  type Order struct {
    19  
    20  	// complete
    21  	Complete bool `json:"complete,omitempty"`
    22  
    23  	// id
    24  	ID int64 `json:"id,omitempty"`
    25  
    26  	// pet Id
    27  	PetID int64 `json:"petId,omitempty"`
    28  
    29  	// quantity
    30  	Quantity int32 `json:"quantity,omitempty"`
    31  
    32  	// ship date
    33  	// Format: date-time
    34  	ShipDate strfmt.DateTime `json:"shipDate,omitempty"`
    35  
    36  	// Order Status
    37  	Status string `json:"status,omitempty"`
    38  }
    39  
    40  // Validate validates this order
    41  func (m *Order) Validate(formats strfmt.Registry) error {
    42  	var res []error
    43  
    44  	if err := m.validateShipDate(formats); err != nil {
    45  		res = append(res, err)
    46  	}
    47  
    48  	if len(res) > 0 {
    49  		return errors.CompositeValidationError(res...)
    50  	}
    51  	return nil
    52  }
    53  
    54  func (m *Order) validateShipDate(formats strfmt.Registry) error {
    55  
    56  	if swag.IsZero(m.ShipDate) { // not required
    57  		return nil
    58  	}
    59  
    60  	if err := validate.FormatOf("shipDate", "body", "date-time", m.ShipDate.String(), formats); err != nil {
    61  		return err
    62  	}
    63  
    64  	return nil
    65  }
    66  
    67  // MarshalBinary interface implementation
    68  func (m *Order) MarshalBinary() ([]byte, error) {
    69  	if m == nil {
    70  		return nil, nil
    71  	}
    72  	return swag.WriteJSON(m)
    73  }
    74  
    75  // UnmarshalBinary interface implementation
    76  func (m *Order) UnmarshalBinary(b []byte) error {
    77  	var res Order
    78  	if err := swag.ReadJSON(b, &res); err != nil {
    79  		return err
    80  	}
    81  	*m = res
    82  	return nil
    83  }