2

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

souravlahoti
  • 716
  • 2
  • 8
  • 29
  • try to delete `commentsRouter_controllers.go` beego will rebuild it which may be the solution to your problem. – Stef K Nov 06 '16 at 10:53
  • 1
    Try beego admin router `/listconf?command=router` to check if the router init success. – Bryce Feb 08 '17 at 08:21

0 Answers0