github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/models/comment.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  // Comment A comment for an issue.
    17  //
    18  // Users can comment on issues to discuss plans for resolution etc.
    19  //
    20  // swagger:model Comment
    21  type Comment struct {
    22  
    23  	// The content of the comment.
    24  	//
    25  	// This is a free text field with support for github flavored markdown.
    26  	//
    27  	// Required: true
    28  	Content *string `json:"content"`
    29  
    30  	// The time at which this comment was created.
    31  	//
    32  	// This field is autogenerated when the content is posted.
    33  	// Read Only: true
    34  	// Format: date-time
    35  	CreatedAt strfmt.DateTime `json:"createdAt,omitempty"`
    36  
    37  	// user
    38  	// Required: true
    39  	User *UserCard `json:"user"`
    40  }
    41  
    42  // Validate validates this comment
    43  func (m *Comment) Validate(formats strfmt.Registry) error {
    44  	var res []error
    45  
    46  	if err := m.validateContent(formats); err != nil {
    47  		res = append(res, err)
    48  	}
    49  
    50  	if err := m.validateCreatedAt(formats); err != nil {
    51  		res = append(res, err)
    52  	}
    53  
    54  	if err := m.validateUser(formats); err != nil {
    55  		res = append(res, err)
    56  	}
    57  
    58  	if len(res) > 0 {
    59  		return errors.CompositeValidationError(res...)
    60  	}
    61  	return nil
    62  }
    63  
    64  func (m *Comment) validateContent(formats strfmt.Registry) error {
    65  
    66  	if err := validate.Required("content", "body", m.Content); err != nil {
    67  		return err
    68  	}
    69  
    70  	return nil
    71  }
    72  
    73  func (m *Comment) validateCreatedAt(formats strfmt.Registry) error {
    74  
    75  	if swag.IsZero(m.CreatedAt) { // not required
    76  		return nil
    77  	}
    78  
    79  	if err := validate.FormatOf("createdAt", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
    80  		return err
    81  	}
    82  
    83  	return nil
    84  }
    85  
    86  func (m *Comment) validateUser(formats strfmt.Registry) error {
    87  
    88  	if err := validate.Required("user", "body", m.User); err != nil {
    89  		return err
    90  	}
    91  
    92  	if m.User != nil {
    93  		if err := m.User.Validate(formats); err != nil {
    94  			if ve, ok := err.(*errors.Validation); ok {
    95  				return ve.ValidateName("user")
    96  			}
    97  			return err
    98  		}
    99  	}
   100  
   101  	return nil
   102  }
   103  
   104  // MarshalBinary interface implementation
   105  func (m *Comment) MarshalBinary() ([]byte, error) {
   106  	if m == nil {
   107  		return nil, nil
   108  	}
   109  	return swag.WriteJSON(m)
   110  }
   111  
   112  // UnmarshalBinary interface implementation
   113  func (m *Comment) UnmarshalBinary(b []byte) error {
   114  	var res Comment
   115  	if err := swag.ReadJSON(b, &res); err != nil {
   116  		return err
   117  	}
   118  	*m = res
   119  	return nil
   120  }