This question already has an answer here:
I am creating a Restful API.
I am passing function name and arguments in JSON
eg. "localhost/json_server?method=foo&id=1"
Lets say, i have a simple go server running
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("path",r.URL.Path )
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
.........
function json_server(){
....
}
The r.url.Path
will give me "json_server
" in string. Now i want to first check if the function exists , if exists call the function as defined else throw some exception.
Is this possible to do ?
When i am doing python and i use getattr(method,args)
to call the method and arguments which are in string.
I have developed interest in Go after using Docker. Any help will be appreciated.
</div>