package models import ( "shopperthree_manage_v2/client/mysql" "shopperthree_manage_v2/pkg/ierr" ) type File struct { Url string `json:"url" gorm:"url;type:varchar(512);NOT NULL"` // URL地址 Name string `json:"name" gorm:"name;type:varchar(128);NOT NULL"` // 文件名 Path string `json:"path" gorm:"path;type:varchar(128);NOT NULL"` // 存储的路径 Size int64 `json:"size" gorm:"size;NOT NULL"` // 文件大小 Ext string `json:"ext" gorm:"ext;type:varchar(16);NOT NULL"` // 文件后缀 UserId string `json:"user_id" gorm:"user_id;type:varchar(20);NOT NULL;index:idx_user_id"` // 上传的用户id CommonField } func (f *File) TableName() string { return "file" } func (f *File) Save() error { if f.Name == "" { return ierr.NewIError(ierr.InvalidFilename, "invalid file name") } if f.UserId == "" { return ierr.NewIError(ierr.InvalidUserId, "invalid user id") } var err = mysql.Client.Master().Save(f).Error if err != nil { return ierr.NewIError(ierr.CreateDataFail, err.Error()) } return nil }