[[path:"/handle"]]
[[method: Method.POST]]
void handle([[Bean]] Json json) {
....
}
由于c++是采用静态反射,不能运行时注入,想了想感觉可以从编译期生成注册代码来实现?
等有template for后可以这样实现:
//通过静态反射获取方法和属性的映射
map<Function, Attr> methodIntrospector=...;
// template for生成编译期代码,运行时注册
template for(auto entry: methodIntrospector) {
// 获取函数
Function func = entry.first;
// 获取属性
Attr attr = entry.second;
// 获取映射路径
Path path = attr.getPath();
// 获取请求方法
Method method = Attr.getMethod();
// 注册handle函数
registerHandlerMethod(path, method, func);
}