我的项目是使用bee api appname [bee api xxabc]创建的,一切运行正常。由于某种原因,必须将项目重命名为xx-def并将所有导入更改为新的重命名包" github.com/username/xx-def/controllers"等
但是现在使用bee run运行项目时,构建成功但是在点击路径时显示GET / api 404不匹配
我删除了所有以前的软件包以及pkg和bin文件夹并获取了所有内容,但没有解决问题。
main.go
package main
import (
"os"
"github.com/astaxie/beego"
"github.com/babajob/xx-def/services"
)
func main() {
BEEGO_RUNMODE := os.Getenv("BEEGO_RUNMODE")
if BEEGO_RUNMODE == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
beego.BConfig.RouterCaseSensitive = true
} else {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.RouterCaseSensitive = true
authPlugin := services.NewBasicAuthenticator(services.SecretAuth, "Authorization Required")
beego.InsertFilter("*", beego.BeforeRouter, authPlugin)
}
beego.Run()
}
router.go
package routers
import (
"github.com/astaxie/beego"
"github.com/babajob/xx-def/controllers"
)
func init() {
beego.Router("/api", &controllers.XYZController{}, "get:Api")
}
XYZController.go
package controllers
import (
"strconv"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/babajob/xx-def/models"
"github.com/babajob/xx-def/repository"
"github.com/babajob/xx-def/services"
"github.com/gorilla/feeds"
)
type XYZController struct {
beego.Controller
}
func (x *XYZController) Api() {
//do something db related
x.Data["json"] = "hello"
x.ServeJSON()
}
有一个commentsRouter_controllers.go文件,我认为Swagger使用它甚至我更新了它但没有用