示例2,使用字段匹配路由

    1. package main
    2. import (
    3. "github.com/gogf/gf/v2/frame/g"
    4. "github.com/gogf/gf/v2/net/ghttp"
    5. "github.com/gogf/gf/v2/os/gview"
    6. )
    7. func main() {
    8. s.BindHandler("/:obj/*action/{page}.html", func(r *ghttp.Request) {
    9. buffer, _ := gview.ParseContent(`
    10. <html>
    11. <head>
    12. <style>
    13. a,span {padding:8px; font-size:16px;}
    14. div{margin:5px 5px 20px 5px}
    15. </style>
    16. </head>
    17. <body>
    18. <div>{{.page1}}</div>
    19. <div>{{.page2}}</div>
    20. </body>
    21. </html>
    22. `, g.Map{
    23. "page1": page.GetContent(1),
    24. "page2": page.GetContent(2),
    25. "page3": page.GetContent(3),
    26. "page4": page.GetContent(4),
    27. })
    28. r.Response.Write(buffer)
    29. })
    30. s.SetPort(8199)
    31. s.Run()