Open icetech233 opened 3 weeks ago
gorilla/mux
r.Host("{subdomain:[a-z]+}.example.com")
r.HandleFunc("/products", ProductsHandler). Host("www.example.com"). Methods("GET"). Schemes("http")
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
api := r.Group("/api")
api.GET("/users/{id}", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "hello world",
})
})
if err := r.Run(":8080"); err != nil {
panic(err)
}
}
Is this what you want?
package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() api := r.Group("/api") api.GET("/users/{id}", func(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{ "message": "hello world", }) }) if err := r.Run(":8080"); err != nil { panic(err) } }
Is this what you want?
不是 ,域名 的英文 不认识吗??写了 host domain
can suport domain router? like github.com/gorilla/mux
Matching Routes Routes can also be restricted to a domain or subdomain. Just define a host pattern to be matched. They can also have variables:
r := mux.NewRouter() // Only matches if domain is "www.example.com". r.Host("www.example.com") // Matches a dynamic subdomain. r.Host("{subdomain:[a-z]+}.example.com") There are several other matchers that can be added. To match path prefixes:
r.PathPrefix("/products/")