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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了