未验证 提交 86dd5e36 编写于 作者: W Wang XiangYu 提交者: GitHub

cmd case insensitive (#3042)

Signed-off-by: Nwxyu <xy.wang@zilliz.com>
上级 34309709
......@@ -16,6 +16,8 @@
#include "utils/Log.h"
#include "utils/TimeRecorder.h"
#include <algorithm>
#include <cctype>
#include <memory>
#include <vector>
......@@ -23,7 +25,7 @@ namespace milvus {
namespace server {
CmdReq::CmdReq(const std::shared_ptr<milvus::server::Context>& context, const std::string& cmd, std::string& result)
: BaseReq(context, BaseReq::kCmd), cmd_(cmd), result_(result) {
: BaseReq(context, BaseReq::kCmd), origin_cmd_(cmd), cmd_(tolower(cmd)), result_(result) {
}
BaseReqPtr
......@@ -54,14 +56,9 @@ CmdReq::OnExecute() {
sys_info_inst.GetSysInfoJsonStr(result_);
} else if (cmd_ == "build_commit_id") {
result_ = LAST_COMMIT_ID;
} else if (cmd_.substr(0, 3) == "GET") {
} else if (cmd_.substr(0, 3) == "get") {
try {
std::stringstream ss(cmd_);
std::vector<std::string> words;
std::string word;
while (std::getline(ss, word, ' ')) {
words.push_back(word);
}
auto words = split(cmd_, ' ');
if (words.size() == 2) {
result_ = ConfigMgr::GetInstance().Get(words[1]);
}
......@@ -70,14 +67,9 @@ CmdReq::OnExecute() {
} catch (...) {
stat = Status(SERVER_UNEXPECTED_ERROR, "Unknown exception happened on GET command.");
}
} else if (cmd_.substr(0, 3) == "SET") {
} else if (cmd_.substr(0, 3) == "set") {
try {
std::stringstream ss(cmd_);
std::vector<std::string> words;
std::string word;
while (std::getline(ss, word, ' ')) {
words.push_back(word);
}
auto words = split(cmd_, ' ');
if (words.size() == 3) {
ConfigMgr::GetInstance().Set(words[1], words[2]);
}
......@@ -93,5 +85,22 @@ CmdReq::OnExecute() {
return stat;
}
std::vector<std::string>
CmdReq::split(const std::string& src, char delimiter) {
std::stringstream ss(src);
std::vector<std::string> words;
std::string word;
while (std::getline(ss, word, delimiter)) {
words.push_back(word);
}
return words;
}
std::string
CmdReq::tolower(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
return s;
}
} // namespace server
} // namespace milvus
......@@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include <vector>
namespace milvus {
namespace server {
......@@ -31,6 +32,14 @@ class CmdReq : public BaseReq {
OnExecute() override;
private:
static std::vector<std::string>
split(const std::string& src, char delimiter);
static std::string
tolower(std::string s);
private:
const std::string origin_cmd_;
const std::string cmd_;
std::string& result_;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册