mirror of
https://github.com/laomms/wxhelper.git
synced 2024-12-22 15:59:23 +08:00
43 lines
939 B
C++
43 lines
939 B
C++
|
|
#ifndef WXHELPER_HTTP_CONTROLLER_H_
|
|
#define WXHELPER_HTTP_CONTROLLER_H_
|
|
|
|
#include "http_router.h"
|
|
#include "singleton.h"
|
|
namespace http {
|
|
#define PATHS_BEGIN static void AddPath() {
|
|
#define ADD_PATH(path, method) RegisterPath(path, &method)
|
|
#define PATHS_END }
|
|
|
|
class BaseHttpController {
|
|
public:
|
|
virtual ~BaseHttpController() {}
|
|
};
|
|
|
|
template <typename T>
|
|
class HttpController : public base::Singleton<T>{
|
|
public:
|
|
virtual ~HttpController() {}
|
|
|
|
protected:
|
|
HttpController() {}
|
|
|
|
static void RegisterPath(const std::string &path, HttpHandler function) {
|
|
HttpRouter::GetInstance().AddPathRouting(path, function);
|
|
}
|
|
|
|
private:
|
|
struct Registrator {
|
|
public:
|
|
Registrator() { T::AddPath(); }
|
|
};
|
|
|
|
static Registrator registrator_;
|
|
virtual void *GetRegistrator() { return ®istrator_; }
|
|
};
|
|
|
|
template <typename T>
|
|
typename HttpController<T>::Registrator HttpController<T>::registrator_;
|
|
} // namespace http
|
|
#endif
|