I'm running the below code using goapp serve
. Somehow getting 404 page not found
error while checking from postman. Could you please help me to fix this
package hello
import (
"fmt"
"net/http"
"github.com/julienschmidt/httprouter"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!
")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!
", ps.ByName("name"))
}
func init() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
//log.Fatal(http.ListenAndServe(":8080", router))
}
In postman passing endpoint
http://localhost:8080/hello/hyderabad