12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package models
- import (
- "errors"
- "github.com/jinzhu/gorm"
- )
- // User user
- type User struct {
- gorm.Model
- UserKey string
- UserRoleID int
- UserName string `sql:"type:varchar(20);not null;"`
- UserPass string `sql:"type:varchar(50);not null;"`
- Phone string `sql:"type:varchar(20);not null;"`
- Email string `sql:"type:varchar(200);not null;"`
- UserType int `sql:"default:1;not null;"`
- VendorID uint
- Status int `sql:"default:1;not null;"`
- Vendor Vendor `gorm:"foreignkey:VendorID"`
- }
- // Validate 验证
- func (a *User) Validate() error {
- if a.UserName == "" || a.UserPass == "" || a.Vendor.VendorName == "" {
- return errors.New("参数不能为空")
- }
- return nil
- }
- // LoginRequest 登录请求
- type LoginRequest struct {
- UserName string `json:"login_name" `
- Password string `json:"login_pass" `
- }
- // Validate 验证
- func (a *LoginRequest) Validate() error {
- if a.UserName == "" || a.Password == "" {
- return errors.New("参数不能为空")
- }
- return nil
- }
- // Reqrequest 注册请求
- type Reqrequest struct {
- UserName string `json:"username"`
- PassWord string `json:"password" `
- Phone string `json:"phone" `
- Email string `json:"email" `
- VendorName string `json:"company"`
- }
- // Validate 验证
- func (a *Reqrequest) Validate() error {
- if a.UserName == "" || a.PassWord == "" || a.Phone == "" || a.Email == "" || a.VendorName == "" {
- return errors.New("参数不能为空")
- }
- return nil
- }
|