create api controller command,not complete yet
This commit is contained in:
parent
f992c02673
commit
3f69aafec8
|
@ -150,7 +150,45 @@ void create_controller::newSimpleControllerSourceFile(std::ofstream &file,const
|
|||
file<<" //write your application logic here\n";
|
||||
file<<"}";
|
||||
}
|
||||
void create_controller::createApiController(std::vector<std::string> &apiPaths)
|
||||
void create_controller::createApiController(std::vector<std::string> &apiClasses)
|
||||
{
|
||||
for(auto iter=apiClasses.begin();iter!=apiClasses.end();iter++)
|
||||
{
|
||||
if ((*iter)[0] == '-')
|
||||
{
|
||||
std::cout<<ARGS_ERROR_STR<<std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(auto className:apiClasses)
|
||||
{
|
||||
createApiController(className);
|
||||
}
|
||||
}
|
||||
void create_controller::createApiController(const std::string &className)
|
||||
{
|
||||
std::string ctlName=className;
|
||||
auto pos=ctlName.rfind("::");
|
||||
if(pos!=std::string::npos)
|
||||
{
|
||||
ctlName=ctlName.substr(pos+2);
|
||||
}
|
||||
std::cout<<"create api controller:"<<className<<std::endl;
|
||||
std::string headFileName=ctlName+".h";
|
||||
std::string sourceFilename=ctlName+".cc";
|
||||
std::ofstream oHeadFile(headFileName.c_str(),std::ofstream::out);
|
||||
std::ofstream oSourceFile(sourceFilename.c_str(),std::ofstream::out);
|
||||
if(!oHeadFile||!oSourceFile)
|
||||
return;
|
||||
newApiControllerHeaderFile(oHeadFile,className);
|
||||
newApiControllerSourceFile(oSourceFile,className);
|
||||
}
|
||||
|
||||
void create_controller::newApiControllerHeaderFile(std::ofstream &file,const std::string &className)
|
||||
{
|
||||
|
||||
}
|
||||
void create_controller::newApiControllerSourceFile(std::ofstream &file,const std::string &className)
|
||||
{
|
||||
|
||||
}
|
|
@ -32,8 +32,12 @@ namespace drogon_ctl
|
|||
};
|
||||
void createSimpleController(std::vector<std::string> &ctlNames,const std::string &namespaceName="");
|
||||
void createSimpleController(const std::string &ctlName,const std::string &namespaceName="");
|
||||
void createApiController(std::vector<std::string> &apiPaths);
|
||||
void createApiController(std::vector<std::string> &apiClasses);
|
||||
void createApiController(const std::string &className);
|
||||
void newSimpleControllerHeaderFile(std::ofstream &file,const std::string &ctlName,const std::string &namespaceName="");
|
||||
void newSimpleControllerSourceFile(std::ofstream &file,const std::string &ctlName,const std::string &namespaceName="");
|
||||
void newApiControllerHeaderFile(std::ofstream &file,const std::string &className);
|
||||
void newApiControllerSourceFile(std::ofstream &file,const std::string &className);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -70,12 +70,12 @@ int main()
|
|||
|
||||
B b;
|
||||
//functor
|
||||
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle3","",b);
|
||||
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle3","/{1}/{2}",b);
|
||||
|
||||
A tmp;
|
||||
std::function<void(const HttpRequest&,const std::function<void (HttpResponse &)>&,int,const std::string &,const std::string &,int)>
|
||||
func=std::bind(&A::handle,&tmp,_1,_2,_3,_4,_5,_6);
|
||||
//std::function
|
||||
//api example for std::function
|
||||
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle4","",func);
|
||||
LOG_DEBUG<<drogon::DrObjectBase::demangle(typeid(func).name());
|
||||
drogon::HttpAppFramework::instance().run();
|
||||
|
|
|
@ -68,34 +68,12 @@ namespace drogon
|
|||
{
|
||||
HttpApiBinderBasePtr binder;
|
||||
|
||||
if(std::is_bind_expression<FUNCTION>::value)
|
||||
{
|
||||
//out of std::bind
|
||||
// typedef decltype(&std::remove_reference<FUNCTION>::type::operator ()) OperType;
|
||||
// binder=std::make_shared<
|
||||
// HttpApiBinder<OperType>
|
||||
// >(std::forward<FUNCTION>(function));
|
||||
}
|
||||
else
|
||||
{
|
||||
binder=std::make_shared<
|
||||
HttpApiBinder<FUNCTION>
|
||||
>(std::forward<FUNCTION>(function));
|
||||
}
|
||||
binder=std::make_shared<
|
||||
HttpApiBinder<FUNCTION>
|
||||
>(std::forward<FUNCTION>(function));
|
||||
|
||||
instance().registerHttpApiController(pathName,parameterPattern,binder,filters);
|
||||
}
|
||||
// template <typename FUNCTION>
|
||||
// static void registerHttpApiBind(const std::string &pathName,
|
||||
// const std::string ¶meterPattern,
|
||||
// const std::function<FUNCTION> & function,
|
||||
// const std::vector<std::string> &filters=std::vector<std::string>())
|
||||
// {
|
||||
// HttpApiBinderBasePtr binder=std::make_shared<
|
||||
// HttpApiBinder<decltype(function)>
|
||||
// >(std::forward<decltype(function)>(function));
|
||||
// instance().registerHttpApiController(pathName,parameterPattern,binder,filters);
|
||||
// }
|
||||
virtual void enableSession(const size_t timeout=0)=0;
|
||||
virtual void disableSession()=0;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue