<分区>
我正在创建一个 Restful API。
我在 JSON 中传递函数名和参数
例如。 "localhost/json_server?method=foo&id=1"
比方说,我有一个简单的 go 服务器正在运行
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(){
....
}
r.url.Path
将在 string 中给我“json_server
”。现在我想首先检查该函数是否存在,如果存在则按定义调用该函数,否则抛出一些异常。
这可能吗?
当我在做 python 时,我使用 getattr(method,args)
调用字符串中的方法和参数。
使用 Docker 后,我对 Go 产生了兴趣。任何帮助将不胜感激。