-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.h
More file actions
30 lines (25 loc) · 799 Bytes
/
response.h
File metadata and controls
30 lines (25 loc) · 799 Bytes
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
#ifndef RESPONSE_H
#define RESPONSE_H
#include <string>
#include <functional>
#include "Poco/JSON/Object.h"
template <typename T>
std::string responseFormat(int success, int code, const std::string& msg, T&& data) {
Poco::JSON::Object jres;
jres.set("success", success);
jres.set("code", code);
jres.set("message", msg);
jres.set("data", std::forward<T>(data));
std::stringstream jsnString;
jres.stringify( jsnString, 3 );
return jsnString.str();
}
template <typename T>
std::string responseSuccess(T&& data) {
return responseFormat(1, 0, "success", std::forward<T>(data));
}
template <typename T>
std::string responseError(int code, const std::string& msg, T&& data) {
return responseFormat(0, code, msg, std::forward<T>(data));
}
#endif // RESPONSE_H