when registering models using the beego framework, an error is reported:
panic: <orm.RegisterModel> cannot use non-ptr model struct `.`
if you look at the description, you should pass in the pointer, but I passed the pointer (new)
.main.go
package db
import (
"github.com/astaxie/beego/orm"
)
func InitDB(models ...interface{}) {
orm.RegisterDriver("mysql", orm.DRMySQL)
// set default database
orm.RegisterDataBase("default", "mysql", "root:*****@tcp(127.0.0.1:3306)/db_test?charset=utf8", 30)
// register model
orm.RegisterModel(models)
// create table
orm.RunSyncdb("default", false, true)
}
db/main.go
package db
import (
"github.com/astaxie/beego/orm"
)
func InitDB(models ...interface{}) {
orm.RegisterDriver("mysql", orm.DRMySQL)
// set default database
orm.RegisterDataBase("default", "mysql", "root:123456@tcp(127.0.0.1:3306)/db_test?charset=utf8", 30)
// register model
orm.RegisterModel(models)
// create table
orm.RunSyncdb("default", false, true)
}
models/user.go
package models
import "hello/db"
type User struct {
Uid int `orm:"pk"`
Username string
Password string
}
The InitDB function in db/main.go registers models, and then reports an error
should be a grammatical problem