英文:
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.
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")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论