File: TestController.h

package info (click to toggle)
drogon 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,096 kB
  • sloc: cpp: 52,222; sh: 249; xml: 20; makefile: 11
file content (43 lines) | stat: -rw-r--r-- 1,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <drogon/HttpSimpleController.h>
#include <drogon/IOThreadStorage.h>
#include <drogon/utils/monitoring/Counter.h>
#include <drogon/utils/monitoring/Collector.h>
#include <drogon/plugins/PromExporter.h>
using namespace drogon;

namespace example
{
class TestController : public drogon::HttpSimpleController<TestController>
{
  public:
    virtual void asyncHandleHttpRequest(
        const HttpRequestPtr &req,
        std::function<void(const HttpResponsePtr &)> &&callback) override;
    PATH_LIST_BEGIN
    // list path definations here;
    // PATH_ADD("/path","filter1","filter2",...);
    PATH_ADD("/", Get);
    PATH_ADD("/Test", "nonFilter");
    PATH_ADD("/tpost", Post, Options);
    PATH_ADD("/slow", "TimeFilter", Get);

    PATH_LIST_END
    TestController()
    {
        LOG_DEBUG << "TestController constructor";
        auto collector = std::make_shared<
            drogon::monitoring::Collector<drogon::monitoring::Counter>>(
            "test_counter",
            "The counter for requests to the root url",
            std::vector<std::string>());
        counter_ = collector->metric(std::vector<std::string>());
        collector->registerTo(
            *app().getSharedPlugin<drogon::plugin::PromExporter>());
    }

  private:
    drogon::IOThreadStorage<int> threadIndex_;
    std::shared_ptr<drogon::monitoring::Counter> counter_;
};
}  // namespace example