You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
|
|
|
)
|
|
|
|
type User struct {
|
|
|
|
Model
|
|
|
|
Name string `json:"name"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Nickname string `json:"nickname"`
|
|
|
|
Avator string `json:"avator"`
|
|
|
|
}
|
|
|
|
func CreateUser(name string,password string,avator string){
|
|
|
|
user:=&User{
|
|
|
|
Name:name,
|
|
|
|
Password: password,
|
|
|
|
Avator:avator,
|
|
|
|
}
|
|
|
|
DB.Create(user)
|
|
|
|
}
|
|
|
|
func FindUser(username string)User{
|
|
|
|
var user User
|
|
|
|
DB.Where("name = ?", username).First(&user)
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
func FindUserById(id interface{})User{
|
|
|
|
var user User
|
|
|
|
DB.Where("id = ?", id).First(&user)
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
func DeleteUserById(id string){
|
|
|
|
DB.Where("id = ?",id).Delete(User{})
|
|
|
|
}
|
|
|
|
func FindUsers()[]User{
|
|
|
|
var users []User
|
|
|
|
DB.Order("id desc").Find(&users)
|
|
|
|
return users
|
|
|
|
}
|