duanhuang4306 2016-10-28 11:24
浏览 650

Beego Router Nomatch-404

My project was created using bee api appname [ bee api xxabc ] and everything was running fine. Due to some reason had to rename the project to xx-def and changing all the imports to the new renamed package "github.com/username/xx-def/controllers" etc.

But now on running the project using bee run the build is successful but it shows mismatch GET /api 404 on hitting the route

I had deleted all the previous packages and pkg and bin folder and go get everything but did not resolve the issue.

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()
}

There is a commentsRouter_controllers.go file which I think Swagger uses it even I updated it but no use

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题