GoFrame :路由与控制器 3.1 路由基础 3.1.1 路由定义 基本路由定义 package main import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) func main() { s := g.Server() // 简单路由 s.BindHandler("/hello", func(r *ghttp.Request) { r.Response.Write("Hello, GoFrame!") }) // 启动服务 s.Run() } 路由参数 // 路径参数 s.BindHandler("/user/{id}", func(r *ghttp.Request) { userId := r.Get("id") r.Response.Write("User ID: " + userId) }) // 查询参数 s.BindHandler("/search", func(r *ghttp.Request) { keyword := r.Get("keyword") r.Response.Write("Search Keyword: " + keyword) }) 3.1.2 RESTful路由 RESTful风格路由 type UserController struct { g.Controller } func (c *UserController) Get() { // GET /users c.Response.WriteJson(g.Map{ "message": "Get all users", }) } func (c *UserController) Post() { // POST /users c.Response.WriteJson(g.Map{ "message": "Create a n