.
│ go.mod
│ go.sum
│
├─controller
│ └─IndexController
│ index.go
│
├─main
│ main.go
│
├─model
├─router
│ router.go
│
└─views
└─index
index.html
main.go_ "demoCode/beego_example/router"
package main
import (
_ "demoCode/beego_example/router"
"github.com/astaxie/beego"
)
func main() {
beego.Run()
}
router.go
beego.Routercontroller
/index/index
Controller
method
*methodhttpmethod:funcname;funcnamemethod
可用的 HTTP Method:
*: 包含以下所有的函数
get: GET 请求
post: POST 请求
put: PUT 请求
delete: DELETE 请求
patch: PATCH 请求
options: OPTIONS 请求
head: HEAD 请求
package router
import (
"demoCode/beego_example/controller/IndexController"
"github.com/astaxie/beego"
)
func init() {
beego.Router("/index", &IndexController.IndexController{}, "*:Index")
}
/indexIndexControllerindex.go
Index()TplName
package IndexController
import "github.com/astaxie/beego"
type IndexController struct {
beego.Controller
}
func (p *IndexController) Index() {
p.TplName = "index/index.html"
}
index.html
<p>Hello, worldp>