github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/models/user_card.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  // UserCard A minimal representation of a user.
    17  //
    18  // This representation of a user is mainly meant for inclusion in other models, or for list views.
    19  //
    20  // swagger:model UserCard
    21  type UserCard struct {
    22  
    23  	// When true this user is an admin.
    24  	//
    25  	// Only employees of the owning company can be admins.
    26  	// Admins are like project owners but have access to all the projects in the application.
    27  	// There aren't many admins, and it's only used for extremly critical issues with the application.
    28  	//
    29  	// Read Only: true
    30  	Admin *bool `json:"admin,omitempty"`
    31  
    32  	// The amount of karma this user has available.
    33  	//
    34  	// In this application users get a cerain amount of karma alotted.
    35  	// This karma can be donated to other users to show appreciation, or it can be used
    36  	// by a user to vote on issues.
    37  	// Once an issue is closed or rejected, the user gets his karma back.
    38  	//
    39  	// Read Only: true
    40  	// Maximum: < 1000
    41  	AvailableKarma float64 `json:"availableKarma,omitempty"`
    42  
    43  	// A unique identifier for a user.
    44  	//
    45  	// This id is automatically generated on the server when a user is created.
    46  	//
    47  	// Required: true
    48  	// Read Only: true
    49  	ID int64 `json:"id"`
    50  
    51  	// The screen name for the user.
    52  	//
    53  	// This is used for vanity type urls as well as login credentials.
    54  	//
    55  	// Required: true
    56  	// Max Length: 255
    57  	// Min Length: 3
    58  	// Pattern: \w[\w_-]+
    59  	ScreenName *string `json:"screenName"`
    60  }
    61  
    62  // Validate validates this user card
    63  func (m *UserCard) Validate(formats strfmt.Registry) error {
    64  	var res []error
    65  
    66  	if err := m.validateAvailableKarma(formats); err != nil {
    67  		res = append(res, err)
    68  	}
    69  
    70  	if err := m.validateID(formats); err != nil {
    71  		res = append(res, err)
    72  	}
    73  
    74  	if err := m.validateScreenName(formats); err != nil {
    75  		res = append(res, err)
    76  	}
    77  
    78  	if len(res) > 0 {
    79  		return errors.CompositeValidationError(res...)
    80  	}
    81  	return nil
    82  }
    83  
    84  func (m *UserCard) validateAvailableKarma(formats strfmt.Registry) error {
    85  
    86  	if swag.IsZero(m.AvailableKarma) { // not required
    87  		return nil
    88  	}
    89  
    90  	if err := validate.Maximum("availableKarma", "body", float64(m.AvailableKarma), 1000, true); err != nil {
    91  		return err
    92  	}
    93  
    94  	return nil
    95  }
    96  
    97  func (m *UserCard) validateID(formats strfmt.Registry) error {
    98  
    99  	if err := validate.Required("id", "body", int64(m.ID)); err != nil {
   100  		return err
   101  	}
   102  
   103  	return nil
   104  }
   105  
   106  func (m *UserCard) validateScreenName(formats strfmt.Registry) error {
   107  
   108  	if err := validate.Required("screenName", "body", m.ScreenName); err != nil {
   109  		return err
   110  	}
   111  
   112  	if err := validate.MinLength("screenName", "body", string(*m.ScreenName), 3); err != nil {
   113  		return err
   114  	}
   115  
   116  	if err := validate.MaxLength("screenName", "body", string(*m.ScreenName), 255); err != nil {
   117  		return err
   118  	}
   119  
   120  	if err := validate.Pattern("screenName", "body", string(*m.ScreenName), `\w[\w_-]+`); err != nil {
   121  		return err
   122  	}
   123  
   124  	return nil
   125  }
   126  
   127  // MarshalBinary interface implementation
   128  func (m *UserCard) MarshalBinary() ([]byte, error) {
   129  	if m == nil {
   130  		return nil, nil
   131  	}
   132  	return swag.WriteJSON(m)
   133  }
   134  
   135  // UnmarshalBinary interface implementation
   136  func (m *UserCard) UnmarshalBinary(b []byte) error {
   137  	var res UserCard
   138  	if err := swag.ReadJSON(b, &res); err != nil {
   139  		return err
   140  	}
   141  	*m = res
   142  	return nil
   143  }