golangWEB框架gin学习之路由群组

原文地址:http://www.niu12.com/article/42

package main

import (
"github.com/gin-gonic/gin"
"net/http"
)

func main() {
route := gin.Default()
route.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "hello world")
})
v1 := route.Group("/v1")
{
// http://localhost:8080/v1 输出 v1's homepage
v1.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "v1's homepage")
})

// http://localhost:8080/v1/login 输出 v1's login page
v1.GET("/login", func(c *gin.Context) {
c.String(http.StatusOK, "v1's login page")
})
}

v2 := route.Group("v2")
{
// http://localhost:8080/v2 输出 v2's homepage
v2.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "v2's homepage")
})

// http://localhost:8080/v2/login 输出 v2's login page
v2.GET("/login", func(c *gin.Context) {
c.String(http.StatusOK, "v2's login page")
})
}
route.Run(":8080")
}
posted @ 2018-10-18 11:09  周起  阅读(2086)  评论(0)    收藏  举报