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()
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。