Why GetBy can't be accessed, but PostBy can
- Dominant language
- Go
- Stars
- 25.6k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hello everyone, we are currently experiencing a strange problem and would like to ask for your help, as follows.
GET, visit http://127.0.0.1:8080/project/1, return 404
POST, visit http://127.0.0.1:8080/project/1, return 200
Only GetBy(id int64) is defined in the controller, not PostBy.
The code is as follows.
iris version:V12
controller:
```
// http://127.0.0.1:8080/project/1
func (p *ProjectController) GetBy(id int64) *proto.RspProject {
p.Ctx.Application().Logger().Infof(`get project info`) //should be prinf
ret := proto.NewRspProject()
return ret
}
```
route defined:
```
//route interface
type router interface {
setup(*mvc.Application)
path() string
}
//router manager:
func (r *routerMgr) Init(app *iris.Application) {
for _, v := range r.routers {
mvc.Configure(app.Party(v.path(), crs).AllowMethods(iris.MethodGet, iris.MethodPost), v.setup)
}
}
func (r *routerMgr) register(route ...router) {
r.routers = append(r.routers, route...)
}
//
//
//
//route define:
type projectRoute int
func (r *projectRoute) path() string {
return `/project`
}
func (r *projectRoute) setup(app *mvc.Application) {
servPro := services.NewProjectService()
sessManager := sessions.New(sessions.Config{
Cookie: "project",
Expires: 60 * time.Minute,
AllowReclaim: true,
})
app.Register(servPro, sessManager.Start)
app.Handle(new(controllers.ProjectController))
}
//
//
//
//somewhere register
NewRouterMgr().register(
new(usersRoute),
new(projectRoute),
)
```
debug log here:
```
[DBUG] 2020/04/16 15:22 MVC Controller [controllers.UserController] [Scope=Stateless]
[DBUG] 2020/04/16 15:22 Dependencies:
[1] Static binding: &services.userService{repo:(*dao.userDao)(0xc0000ca3a8)} for field 'UserServ services.UserService'
[DBUG] 2020/04/16 15:22 MVC dependencies of method 'controllers.UserController.GetBy':
[1] Dynamic binding: 'int64' for input position: 1 and type: 'int64'
[DBUG] 2020/04/16 15:22 MVC Controller [controllers.ProjectController] [Scope=Stateless]
[DBUG] 2020/04/16 15:22 Dependencies:
[1] Static binding: &services.projectService{repo:(*dao.projectDao)(0xc0000ca788)} for field 'ProServ services.ProjectService'
[DBUG] 2020/04/16 15:22 MVC dependencies of method 'controllers.ProjectController.GetBy':
[1] Dynamic binding: 'int64' for input position: 1 and type: 'int64'
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/{param1:int64} -> controllers.UserController.GetBy() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\project.go:29] GET: /project/{param1:int64} -> controllers.ProjectController.GetBy() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/search -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/add -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\project.go:29] GET: /project/allmembers -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/delete -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/login -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\project.go:29] POST: /project/{param1:int64} -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/logout -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/update -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] GET: /users/reg -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/{param1:int64} -> github.com/kataras/iris/v12/mvc.(*ControllerActivator).handlerOf.func2() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/reg -> controllers.UserController.PostReg() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/search -> controllers.UserController.PostSearch() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/logout -> controllers.UserController.PostLogout() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/update -> controllers.UserController.PostUpdate() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/login -> controllers.UserController.PostLogin() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/delete -> controllers.UserController.PostDelete() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\users.go:29] POST: /users/add -> controllers.UserController.PostAdd() and 1 more
[DBUG] 2020/04/16 15:22 [./web\routers\project.go:29] POST: /project/allmembers -> controllers.ProjectController.PostAllmembers() and 1 more
[DBUG] 2020/04/16 15:22 Application: running using 1 host(s)
[DBUG] 2020/04/16 15:22 Host: addr is localhost:8080
[DBUG] 2020/04/16 15:22 Host: virtual host is localhost:8080
[DBUG] 2020/04/16 15:22 Host: register startup notifier
[DBUG] 2020/04/16 15:22 Host: register server shutdown on interrupt(CTRL+C/CMD+C)
[DBUG] 2020/04/16 15:22 Host: server will ignore the following errors: [http: Server closed]
Now listening on: http://localhost:8080
Application started. Press CTRL+C to shut down.
```
Contributor guide
Assessment
This issue has not been assessed yet.