我尝试在 C 语言和 github 页面 https://github.com/c9s/r3 上使用 R3Route URL 路由器我看到以下内容:
#include <r3/r3.h>
// create a router tree with 10 children capacity (this capacity can grow dynamically)
R3Node *n = r3_tree_create(10);
int route_data = 3;
// insert the R3Route path into the router tree
r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path
有人可以告诉我这里的route_data是什么吗?为什么是3?
谢谢
最佳答案
我刚刚检查了这个库的源代码,发现了这个:
#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_ex(n,p,strlen(p), NULL, d, NULL)
其中 d 是你的 int = 3
这是该函数的新原型(prototype)
R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, int path_len, R3Route * route, void * data, char **errstr)
在这个函数中,数据仅在这一行使用
if (route) {
route->data = data;
}
route是一个结构体,其定义可以在r3.h中找到
我在代码中到处搜索这个 int 但没有成功..
如果您使用此结构(R3Route),则通过在结构中将参数传递为 void * 可能会很有用,但您应该尝试将 int * 更改为 NULL 并尝试执行您的程序。我并不是很有用,因为我不知道这个库,但这就是我发现的一切。 :)
关于c - C 中的 R3Route URL 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36346461/