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"),"Familu", ps.ByName("fam"))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name/:fam", Hello)
log.Fatal(http.ListenAndServe(":9001", router))
}
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"))
fmt.Fprintf(w, "Fam, %s!\n", ps.ByName("fam"))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name/:fam", Hello)
log.Fatal(http.ListenAndServe(":9001", router))
}
...
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\nFam, %s!\n", ps.ByName("name"), ps.ByName("fam"))
}
...