Current location - Quotes Website - Signature design - How does golang accept the data passed in by postman in the method?
How does golang accept the data passed in by postman in the method?
What you are doing is binding the full path to be processed. /location/{titanrolex}GetUser. What you really want is to bind /location/ to a handler (such as LocationHandler) to handle it.

You can do this using standard libraries or other routers. I will introduce two methods:

Standard library:

Import (

fmt

net//Julien Schmidt//Julien Schmidt//http

log

)

functionlocationhandler(whttp。 ResponseWriter。 Request, pshttprouter Params){

fmt。 Fprintf(w, location: %s\n, ps. Alias (location))

}

funcmain(){

Router: = httprouter. New ()

Router. GET(/location/:loc,LocationHandler)

Journal. Fatal (http. ListenAndServe(:8080, router))

}

Note that httprouter uses a slightly different signature for the handler. As you can see, this is because it also passes these parameters to the function.

Oh, one more thing to note, you can click it directly on http://localhost: 8080/location/titanrolex with your browser-if something else is good enough, it will encode the URLEncode as http://localhost: 8080/location/titan% 20 Rolex.