add httprouter example code

This commit is contained in:
Yunus AYDIN
2023-12-14 00:23:09 +03:00
parent 5f6de79c09
commit d899267acb

View File

@@ -0,0 +1,25 @@
package httprouter
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
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("/test/*test", Index)
router.GET("/hello/:name", Hello)
log.Fatal(http.ListenAndServe(":8082", router))
}