can i call a controller directly from main without router in beego

huangapple go评论84阅读模式
英文:

can i call a controller directly from main without router in beego

问题

我有一个来自包xx的控制器,叫做XXController。现在我想将这个控制器作为一个函数调用,像这样xx.XXController{}。并且控制器内部的登录应该被执行。

英文:

I have a controller say XXController from package xx. Now i want this controller to be called as an function like xx.XXController{}. And the login inside controller should get executed.

答案1

得分: 0

这是我找到的一个使用Beego框架的示例。希望对你有所帮助。

示例代码链接

package routers

import (
	"github.com/astaxie/beego"
	ctl "github.com/ikeikeikeike/beego-samples/auth/controllers"
)

func init() {
	beego.Router("/", &ctl.UsersController{}, "get:Index")
	beego.Router("/login", &ctl.LoginController{}, "get,post:Login")
	beego.Router("/logout", &ctl.LoginController{}, "get:Logout")
	beego.Router("/signup", &ctl.LoginController{}, "get,post:Signup")
}
英文:

This is an example I found using Beego Framework. Hope this helps.

Link to example Code

package routers

import (
	"github.com/astaxie/beego"
	ctl "github.com/ikeikeikeike/beego-samples/auth/controllers"
)

func init() {
	beego.Router("/", &ctl.UsersController{}, "get:Index")
	beego.Router("/login", &ctl.LoginController{}, "get,post:Login")
	beego.Router("/logout", &ctl.LoginController{}, "get:Logout")
	beego.Router("/signup", &ctl.LoginController{}, "get,post:Signup")
}

huangapple
  • 本文由 发表于 2015年10月20日 19:39:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/33235643.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定