这个问题我在beego官方找不到。本身学Go语言不久。
代码如下
```go
package models
import (
"time"
"github.com/astaxie/beego/orm"
"crypto/md5"
"encoding/hex"
)
type Users struct {
Id int `orm:"pk"`
Username string
Realname string
Createdate time.Time `orm:"auto_now_add:type(datetime)"`
Modifydate time.Time `orm:"auto_now_add:type(datetime)"`
Passwd string
User_level string
Email string
Gender string
}
func Md5encryption(beforeMd5ed string) string {
h := md5.New()
h.Write([]byte(beforeMd5ed))
return hex.EncodeToString(h.Sum(nil))
}
func VerifyUser(UserName string,ThePasswd string) bool {
o := orm.NewOrm()
u := Users{Username:UserName}
_ = o.Read(&u,"username")
return Md5encryption(ThePasswd) == u.Passwd
}
func DBinsert(UserName string,Email string,Password string,RealName string,Gender string) bool {
o := orm.NewOrm()
var u Users
u.Username = UserName
u.Passwd = Md5encryption(Password)
u.Email = Email
u.Gender = Gender
u.Realname = RealName
_,err := o.Insert(&u)
if err == nil {
return true
}else {
return false
}
}
func CheckUN(username string) bool {
o := orm.NewOrm()
u := Users{Username:username}
err := o.Read(&u,"username")
if err == orm.ErrNoRows {
return true
}else {
return false
}
}
func GetUserInfo(username string) Users {
o :=orm.NewOrm()
u := Users{Username:username}
o.Read(&u,"username")
return u
}
```
beego 出现[router.go:656][E] gob: name not registered for interface: "deploy/models/class.Users"
rffan · · 3469 次点击更多评论