Beego为何永久出现404未知错误?

发布于 2025-01-20 21:40:51 字数 1650 浏览 0 评论 0原文

我将beego用于我的项目,但是在设置项目后,我只会遇到404个错误... 我的主机和路由器都可以。 任何问题的想法,我一直在寻找几个小时,徒劳的...

main.go

import (
    _ "bealinkapi/routers"
    "github.com/beego/beego/v2/client/orm"
    beego "github.com/beego/beego/v2/server/web"
    _ "github.com/lib/pq"
    "time"
)

func main() {
    orm.RegisterDriver("Postgres", orm.DRPostgres)
    orm.DefaultTimeLoc = time.UTC
    o, _ := beego.AppConfig.String("sqlconn")
    err := orm.RegisterDataBase("MyAppName", "postgres", o)
    if err != nil {
        panic(err)
    }
    if beego.BConfig.RunMode == "dev" {
        beego.BConfig.WebConfig.DirectoryIndex = true
        beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
    }
    beego.Run()
}

Router.Go

// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact [email protected]
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers

import (
    "bealinkapi/controllers"

    beego "github.com/beego/beego/v2/server/web"
)

func init() {
    ns := beego.NewNamespace("/v1",
        beego.NSNamespace("/bl_user",
            beego.NSInclude(
                &controllers.BlUserController{},
            ),
        ),
    )
    beego.AddNamespace(ns)
}

Console: 2022/04/11 15:04:55.627 [D] [Router.go:1272] | 127.0.0.1 | 404 | 265.248µs | nomatch | get/v1/bl_user/1

I use Beego for my project, but after setting up the project, I only get 404 errors...
My main.go is ok, as well as my router.
Any idea of ​​the problem, I've been looking for several hours, in vain...

main.go

import (
    _ "bealinkapi/routers"
    "github.com/beego/beego/v2/client/orm"
    beego "github.com/beego/beego/v2/server/web"
    _ "github.com/lib/pq"
    "time"
)

func main() {
    orm.RegisterDriver("Postgres", orm.DRPostgres)
    orm.DefaultTimeLoc = time.UTC
    o, _ := beego.AppConfig.String("sqlconn")
    err := orm.RegisterDataBase("MyAppName", "postgres", o)
    if err != nil {
        panic(err)
    }
    if beego.BConfig.RunMode == "dev" {
        beego.BConfig.WebConfig.DirectoryIndex = true
        beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
    }
    beego.Run()
}

router.go

// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact [email protected]
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers

import (
    "bealinkapi/controllers"

    beego "github.com/beego/beego/v2/server/web"
)

func init() {
    ns := beego.NewNamespace("/v1",
        beego.NSNamespace("/bl_user",
            beego.NSInclude(
                &controllers.BlUserController{},
            ),
        ),
    )
    beego.AddNamespace(ns)
}

console:
2022/04/11 15:04:55.627 [D] [router.go:1272] | 127.0.0.1| 404 | 265.248µs| nomatch| GET /v1/bl_user/1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光飞翔i 2025-01-27 21:40:51

在使用 swagger 接口测试 api 调用时,我遇到了类似的问题,但是当我进行 postman 调用时,这是正常的,由于某种原因,问题出在 swagger 上。此外,当我创建新的命名空间和路由器时,在邮递员中测试时一切都按预期工作。

I had a similar issue when using the swagger interface to test the api calls, but when I did a postman call it was normal, for some reason the problem was with swagger. Also when I created new namespaces and routers everything worked as expected when testing in postman.

无悔心 2025-01-27 21:40:51

我也有同样的问题。从Bee v2.0.2中,您必须使用额外的命令生成路由器。

bee v2.0.3发行说明

bee generate routers
bee run

I had the same issue. From Bee V2.0.2 you have to generate the routers using an extra command.

Bee V2.0.3 release notes

Try this:

bee generate routers
bee run

空‖城人不在 2025-01-27 21:40:51

检查名为 commentrouter_controller.go 的文件
似乎您的项目中缺少此文件。

commentRouter_controller.go是自动生成的。如果没有,请检查此链接以获取更多信息 https://github.com/beego.com/beego/beego/beego/beego/beego/issues/issues/issues/issues /2520

Check the file named commentsRouter_controller.go
Seems this file is missing in your project.

commentsRouter_controller.go is generated automatically. If not please check this link for more info https://github.com/beego/beego/issues/2520

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文