【发布时间】:2018-03-30 21:05:23
【问题描述】:
我是 golang 新手,使用 julienschmidt/httprouter 进行路由。 基于下面的sn-p,可以发送一个参数。 但我对发送多个参数有点困惑,云任何人都可以帮助我。
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"log"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
log.Fatal(http.ListenAndServe(":8080", router))
}
【问题讨论】: