main.go
package main
import (
"github.com/astaxie/beego"
_ "harbor-edge-imgsvr/initial"
_ "harbor-edge-imgsvr/routhers"
_ "harbor-edge-imgsvr/models"
)
func main() {
//beego.SetStaticPath("/api/v1/harbor/static", "tmp")
beego.Run()
}
models/init.go
package models
import (
"github.com/astaxie/beego/orm"
)
func init() {
orm.RegisterModel(
new(Statuss),
)
}
initial/db.go
package initial
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/mattn/go-sqlite3"
)
func init() {
orm.RegisterDriver("sqlite", orm.DRsqlite)
dbpath:=beego.AppConfig.String("dbpath")
orm.RegisterDataBase("default", "sqlite3", dbpath)
orm.RunSyncdb("default", false, true)
}
调试半天发现导包顺序错误,都是些小问题,但是平时不注意
main.go
package main
import (
"github.com/astaxie/beego"
_ "harbor-edge-imgsvr/models" // 注意这个须在initial包上面
_ "harbor-edge-imgsvr/initial"
_ "harbor-edge-imgsvr/routhers"
)
func main() {
//beego.SetStaticPath("/api/v1/harbor/static", "tmp")
beego.Run()
}