Skip to content

Commit d899267

Browse files
committed
add httprouter example code
1 parent 5f6de79 commit d899267

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package httprouter
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
8+
"github.com/julienschmidt/httprouter"
9+
)
10+
11+
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
12+
fmt.Fprint(w, "Welcome!\n")
13+
}
14+
15+
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
16+
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
17+
}
18+
19+
func main() {
20+
router := httprouter.New()
21+
router.GET("/test/*test", Index)
22+
router.GET("/hello/:name", Hello)
23+
24+
log.Fatal(http.ListenAndServe(":8082", router))
25+
}

0 commit comments

Comments
 (0)