码农笔录博客源码
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
586 B

package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
)
type UserService struct {
}
func FindByUserName(username string) (*models.User, error) {
o := orm.NewOrm()
qs := o.QueryTable(&models.User{})
var users []*models.User
_, err := qs.Filter("UserName", username).All(&users)
if err != nil {
return nil, err
}
if len(users) != 0 {
return users[0], nil
}
return nil, nil
}
func SaveUser(user *models.User) error {
o := orm.NewOrm()
id, eror := o.Insert(user)
if eror != nil {
return eror
} else {
user.Id = id
o.Commit()
}
return nil
}