mirror of
https://gitee.com/sogou/srpc.git
synced 2024-12-21 16:14:54 +08:00
Merge pull request #292 from holmes1412/master
srpc tools: update get_opt for project_name; module: fix parent_span_id;
This commit is contained in:
commit
109faa46a6
@ -120,7 +120,7 @@ int main()
|
||||
|
||||
// 2. 构造参数,填上upstream的名字
|
||||
RPCClientParams client_params = RPC_CLIENT_PARAMS_DEFAULT;
|
||||
client_params.host = "srpc::echo_server"; // 这个scheme只用于upstream URI解析
|
||||
client_params.host = "echo_server";
|
||||
client_params.port = 1412; // 这个port只用于upstream URI解析,不影响具体实例的选取
|
||||
|
||||
// 3. 用参数创建client,其他用法与示例类似
|
||||
|
@ -125,7 +125,7 @@ int main()
|
||||
|
||||
// 2. create params and fill upstream name
|
||||
RPCClientParams client_params = RPC_CLIENT_PARAMS_DEFAULT;
|
||||
client_params.host = "srpc::echo_server"; // this scheme only used when upstream URI parsing
|
||||
client_params.host = "echo_server";
|
||||
client_params.port = 1412; // this port only used when upstream URI parsing and will not affect the select of instances
|
||||
|
||||
// 3. construct client by params, the rest of usage is similar as other tutorials
|
||||
|
@ -60,8 +60,6 @@ protected:
|
||||
void server_process(NETWORKTASK *task) const;
|
||||
|
||||
private:
|
||||
void set_tracing(TASK *Task);
|
||||
|
||||
std::mutex mutex;
|
||||
std::map<std::string, RPCService *> service_map;
|
||||
RPCModule *modules[SRPC_MODULE_MAX] = { NULL };
|
||||
|
@ -493,7 +493,8 @@ bool RPCClientTask<RPCREQ, RPCRESP>::finish_once()
|
||||
if (!modules_.empty())
|
||||
{
|
||||
RPCModuleData resp_data;
|
||||
this->resp.get_meta_module_data(resp_data);
|
||||
//TODO: Fill some resp meta to client task
|
||||
//this->resp.get_meta_module_data(resp_data);
|
||||
for (auto *module : modules_)
|
||||
module->client_task_end(this, resp_data);
|
||||
}
|
||||
|
@ -284,10 +284,9 @@ static void basic_default_file_initialize(DEFAULT_FILES& files)
|
||||
files.push_back(info);
|
||||
}
|
||||
|
||||
static bool basic_get_opt(int argc, const char **argv, struct srpc_config *config)
|
||||
static bool get_opt_args(int argc, const char **argv, struct srpc_config *config)
|
||||
{
|
||||
char c;
|
||||
optind = 3;
|
||||
|
||||
while ((c = getopt(argc, (char * const *)argv, "o:t:d:")) != -1)
|
||||
{
|
||||
@ -317,6 +316,34 @@ static bool basic_get_opt(int argc, const char **argv, struct srpc_config *confi
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool basic_get_opt(int argc, const char **argv, struct srpc_config *config)
|
||||
{
|
||||
optind = 2;
|
||||
|
||||
if (get_opt_args(argc, argv, config) == false)
|
||||
return false;
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
config->project_name = argv[optind];
|
||||
optind++;
|
||||
|
||||
if (get_opt_args(argc, argv, config) == false)
|
||||
return false;
|
||||
|
||||
if (config->project_name == NULL)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void basic_print_usage(const char *name, const char *command)
|
||||
{
|
||||
printf(COLOR_PINK"Usage:\n"
|
||||
@ -423,7 +450,7 @@ bool FileServiceController::get_opt(int argc, const char **argv)
|
||||
void FileServiceController::print_success_info() const
|
||||
{
|
||||
printf(COLOR_GREEN"Success:\n make project path "
|
||||
COLOR_BLUE"\" %s \"" COLOR_GREEN " done.\n\n",
|
||||
COLOR_BLUE"\" %s \"" COLOR_GREEN "done.\n\n",
|
||||
this->config.output_path);
|
||||
printf(COLOR_PINK"Commands:\n " COLOR_BLUE "cd %s\n make -j\n\n",
|
||||
this->config.output_path);
|
||||
|
@ -89,6 +89,8 @@ static int check_file_idl_type(const char *filename)
|
||||
|
||||
srpc_config::srpc_config()
|
||||
{
|
||||
project_name = NULL;
|
||||
service_name = NULL;
|
||||
rpc_type = PROTOCOL_TYPE_SRPC;
|
||||
idl_type = IDL_TYPE_DEFAULT;
|
||||
data_type = DATA_TYPE_DEFAULT;
|
||||
@ -104,25 +106,32 @@ bool srpc_config::prepare_specified_idl_file()
|
||||
{
|
||||
if (this->specified_idl_path != NULL)
|
||||
{
|
||||
printf("Error:\n idl_path is specified but NO idl_file.\n\n");
|
||||
printf(COLOR_RED"Error:\n idl_path is specified "
|
||||
"but NO idl_file.\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (this->service_name != NULL)
|
||||
{
|
||||
printf(COLOR_RED"Error:\n [-s service_name] does NOT take effect "
|
||||
"when idl_file is specified.\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->idl_type = check_file_idl_type(this->specified_idl_file);
|
||||
if (this->idl_type == IDL_TYPE_MAX)
|
||||
{
|
||||
printf("Error:\n Invalid idl type. file : \" %s \"\n\n",
|
||||
this->specified_idl_file);
|
||||
printf(COLOR_RED"Error:\n Invalid idl type. file :" COLOR_BLUE
|
||||
" %s\n\n" COLOR_OFF, this->specified_idl_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (access(this->specified_idl_file, F_OK) != 0)
|
||||
{
|
||||
printf("Error:\n idl_file \" %s \" does NOT exist.\n\n",
|
||||
this->specified_idl_file);
|
||||
printf(COLOR_RED"Error:\n idl_file" COLOR_BLUE " %s " COLOR_RED
|
||||
"does NOT exist.\n\n" COLOR_OFF, this->specified_idl_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,20 @@
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#define COLOR_OFF "\033[0m"
|
||||
#define COLOR_WHITE "\033[37;1m"
|
||||
#define COLOR_RED "\033[31;1m"
|
||||
#define COLOR_GREEN "\033[32;1m"
|
||||
#define COLOR_YELLOW "\033[33;1m"
|
||||
#define COLOR_PURPLE "\033[34;1m"
|
||||
#define COLOR_PINK "\033[35;1m"
|
||||
#define COLOR_BLUE "\033[36;1m"
|
||||
#define COLOR_LPURPLE "\033[94;1m"
|
||||
|
||||
#define COLOR_COMMAND COLOR_BLUE
|
||||
#define COLOR_INFO COLOR_YELLOW
|
||||
#define COLOR_FLAG COLOR_PURPLE
|
||||
|
||||
struct srpc_config
|
||||
{
|
||||
uint8_t type;
|
||||
|
@ -235,8 +235,7 @@ bool CommandController::parse_args(int argc, const char **argv)
|
||||
}
|
||||
|
||||
memset(this->config.output_path, 0, MAXPATHLEN);
|
||||
this->config.project_name = argv[2];
|
||||
this->config.service_name = argv[2];
|
||||
|
||||
if (get_path(__FILE__, this->config.depend_path, 2) == false)
|
||||
return false;
|
||||
|
||||
@ -257,12 +256,6 @@ bool CommandController::parse_args(int argc, const char **argv)
|
||||
|
||||
bool CommandController::check_args()
|
||||
{
|
||||
if (*(this->config.project_name) == '-')
|
||||
{
|
||||
printf(COLOR_RED "Error: Invalid PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t path_len = strlen(this->config.output_path);
|
||||
|
||||
if (strlen(this->config.project_name) >= MAXPATHLEN - path_len - 2)
|
||||
|
@ -19,20 +19,6 @@
|
||||
|
||||
#include "srpc_config.h"
|
||||
|
||||
#define COLOR_OFF "\033[0m"
|
||||
#define COLOR_WHITE "\033[37;1m"
|
||||
#define COLOR_RED "\033[31;1m"
|
||||
#define COLOR_GREEN "\033[32;1m"
|
||||
#define COLOR_YELLOW "\033[33;1m"
|
||||
#define COLOR_PURPLE "\033[34;1m"
|
||||
#define COLOR_PINK "\033[35;1m"
|
||||
#define COLOR_BLUE "\033[36;1m"
|
||||
#define COLOR_LPURPLE "\033[94;1m"
|
||||
|
||||
#define COLOR_COMMAND COLOR_BLUE
|
||||
#define COLOR_INFO COLOR_YELLOW
|
||||
#define COLOR_FLAG COLOR_PURPLE
|
||||
|
||||
class CommandController
|
||||
{
|
||||
public:
|
||||
@ -123,9 +109,6 @@ public:
|
||||
void print_usage(const char *name) const override;
|
||||
void print_success_info() const override;
|
||||
|
||||
protected:
|
||||
bool check_args() override;
|
||||
|
||||
private:
|
||||
bool get_opt(int argc, const char **argv) override;
|
||||
|
||||
|
@ -336,11 +336,9 @@ static uint8_t proxy_string_to_type(const char *type)
|
||||
return PROTOCOL_TYPE_MAX;
|
||||
}
|
||||
|
||||
bool ProxyController::get_opt(int argc, const char **argv)
|
||||
static bool proxy_get_opt(int argc, const char **argv, struct srpc_config *config)
|
||||
{
|
||||
struct srpc_config *config = &this->config;
|
||||
char c;
|
||||
optind = 3;
|
||||
|
||||
while ((c = getopt(argc, (char * const *)argv, "o:c:s:d:")) != -1)
|
||||
{
|
||||
@ -372,6 +370,35 @@ bool ProxyController::get_opt(int argc, const char **argv)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProxyController::get_opt(int argc, const char **argv)
|
||||
{
|
||||
optind = 2;
|
||||
getcwd(this->config.output_path, MAXPATHLEN);
|
||||
|
||||
if (proxy_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->config.project_name = argv[optind];
|
||||
optind++;
|
||||
|
||||
if (proxy_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (this->config.project_name == NULL)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProxyController::check_args()
|
||||
{
|
||||
int server_type = check_proxy_type(this->config.proxy_server_type);
|
||||
|
@ -54,6 +54,9 @@ RPCController::RPCController()
|
||||
|
||||
info = { "config/config_full.cc", "config/config.cc", nullptr };
|
||||
this->default_files.push_back(info);
|
||||
|
||||
info = { "common/config.json", "full.conf", nullptr };
|
||||
this->default_files.push_back(info);
|
||||
}
|
||||
|
||||
void RPCController::print_usage(const char *name) const
|
||||
@ -137,11 +140,9 @@ bool RPCController::copy_files()
|
||||
return CommandController::copy_files();
|
||||
}
|
||||
|
||||
bool RPCController::get_opt(int argc, const char **argv)
|
||||
static bool rpc_get_opt(int argc, const char **argv, struct srpc_config *config)
|
||||
{
|
||||
struct srpc_config *config = &this->config;
|
||||
char c;
|
||||
optind = 3;
|
||||
|
||||
while ((c = getopt(argc, (char * const *)argv,
|
||||
"o:r:i:x:c:s:d:f:p:")) != -1)
|
||||
@ -189,6 +190,37 @@ bool RPCController::get_opt(int argc, const char **argv)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RPCController::get_opt(int argc, const char **argv)
|
||||
{
|
||||
optind = 2;
|
||||
|
||||
if (rpc_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->config.project_name = argv[optind];
|
||||
optind++;
|
||||
|
||||
if (rpc_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (this->config.project_name == NULL)
|
||||
{
|
||||
printf(COLOR_RED "Missing: PROJECT_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->config.service_name == NULL)
|
||||
this->config.service_name = this->config.project_name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RPCController::check_args()
|
||||
{
|
||||
if (CommandController::check_args() == false)
|
||||
@ -201,7 +233,7 @@ bool RPCController::check_args()
|
||||
config->data_type == DATA_TYPE_MAX ||
|
||||
config->compress_type == COMPRESS_TYPE_MAX)
|
||||
{
|
||||
printf(COLOR_RED"Error:\n Invalid rpc args.\n" COLOR_OFF);
|
||||
printf(COLOR_RED"Error:\n Invalid rpc args : -r | -i | -c | -d .\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -214,7 +246,7 @@ bool RPCController::check_args()
|
||||
{
|
||||
printf(COLOR_RED"Error:\n "
|
||||
COLOR_BLUE"\" %s \" "
|
||||
COLOR_RED"does NOT support protobuf as idl or data type.\n" COLOR_OFF,
|
||||
COLOR_RED"does NOT support protobuf as idl or data type.\n\n" COLOR_OFF,
|
||||
config->rpc_type_string());
|
||||
return false;
|
||||
}
|
||||
@ -266,24 +298,21 @@ void APIController::print_usage(const char *name) const
|
||||
COLOR_OFF, name, name);
|
||||
}
|
||||
|
||||
bool APIController::get_opt(int argc, const char **argv)
|
||||
static bool api_get_opt(int argc, const char **argv, struct srpc_config *config)
|
||||
{
|
||||
char c;
|
||||
optind = 3;
|
||||
|
||||
getcwd(this->config.output_path, MAXPATHLEN);
|
||||
|
||||
while ((c = getopt(argc, (char * const *)argv, "o:i:")) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'o':
|
||||
memset(this->config.output_path, 0, MAXPATHLEN);
|
||||
if (sscanf(optarg, "%s", this->config.output_path) != 1)
|
||||
memset(config->output_path, 0, MAXPATHLEN);
|
||||
if (sscanf(optarg, "%s", config->output_path) != 1)
|
||||
return false;
|
||||
break;
|
||||
case 'i':
|
||||
this->config.set_idl_type(optarg);
|
||||
config->set_idl_type(optarg);
|
||||
break;
|
||||
default:
|
||||
printf(COLOR_RED "Error:\n Unknown args : "
|
||||
@ -295,11 +324,29 @@ bool APIController::get_opt(int argc, const char **argv)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool APIController::check_args()
|
||||
bool APIController::get_opt(int argc, const char **argv)
|
||||
{
|
||||
if (*(this->config.project_name) == '-')
|
||||
optind = 2;
|
||||
getcwd(this->config.output_path, MAXPATHLEN);
|
||||
|
||||
if (api_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
printf(COLOR_RED "Error: Invalid FILE_NAME\n\n" COLOR_OFF);
|
||||
printf(COLOR_RED "Missing: FILE_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->config.project_name = argv[optind];
|
||||
optind++;
|
||||
|
||||
if (api_get_opt(argc, argv, &this->config) == false)
|
||||
return false;
|
||||
|
||||
if (this->config.project_name == NULL)
|
||||
{
|
||||
printf(COLOR_RED "Missing: FILE_NAME\n\n" COLOR_OFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ static void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGTERM, sig_handler);
|
||||
|
||||
@ -59,7 +58,6 @@ int main()
|
||||
else
|
||||
perror("server start");
|
||||
|
||||
google::protobuf::ShutdownProtobufLibrary();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user