add TestController in example

This commit is contained in:
an-tao 2018-05-14 16:57:40 +08:00
parent 584d90beaf
commit d1f8b43833
4 changed files with 31 additions and 25 deletions

View File

@ -0,0 +1,12 @@
#include "TestController.h"
void TestController::asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)
{
std::unique_ptr<HttpResponse> resp=std::unique_ptr<HttpResponse>(HttpResponse::newHttpResponse());
LOG_DEBUG<<"!!!!!!!!!!1";
resp->setStatusCode(HttpResponse::k200Ok);
resp->setContentTypeCode(CT_TEXT_HTML);
resp->setBody("hello!!!");
callback(*resp);
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <drogon/HttpSimpleController.h>
using namespace drogon;
class TestController:public drogon::HttpSimpleController<TestController>
{
public:
//TestController(){}
virtual void asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)override;
void ttt(){}
PATH_LIST_BEGIN
PATH_ADD("/");
PATH_ADD("/Test","nonFilter");
PATH_ADD("/tpost","drogon::PostFilter");
PATH_LIST_END
};

View File

@ -19,28 +19,6 @@ public:
// HHH(){std::cout<<"class HHH constr,name="<<className()<<std::endl;}
};
class TestController:public drogon::HttpSimpleController<TestController>
{
public:
TestController(){}
virtual void asyncHandleHttpRequest(const HttpRequest& req,std::function<void (HttpResponse &)>callback)override
{
std::unique_ptr<HttpResponse> resp=std::unique_ptr<HttpResponse>(HttpResponse::newHttpResponse());
LOG_DEBUG<<"!!!!!!!!!!1";
resp->setStatusCode(HttpResponse::k200Ok);
resp->setContentTypeCode(CT_TEXT_HTML);
resp->setBody("hello!!!");
callback(*resp);
}
void ttt(){}
PATH_LIST_BEGIN
PATH_ADD("/");
PATH_ADD("/Test","nonFilter");
PATH_ADD("/tpost","drogon::PostFilter");
PATH_LIST_END
};
@ -48,9 +26,6 @@ public:
int main()
{
//drogon::DrObjectBase *p=drogon::DrClassMap::newObject("HHH");
//TestController haha;
//std::cout<<haha.good()<<std::endl;
std::cout<<banner<<std::endl;
drogon::HttpAppFramework::instance().setListening("0.0.0.0",12345);

View File

@ -8,6 +8,7 @@
#include <drogon/DrObject.h>
#include <drogon/HttpAppFramework.h>
#include <trantor/utils/Logger.h>
#include <string>
#include <vector>
#include <iostream>