mirror of
https://github.com/drogonframework/drogon.git
synced 2025-06-24 00:00:43 -04:00
Compare commits
717 Commits
v1.0.0-bet
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
a22956b82b | ||
|
3c5749bbc2 | ||
|
7cd1ae8940 | ||
|
c3f9192541 | ||
|
e46e05e94a | ||
|
26e7c6913c | ||
|
8d640bafb4 | ||
|
f6b5404dbb | ||
|
46b5c9044d | ||
|
ac0d4d0f89 | ||
|
5c4057331e | ||
|
95a518e7f2 | ||
|
c03a3df106 | ||
|
d6a33f93c9 | ||
|
59cd4366c7 | ||
|
c92d146374 | ||
|
3c7c66e310 | ||
|
1fb67d68be | ||
|
cbf63f8fc4 | ||
|
d68e8aa554 | ||
|
41537a6e86 | ||
|
a32dc67867 | ||
|
e155df9f66 | ||
|
f5de41f5d7 | ||
|
a3b4779540 | ||
|
686f68a12f | ||
|
152a69f1e9 | ||
|
38dd5fea31 | ||
|
3a6268f7e9 | ||
|
47f8af7ca1 | ||
|
44f796b796 | ||
|
df7e83ae74 | ||
|
99e816283d | ||
|
3e944d28d8 | ||
|
1765223755 | ||
|
71b6d57cae | ||
|
882c1d9ecd | ||
|
8541e67143 | ||
|
6d9ecb8d8d | ||
|
23c561f072 | ||
|
284d14b8ca | ||
|
ca2210331d | ||
|
3fce70b535 | ||
|
bf1fc03bff | ||
|
5225bb3295 | ||
|
ac0a1b873e | ||
|
912f1d803c | ||
|
13d7148764 | ||
|
b0c5331bc1 | ||
|
c9f5754423 | ||
|
31fb18fb46 | ||
|
f918ead0ae | ||
|
fee34095a2 | ||
|
2911a7c08a | ||
|
1b4653577f | ||
|
bbcad71458 | ||
|
beec858eba | ||
|
93d8fb425d | ||
|
73406d1225 | ||
|
6bafdf30fd | ||
|
59919f33ef | ||
|
1326205483 | ||
|
80ec7d9211 | ||
|
5b5d1906bf | ||
|
206ef0d881 | ||
|
c46f149c2c | ||
|
0546032edc | ||
|
f743cfd4d1 | ||
|
500d44faac | ||
|
e786907478 | ||
|
5d4523a3a6 | ||
|
dfacd1b454 | ||
|
85b918f9e9 | ||
|
7b8d0085b1 | ||
|
f6913f6328 | ||
|
a2f759e4cd | ||
|
ad2b7e13e1 | ||
|
b04dfd7f96 | ||
|
de5a4a5f57 | ||
|
8bdb9b2fa6 | ||
|
0a889e921d | ||
|
9a96a20c6e | ||
|
f37a1d036f | ||
|
c4c95918bf | ||
|
6726df139d | ||
|
150735848d | ||
|
155ae9ad65 | ||
|
306df8a8fb | ||
|
82c46f13f8 | ||
|
5f75222243 | ||
|
5b7cefd32c | ||
|
abbcf6023d | ||
|
b5cd748a12 | ||
|
439ddd8dbe | ||
|
e79d5170b4 | ||
|
519398c159 | ||
|
96919df488 | ||
|
294035beb9 | ||
|
46ac53adb3 | ||
|
9f2872639a | ||
|
4cbac301fb | ||
|
88d06684f2 | ||
|
da7f065a6f | ||
|
aa04d33e02 | ||
|
1a9ad1a2c9 | ||
|
22f4b4fad6 | ||
|
99d97df25f | ||
|
6aed658fab | ||
|
3d469112ca | ||
|
f63480674f | ||
|
0d178877f0 | ||
|
5f273d8744 | ||
|
3c8c273582 | ||
|
c2b8e7c624 | ||
|
56a53165b6 | ||
|
674137e89d | ||
|
ffc6e74f27 | ||
|
359b63fa77 | ||
|
baea2dce47 | ||
|
cca1c8f262 | ||
|
aeed963915 | ||
|
e640cc092d | ||
|
93c568bb95 | ||
|
af29e25b03 | ||
|
d745cfe765 | ||
|
6b36b3a4f9 | ||
|
8e4ffa71e2 | ||
|
25f874a278 | ||
|
5ecbd1f184 | ||
|
34d32a1ef0 | ||
|
1fd5c7ea5e | ||
|
2a0da80d5f | ||
|
01ad18d2d5 | ||
|
f4443dce44 | ||
|
021c89ec78 | ||
|
125dd0e69e | ||
|
38bde80aaa | ||
|
4eec56c49f | ||
|
ba9e9731d2 | ||
|
41b740f649 | ||
|
e76bf08eb2 | ||
|
c35e62ccd2 | ||
|
358de6e66f | ||
|
8026790e1a | ||
|
4e890f52d6 | ||
|
27f1a3d812 | ||
|
6370461896 | ||
|
6b20a9fa8d | ||
|
830ced8c5b | ||
|
6f6a03b14b | ||
|
f21b899e63 | ||
|
26840aa056 | ||
|
01385f4f33 | ||
|
2000a4279e | ||
|
1ec3c96cbb | ||
|
56f0102cfe | ||
|
a76c11cc34 | ||
|
e5daba6bf5 | ||
|
8586874c87 | ||
|
f215cb15a0 | ||
|
7599ae98a0 | ||
|
4323e7b6ef | ||
|
9ffe1b267b | ||
|
645c2d8aaf | ||
|
ab76e80089 | ||
|
d9afdf279a | ||
|
1efe89a719 | ||
|
fd7af8110f | ||
|
63b7f5eb13 | ||
|
94ca651cbd | ||
|
6cb8ac6f52 | ||
|
078f60ca03 | ||
|
cfa0de4389 | ||
|
112d19ff12 | ||
|
cedeeb59f4 | ||
|
4e5638fdcd | ||
|
e2e5d6d57f | ||
|
53c84305b2 | ||
|
85d7c068e4 | ||
|
5d0c70278e | ||
|
366311c196 | ||
|
5df9b48998 | ||
|
8d4c17702a | ||
|
9337571e1a | ||
|
816684e15d | ||
|
40aa034595 | ||
|
de4c811772 | ||
|
3ecb8b4917 | ||
|
f761c54aa8 | ||
|
58055ae39c | ||
|
bc4d740b0c | ||
|
f8f5283dff | ||
|
54b137d64f | ||
|
40579ae308 | ||
|
81bf767d89 | ||
|
f1426c6e9a | ||
|
17c80508c0 | ||
|
f361995035 | ||
|
3723ed5e0c | ||
|
83e08f4b27 | ||
|
3aa93e62e7 | ||
|
5c43b82dc2 | ||
|
4c44322221 | ||
|
47e700c77f | ||
|
a122725c3b | ||
|
5509091ab8 | ||
|
43b014cc24 | ||
|
4ad68db5e2 | ||
|
d3dbaed60a | ||
|
d7ae3a21b3 | ||
|
3fa480dd87 | ||
|
56f620717e | ||
|
ad99cf724d | ||
|
a91014a982 | ||
|
9b2716ec24 | ||
|
d00222883f | ||
|
0fb887cb07 | ||
|
f16017ee6e | ||
|
ec5dfdd9f7 | ||
|
8f37e526cc | ||
|
c1da9922eb | ||
|
ca92e32d55 | ||
|
cca5e5badd | ||
|
92e036874a | ||
|
cb2ae14bdf | ||
|
34a5c37974 | ||
|
3c82dcb491 | ||
|
6dbe650c74 | ||
|
74bb47c690 | ||
|
61073b4f74 | ||
|
eea916315e | ||
|
8e4474bf4c | ||
|
269399b701 | ||
|
586fd6d67a | ||
|
44b6916d7e | ||
|
7f04e63f25 | ||
|
5e245d08dc | ||
|
b9a699f866 | ||
|
3263b78ec3 | ||
|
07726dfcab | ||
|
415b34e06d | ||
|
75b106599d | ||
|
7fce0f1ff5 | ||
|
87a3132fd1 | ||
|
abf6f6cc86 | ||
|
bd66fa4f55 | ||
|
5baca75359 | ||
|
29984f26e0 | ||
|
fddbc0abb7 | ||
|
bf4ff759ad | ||
|
42bbc185e1 | ||
|
8b250f8638 | ||
|
178fb22b49 | ||
|
2caa8c4a34 | ||
|
4ec75e03e0 | ||
|
22c7567da3 | ||
|
f615d5e8df | ||
|
f14ba8de28 | ||
|
7c96c7fbf5 | ||
|
65b1715539 | ||
|
4358b71f55 | ||
|
c7912f246b | ||
|
d133b21804 | ||
|
ad2798e4aa | ||
|
abee656699 | ||
|
292d677446 | ||
|
0715a94a06 | ||
|
5df4db96a5 | ||
|
122a42cd4f | ||
|
120aaf249d | ||
|
f0a011b14d | ||
|
e25a162887 | ||
|
02742e4518 | ||
|
4f066258f2 | ||
|
ceab5f3037 | ||
|
21e207abe5 | ||
|
c63b021e7d | ||
|
2af8e47278 | ||
|
00debb056b | ||
|
af551bf2fb | ||
|
b229f74743 | ||
|
a039157587 | ||
|
97a5496fa4 | ||
|
314bab0b4c | ||
|
ab5259b290 | ||
|
d4c0e063f1 | ||
|
57ec87d38d | ||
|
b739a7fab8 | ||
|
394f9bd0d4 | ||
|
bc028776f7 | ||
|
d321bd4fc1 | ||
|
313392a9b6 | ||
|
29955becc1 | ||
|
54d96963f3 | ||
|
ae9d5f20b3 | ||
|
7d87d7e0b2 | ||
|
36d7435d1d | ||
|
479346822f | ||
|
3adf168a87 | ||
|
0b3147c157 | ||
|
007a6ffbe3 | ||
|
554939d7ee | ||
|
1618484d74 | ||
|
19f08786f0 | ||
|
80ea3c4f30 | ||
|
c5e596d942 | ||
|
28518b7bba | ||
|
1b11bfb668 | ||
|
ef93c91ec7 | ||
|
25ece89558 | ||
|
31fa010ca9 | ||
|
ab10d8cb22 | ||
|
c0d48da99f | ||
|
9dff8b296b | ||
|
990be54ea0 | ||
|
6208332de3 | ||
|
a8be56f9bb | ||
|
164972e2d3 | ||
|
37a10318ff | ||
|
29c67565a3 | ||
|
995b8e8b82 | ||
|
89588959b1 | ||
|
875bca0a86 | ||
|
4d63475203 | ||
|
cdd48686ab | ||
|
d3fe59432b | ||
|
1c8580a71b | ||
|
c913441bb4 | ||
|
302bb560b6 | ||
|
a1a0ef1af8 | ||
|
6a397efefe | ||
|
c97125b22f | ||
|
574a60f812 | ||
|
de1bd805fc | ||
|
ff1aac37de | ||
|
94c4f27d61 | ||
|
29b33a7fa0 | ||
|
c40bb2bc1f | ||
|
f582a16adb | ||
|
64b9484657 | ||
|
2465753ee9 | ||
|
bd9d290b82 | ||
|
4ef31d7c2d | ||
|
9abc9e5b6c | ||
|
5610bd2182 | ||
|
5371b967f6 | ||
|
2b75af82ee | ||
|
a1d2bd168b | ||
|
9f23560a29 | ||
|
bf36db1562 | ||
|
c9f5946eff | ||
|
82bd6bceac | ||
|
cfe1681b0f | ||
|
1bc6ee1170 | ||
|
a582a773c1 | ||
|
5373e51f92 | ||
|
474db0dd9a | ||
|
8b90403bae | ||
|
da18f21796 | ||
|
b32fa58d16 | ||
|
cf543716ce | ||
|
ee9ca895c7 | ||
|
9524a91479 | ||
|
b8f44aec2e | ||
|
e2b5a07921 | ||
|
46c00a317f | ||
|
81dd4ebd07 | ||
|
7570137138 | ||
|
a42f759248 | ||
|
3b5de8863a | ||
|
ebf87d69d7 | ||
|
664d97c185 | ||
|
346e2e6033 | ||
|
7af9853589 | ||
|
a4afc394dc | ||
|
3388c72343 | ||
|
8ab868ea22 | ||
|
bd4f3814a6 | ||
|
1bc38c7e22 | ||
|
fffb8f7e7c | ||
|
41d9d7ec58 | ||
|
3b11b80b10 | ||
|
cd55a198d2 | ||
|
3b0fd3d676 | ||
|
19d9ffcfc2 | ||
|
4f2cbd4135 | ||
|
c5a1888da3 | ||
|
f017b09947 | ||
|
e8b21502e2 | ||
|
a4ba8aff95 | ||
|
5892fa2f9f | ||
|
c9c2675ba9 | ||
|
bccf509ca0 | ||
|
86dbf9875b | ||
|
e53c81b229 | ||
|
d51bae1016 | ||
|
567e7c07ad | ||
|
8c4896dfec | ||
|
6971f84dae | ||
|
3d3daef3c5 | ||
|
740c34fce3 | ||
|
dd63a72dab | ||
|
b9bbe45642 | ||
|
b8a6188ad5 | ||
|
fc68b8c92c | ||
|
09a351d032 | ||
|
0e3ee5fad0 | ||
|
4b31f93767 | ||
|
3c785326c6 | ||
|
8ed0434ad8 | ||
|
26c8c0b527 | ||
|
92d39fb174 | ||
|
bbc31612fc | ||
|
bfb25a3765 | ||
|
88f4f090a8 | ||
|
68b2a46a29 | ||
|
e81662f29b | ||
|
29732a94ef | ||
|
e2842c9de5 | ||
|
720ce4e9ed | ||
|
9db332af65 | ||
|
6c8f8bac1f | ||
|
bc4e8faec2 | ||
|
52800006a0 | ||
|
03f34cb40b | ||
|
bba5253a0f | ||
|
080123ff96 | ||
|
6b677a3ff6 | ||
|
be3136ea26 | ||
|
719d50c0a7 | ||
|
754fd2da29 | ||
|
66e29dd9b2 | ||
|
7455355419 | ||
|
2a484536d1 | ||
|
6a55a3aa64 | ||
|
e9fafc643d | ||
|
1c44cf7e4c | ||
|
3ad9326e2a | ||
|
113d23494a | ||
|
7cf0a64ab6 | ||
|
8913abc400 | ||
|
d6b09c9e1b | ||
|
f522d2d70e | ||
|
bc18f56d57 | ||
|
7d137362bd | ||
|
6e6493299e | ||
|
faf3e0c17c | ||
|
ec8146774a | ||
|
895552dcae | ||
|
df331c8a74 | ||
|
953000e3fb | ||
|
e4ec2c36c5 | ||
|
29f2d431ab | ||
|
9e9bc7997e | ||
|
9448c19865 | ||
|
0431f38a4e | ||
|
7066b09edb | ||
|
dff4b6c5d9 | ||
|
e2eb674781 | ||
|
5a03c9aa9f | ||
|
a7f05c4214 | ||
|
0818384172 | ||
|
ac4a816a99 | ||
|
4a6f298661 | ||
|
3eb5bcd1dd | ||
|
22f810a71b | ||
|
fdcf294ef9 | ||
|
9b09abe274 | ||
|
c5effe9c51 | ||
|
8460249ab3 | ||
|
f49d71faba | ||
|
c9f98e1bf3 | ||
|
56cb305ae3 | ||
|
c7b6c8403f | ||
|
94c7add7a1 | ||
|
cdabca9de5 | ||
|
ba5187868d | ||
|
6b0e38fc8f | ||
|
30f06515fe | ||
|
b2bf247048 | ||
|
b68aeb43ae | ||
|
3620228843 | ||
|
133e6dc2ef | ||
|
588a7f0cd1 | ||
|
8049206b5f | ||
|
0783d6aa3e | ||
|
d60f962aa3 | ||
|
1551b66307 | ||
|
7e4174d537 | ||
|
b1bdc747c4 | ||
|
477c3dca7d | ||
|
88236f9279 | ||
|
6427fdedcc | ||
|
f46e3baeb1 | ||
|
0b9d114746 | ||
|
da87c124ae | ||
|
64f9f8b87f | ||
|
1c04b1a419 | ||
|
895ab63937 | ||
|
25cba9a2a5 | ||
|
629ae0bba1 | ||
|
dbfb99ccc8 | ||
|
35c2d123c0 | ||
|
991873cf60 | ||
|
c9035962fc | ||
|
5c1c81e828 | ||
|
5e8db234b9 | ||
|
d888816997 | ||
|
f87a6ca1b8 | ||
|
3b600232be | ||
|
a02d8e402c | ||
|
c5398b26cb | ||
|
0efd0c34c1 | ||
|
5245f136b7 | ||
|
0e7637daf6 | ||
|
04c7c7eb22 | ||
|
dbb51c1e6a | ||
|
b8d820fc2a | ||
|
065675486d | ||
|
6a882841f1 | ||
|
cd46b4a488 | ||
|
f84b709a61 | ||
|
a38d67aedb | ||
|
834e3eabdd | ||
|
a70a2844b1 | ||
|
e7ec973095 | ||
|
b22b7c6be3 | ||
|
945b26dc0c | ||
|
4abbf76214 | ||
|
6a3f72f2e5 | ||
|
b654e35e51 | ||
|
c6b65485e1 | ||
|
e1cbd1b987 | ||
|
ffc410a66e | ||
|
1bddbb117a | ||
|
802e2ae87a | ||
|
0b5075bfa9 | ||
|
afb7e853ec | ||
|
1e87c35b8f | ||
|
36fb3b3a40 | ||
|
65a7dadbfb | ||
|
dc732fc954 | ||
|
8052c38f49 | ||
|
3601992546 | ||
|
32970172f6 | ||
|
9a059aedef | ||
|
706fc70abc | ||
|
cd093fc97e | ||
|
08351ccf98 | ||
|
f736e12a05 | ||
|
63738bd578 | ||
|
74b3ca3db6 | ||
|
e478b63dda | ||
|
0e70be0a95 | ||
|
2c53cf086a | ||
|
471488eef1 | ||
|
f8e56d85dd | ||
|
6bfbf97eea | ||
|
f99c72bd5b | ||
|
cb1876f26b | ||
|
74d57ab7fa | ||
|
51814b76da | ||
|
60c877f920 | ||
|
685aaaa3da | ||
|
a33bf2bf34 | ||
|
88c6b6e7d4 | ||
|
1eea826a52 | ||
|
87d8123276 | ||
|
b067771fa4 | ||
|
b2c1c8de9e | ||
|
e83026230a | ||
|
df51674792 | ||
|
0ec2f51fbf | ||
|
d256e93cde | ||
|
ab5eb955b4 | ||
|
44a8a2d5f7 | ||
|
4eeba18088 | ||
|
8f2609d1bd | ||
|
f670f71484 | ||
|
d665bedb5c | ||
|
ba8c7b5bca | ||
|
8cb327606a | ||
|
c65051a8f1 | ||
|
4b8d08f20f | ||
|
54727a5dbe | ||
|
a81a5fa63e | ||
|
260c9a547f | ||
|
a19d0427ed | ||
|
564fc67649 | ||
|
686068065a | ||
|
49181a22b2 | ||
|
5f60c9fc6c | ||
|
f29a29f2ba | ||
|
e5c9c3a947 | ||
|
0bf37c6052 | ||
|
bd9a149059 | ||
|
9da122a189 | ||
|
d22ce4a848 | ||
|
4f0d29129e | ||
|
79f480c17d | ||
|
490948bb38 | ||
|
6d9aa3b44c | ||
|
df04c47f74 | ||
|
1dfaaac5d0 | ||
|
29a1659085 | ||
|
ed5ceb019d | ||
|
bcd8e27a36 | ||
|
1901801d59 | ||
|
71269e0179 | ||
|
5dc02c3476 | ||
|
e28b9aa59c | ||
|
b30c92a9a2 | ||
|
cd389aec13 | ||
|
98da3490e7 | ||
|
8bd1f5684e | ||
|
af2bd6ba69 | ||
|
ef51951785 | ||
|
0995749dec | ||
|
cde19a1f57 | ||
|
0f5721119c | ||
|
ffda84627b | ||
|
fd720d55d9 | ||
|
4210dbce07 | ||
|
eb2d24197a | ||
|
12cfdd5916 | ||
|
3b8b63d17d | ||
|
cfb71cc619 | ||
|
33044c823f | ||
|
0b5920a1f3 | ||
|
6542236b20 | ||
|
4c577e6fa9 | ||
|
a2142dd93e | ||
|
7ce5768372 | ||
|
5426100bde | ||
|
a060351f7a | ||
|
2919fdb7d4 | ||
|
0168cd0574 | ||
|
1bbc457f0d | ||
|
64e916ccb3 | ||
|
f26450f04b | ||
|
66fbb33956 | ||
|
4b5885e3c0 | ||
|
ec59dbbc3d | ||
|
1cb8b17709 | ||
|
61bb2cf130 | ||
|
f9d714ab74 | ||
|
ce704aff5b | ||
|
d2f291689d | ||
|
566297d4df | ||
|
28f6338271 | ||
|
64fe47acd8 | ||
|
35b4a86e06 | ||
|
292894c426 | ||
|
1abd8b3506 | ||
|
8b7ffb28d7 | ||
|
7dd2d6123b | ||
|
69d687dbcb | ||
|
4ca90f2415 | ||
|
4ce2d25d55 | ||
|
72a4cad9c1 | ||
|
3f0eec6427 | ||
|
3c0103d324 | ||
|
886dfc3648 | ||
|
4f9ee82153 | ||
|
7e8beacd1d | ||
|
fb17efe765 | ||
|
594911b7a2 | ||
|
dbf21f7dbc | ||
|
de37a0ae29 | ||
|
ed2818ed89 | ||
|
17b3ea471d | ||
|
43e7b3fec0 | ||
|
c264c91f38 | ||
|
34d2fe45c3 | ||
|
fb7d73be06 | ||
|
de0d793fc7 | ||
|
3d9278cb82 | ||
|
2ffd4738b2 | ||
|
0fe3f6fd8f | ||
|
465d2ebfe8 | ||
|
ada35c43fa | ||
|
bbb338bf12 | ||
|
5bca202c28 | ||
|
6fca7067da | ||
|
c320527f9d | ||
|
d023743fa3 | ||
|
c4ff98e620 | ||
|
3222c0df84 | ||
|
4c9463eeb7 | ||
|
6f7a062221 | ||
|
a32170b9a3 | ||
|
11cabfb546 | ||
|
e032f9bd0e | ||
|
3a00ffde47 | ||
|
19df3afb78 | ||
|
4a9ba2088c | ||
|
a10e6bfb1c | ||
|
4d8707df4b | ||
|
7117d96016 | ||
|
d59021ef9f | ||
|
2aebba9cc1 | ||
|
321405a93a | ||
|
f1a7462c4c | ||
|
f0110a642d | ||
|
168d2afb17 | ||
|
c4d727cbe6 | ||
|
3a10db99c7 | ||
|
857cacfda7 | ||
|
960309e615 | ||
|
fda2719dd4 | ||
|
80a8f62e30 | ||
|
dddc62a9fe | ||
|
43a21ddc9c | ||
|
820715cd62 | ||
|
5e35055379 | ||
|
34cefefce4 | ||
|
5bd85170bf |
@ -1,41 +0,0 @@
|
||||
version: 1.0.0.{build}
|
||||
configuration:
|
||||
- Release
|
||||
- Debug
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- GENERATOR: Visual Studio 15 2017
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: Win32
|
||||
|
||||
- GENERATOR: Visual Studio 15 2017
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: x64
|
||||
|
||||
init:
|
||||
- cmake --version
|
||||
install:
|
||||
- cd C:\Tools\vcpkg
|
||||
- git pull
|
||||
- .\bootstrap-vcpkg.bat
|
||||
- vcpkg install jsoncpp:x86-windows
|
||||
- vcpkg install jsoncpp:x64-windows
|
||||
- vcpkg install zlib:x86-windows
|
||||
- vcpkg install zlib:x64-windows
|
||||
- vcpkg install libpq:x86-windows
|
||||
- vcpkg install libpq:x64-windows
|
||||
- vcpkg integrate install
|
||||
- cd %APPVEYOR_BUILD_FOLDER%
|
||||
before_build:
|
||||
- git submodule update --init
|
||||
- md build
|
||||
- cd build
|
||||
- cmake --config "%CONFIGURATION%" -G "%GENERATOR%" -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake ..
|
||||
build_script:
|
||||
- cmake --build . --config "%CONFIGURATION%"
|
||||
build:
|
||||
project: build\ALL_BUILD.vcxproj
|
||||
verbosity: minimal
|
||||
cache:
|
||||
- c:\tools\vcpkg\installed\
|
@ -21,23 +21,24 @@ AlwaysBreakTemplateDeclarations: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
AfterCaseLabel: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
@ -52,7 +53,7 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
@ -74,6 +75,7 @@ IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertNewlineAtEOF: true
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
@ -93,7 +95,8 @@ PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 2000
|
||||
PointerAlignment: Left
|
||||
PointerAlignment: Right
|
||||
ReferenceAlignment: Right
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
@ -123,7 +126,8 @@ RawStringFormats:
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: false
|
||||
SeparateDefinitionBlocks: Always
|
||||
SortIncludes: Never
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
|
4
.github/FUNDING.yml
vendored
4
.github/FUNDING.yml
vendored
@ -1,6 +1,6 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
github: drogonframework
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: ['https://paypal.me/antao2019']
|
||||
custom: # ['https://paypal.me/antao2019']
|
||||
|
9
.github/ISSUE_TEMPLATE/bug_report.md
vendored
9
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,10 +1,17 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
labels:
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Notice**
|
||||
If you need support or clarification regarding the usage of Drogon in your project, visit the official Drogon support channel at [gitter](https://gitter.im/drogon-web/community)
|
||||
|
||||
Please create a new issue only if you think you have found a bug or if have a feature request/enhancement.
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
|
9
.github/ISSUE_TEMPLATE/feature_request.md
vendored
9
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,10 +1,17 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
labels:
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Notice**
|
||||
If you need support or clarification regarding the usage of Drogon in your project, visit the official Drogon support channel at [gitter](https://gitter.im/drogon-web/community)
|
||||
|
||||
Please create a new issue only if you think you have found a bug or if have a feature request/enhancement.
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
|
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
237
.github/workflows/cmake.yml
vendored
Normal file
237
.github/workflows/cmake.yml
vendored
Normal file
@ -0,0 +1,237 @@
|
||||
name: Build & Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
windows:
|
||||
name: windows/msvc - ${{ matrix.link }}
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
link: ["STATIC", "SHARED"]
|
||||
steps:
|
||||
- name: Checkout Drogon source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install dependencies
|
||||
run: pip install conan
|
||||
|
||||
- name: Create build directory
|
||||
run: mkdir build
|
||||
|
||||
- name: Install conan packages
|
||||
working-directory: ./build
|
||||
run: |
|
||||
conan profile detect
|
||||
conan install .. -s compiler="msvc" -sbuild_type=Debug --build=missing -s compiler.cppstd=17
|
||||
|
||||
- name: Create Build Environment & Configure Cmake
|
||||
shell: bash
|
||||
working-directory: ./build
|
||||
run: |
|
||||
[[ ${{ matrix.link }} == "SHARED" ]] && shared="ON" || shared="OFF"
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DBUILD_TESTING=on \
|
||||
-DBUILD_SHARED_LIBS=$shared \
|
||||
-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" \
|
||||
-DBUILD_CTL=ON \
|
||||
-DBUILD_EXAMPLES=ON \
|
||||
-DUSE_SPDLOG=ON \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW \
|
||||
-DCMAKE_CXX_STANDARD=17
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build --target install --parallel
|
||||
|
||||
- name: Test
|
||||
shell: bash
|
||||
run: ./test.sh -w
|
||||
|
||||
macos:
|
||||
runs-on: macos-${{ matrix.osver }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
osver: [13, 14, 15]
|
||||
steps:
|
||||
- name: Checkout Drogon source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install dependencies
|
||||
# Already installed: brotli, zlib, lz4, sqlite3
|
||||
run: brew install ninja jsoncpp mariadb hiredis redis spdlog postgresql@14
|
||||
|
||||
- name: Create Build Environment & Configure Cmake
|
||||
# Some projects don't allow in-source building, so create a separate build directory
|
||||
# We'll use this as our working directory for all subsequent commands
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
-DBUILD_TESTING=on \
|
||||
-DUSE_SPDLOG=ON \
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
|
||||
- name: Build
|
||||
working-directory: ./build
|
||||
# Execute the build. You can specify a specific target with "--target <NAME>"
|
||||
run: ninja && sudo ninja install
|
||||
|
||||
- name: Prepare for testing
|
||||
run: |
|
||||
brew services restart postgresql@14
|
||||
brew services start mariadb
|
||||
brew services start redis
|
||||
sleep 4
|
||||
mariadb -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('')"
|
||||
mariadb -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'"
|
||||
mariadb -e "FLUSH PRIVILEGES"
|
||||
brew services restart mariadb
|
||||
sleep 4
|
||||
psql -c 'create user postgres superuser;' postgres
|
||||
|
||||
- name: Test
|
||||
# Execute tests defined by the CMake configuration.
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ./test.sh -t
|
||||
|
||||
ubuntu:
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
link: [SHARED, STATIC]
|
||||
compiler:
|
||||
- cxx: g++
|
||||
ver: 9
|
||||
- cxx: g++
|
||||
ver: 10
|
||||
- cxx: g++
|
||||
ver: 11
|
||||
- cxx: g++
|
||||
ver: 12
|
||||
- cxx: g++
|
||||
ver: 13
|
||||
- cxx: clang++
|
||||
ver: 11
|
||||
- cxx: clang++
|
||||
ver: 12
|
||||
- cxx: clang++
|
||||
ver: 13
|
||||
- cxx: clang++
|
||||
ver: 14
|
||||
- cxx: clang++
|
||||
ver: 15
|
||||
- cxx: clang++
|
||||
ver: 16
|
||||
- cxx: clang++
|
||||
ver: 17
|
||||
include:
|
||||
- link: STATIC
|
||||
compiler:
|
||||
cxx: g++
|
||||
ver: 13
|
||||
feature: coroutines
|
||||
env:
|
||||
CXX: ${{ matrix.compiler.cxx }}-${{ matrix.compiler.ver }}
|
||||
steps:
|
||||
- name: Checkout Drogon source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
# Installing packages might fail as the github image becomes outdated
|
||||
sudo apt update
|
||||
# These aren't available or don't work well in vcpkg
|
||||
sudo apt-get install -y libjsoncpp-dev uuid-dev libssl-dev zlib1g-dev libsqlite3-dev
|
||||
sudo apt-get install -y ninja-build libbrotli-dev
|
||||
sudo apt-get install -y libspdlog-dev
|
||||
|
||||
- name: Install postgresql
|
||||
run: |
|
||||
sudo apt-get --purge remove postgresql postgresql-doc postgresql-common postgresql-client-common
|
||||
sudo apt-get -y install postgresql-all
|
||||
|
||||
- name: Install g++-13
|
||||
if: startsWith(matrix.compiler.cxx, 'g++') && matrix.compiler.ver == 13
|
||||
run: |
|
||||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
sudo apt-get install g++-${{ matrix.compiler.ver }}
|
||||
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
|
||||
|
||||
- name: Install Clang
|
||||
if: startsWith(matrix.compiler.cxx, 'clang') && matrix.compiler.ver < 13
|
||||
run: sudo apt-get install clang-${{ matrix.compiler.ver }}
|
||||
|
||||
- name: Install Clang
|
||||
if: startsWith(matrix.compiler.cxx, 'clang') && matrix.compiler.ver >= 13
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x ./llvm.sh
|
||||
sudo ./llvm.sh ${{ matrix.compiler.ver }}
|
||||
|
||||
- name: Export `shared`
|
||||
run: |
|
||||
[[ ${{ matrix.link }} == "SHARED" ]] && shared="ON" || shared="OFF"
|
||||
echo "shared=$shared" >> $GITHUB_ENV
|
||||
|
||||
- name: Create Build Environment & Configure Cmake
|
||||
# Some projects don't allow in-source building, so create a separate build directory
|
||||
# We'll use this as our working directory for all subsequent commands
|
||||
if: matrix.compiler.feature != 'coroutines'
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
-DBUILD_TESTING=on \
|
||||
-DUSE_SPDLOG=ON \
|
||||
-DBUILD_SHARED_LIBS=$shared
|
||||
- name: Create Build Environment & Configure Cmake (coroutines)
|
||||
# Some projects don't allow in-source building, so create a separate build directory
|
||||
# We'll use this as our working directory for all subsequent commands
|
||||
if: matrix.compiler.feature == 'coroutines'
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
-DBUILD_TESTING=on \
|
||||
-DUSE_SPDLOG=ON \
|
||||
-DCMAKE_CXX_FLAGS="-fcoroutines" \
|
||||
-DBUILD_SHARED_LIBS=$shared \
|
||||
|
||||
- name: Build
|
||||
working-directory: ./build
|
||||
# Execute the build. You can specify a specific target with "--target <NAME>"
|
||||
run: ninja && sudo ninja install
|
||||
|
||||
- name: Prepare for testing
|
||||
run: |
|
||||
sudo systemctl start postgresql
|
||||
sleep 1
|
||||
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '12345'" postgres
|
||||
|
||||
- name: Test
|
||||
# Execute tests defined by the CMake configuration.
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ./test.sh -t
|
80
.github/workflows/codeql.yml
vendored
Normal file
80
.github/workflows/codeql.yml
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 'master' ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ 'master' ]
|
||||
schedule:
|
||||
- cron: '46 7 * * 5'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Use only 'java' to analyze code written in Java, Kotlin or both
|
||||
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
env:
|
||||
SHARED: ON
|
||||
|
||||
steps:
|
||||
- name: Checkout Drogon source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt-get install -y libjsoncpp-dev uuid-dev libssl-dev zlib1g-dev libsqlite3-dev
|
||||
sudo apt-get install -y ninja-build libbrotli-dev
|
||||
|
||||
- name: Create Build Environment & Configure Cmake
|
||||
run: |
|
||||
cmake -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
-DBUILD_TESTING=on \
|
||||
-DBUILD_SHARED_LIBS=$SHARED
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
- name: Build
|
||||
working-directory: ./build
|
||||
run: ninja && sudo ninja install
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
15
.github/workflows/codespell.yml
vendored
Normal file
15
.github/workflows/codespell.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Look for typos in the codebase using codespell.
|
||||
# https://github.com/codespell-project/codespell#readme
|
||||
name: codespell
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
jobs:
|
||||
codespell:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: sudo apt-get install -y codespell
|
||||
- run: codespell --ignore-words-list="coo,folx,ot,statics,xwindows,NotIn,aNULL," --skip="*.csp"
|
41
.github/workflows/cpp.yml
vendored
Normal file
41
.github/workflows/cpp.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: C++
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
format:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dos2unix
|
||||
run: sudo apt-get install -y dos2unix
|
||||
|
||||
- name: Install clang-format-17
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x ./llvm.sh
|
||||
sudo ./llvm.sh 17
|
||||
sudo apt-get install -y clang-format-17
|
||||
|
||||
- name: Check formatting
|
||||
run: ./format.sh && git diff --exit-code
|
||||
env:
|
||||
CLANG_FORMAT: clang-format-17
|
||||
|
||||
cpplint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install cpplint
|
||||
run: pip install cpplint
|
||||
|
||||
- name: Run lint
|
||||
run: cpplint --recursive .
|
28
.github/workflows/docker-publish.yml
vendored
Normal file
28
.github/workflows/docker-publish.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created] # 当新版本被创建时触发
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
cd docker/ubuntu
|
||||
docker build -t drogonframework/drogon:latest .
|
||||
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push drogonframework/drogon:latest
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -31,10 +31,10 @@
|
||||
*.out
|
||||
*.app
|
||||
|
||||
build
|
||||
cmake-build-debug
|
||||
.idea
|
||||
lib/inc/drogon/version.h
|
||||
build/
|
||||
cmake-build-debug/
|
||||
cmake-build-debug-visual-studio/
|
||||
.idea/
|
||||
html/
|
||||
latex/
|
||||
.vscode
|
||||
@ -45,3 +45,5 @@ latex/
|
||||
.vs/
|
||||
CMakeSettings.json
|
||||
install
|
||||
trace.json
|
||||
.cache/
|
||||
|
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,4 +1,4 @@
|
||||
[submodule "trantor"]
|
||||
path = trantor
|
||||
url = https://github.com/an-tao/trantor.git
|
||||
|
||||
branch = master
|
||||
|
77
.travis.yml
77
.travis.yml
@ -1,77 +0,0 @@
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
dist: xenial
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
|
||||
sudo: required
|
||||
|
||||
language: cpp
|
||||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- xenial
|
||||
- sourceline: 'deb http://archive.ubuntu.com/ubuntu xenial main'
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
packages:
|
||||
- gcc
|
||||
- g++
|
||||
- libjsoncpp-dev
|
||||
- uuid-dev
|
||||
- zlib1g-dev
|
||||
- postgresql-server-dev-10
|
||||
- openssl
|
||||
- libssl-dev
|
||||
- libsqlite3-dev
|
||||
- mariadb-client
|
||||
- mariadb-server
|
||||
- build-essential
|
||||
- cmake
|
||||
- boost1.67
|
||||
- libbrotli-dev
|
||||
homebrew:
|
||||
packages:
|
||||
- jsoncpp
|
||||
- ossp-uuid
|
||||
- openssl
|
||||
- cmake
|
||||
- libtool
|
||||
- lz4
|
||||
- mariadb
|
||||
- sqlite3
|
||||
update: true
|
||||
mariadb: '10.0'
|
||||
|
||||
before_install:
|
||||
- wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
|
||||
- tar xf release-1.10.0.tar.gz
|
||||
- cd googletest-release-1.10.0
|
||||
- cmake .
|
||||
- make
|
||||
- sudo make install
|
||||
- cd -
|
||||
|
||||
before_script:
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then
|
||||
brew tap homebrew/services;
|
||||
brew services restart postgresql;
|
||||
brew services start mariadb;
|
||||
sleep 2;
|
||||
mariadb -e "CREATE USER 'root'@'localhost' IDENTIFIED BY ''";
|
||||
mariadb -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('')";
|
||||
mariadb -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'";
|
||||
mariadb -e "FLUSH PRIVILEGES";
|
||||
sleep 2;
|
||||
brew services restart mariadb;
|
||||
psql -c 'create user postgres superuser;' postgres;
|
||||
fi
|
||||
|
||||
services:
|
||||
- postgresql
|
||||
- mysql
|
||||
|
||||
script:
|
||||
- ./build.sh -t
|
||||
- ./test.sh -t
|
1022
CMakeLists.txt
Executable file → Normal file
1022
CMakeLists.txt
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@ contribute in an overall positive way.
|
||||
1. Fork, then clone the repository: `git clone
|
||||
git@github.com:your-username/drogon.git`
|
||||
1. Follow the [official installation steps on
|
||||
DocsForge](https://drogon.docsforge.com/master/installation/). It’s best to
|
||||
Github](https://drogonframework.github.io/drogon-docs/#/ENG-02-Installation). It’s best to
|
||||
make sure to have the `drogon_ctl` executable in your shell’s `PATH`
|
||||
environment variable in case you use a terminal.
|
||||
|
||||
|
36
CPPLINT.cfg
Normal file
36
CPPLINT.cfg
Normal file
@ -0,0 +1,36 @@
|
||||
# Stop searching for additional config files.
|
||||
set noparent
|
||||
|
||||
exclude_files=trantor
|
||||
exclude_files=build
|
||||
|
||||
# Use non-const reference rather than a pointer.
|
||||
filter=-runtime/references
|
||||
|
||||
# CHECK macros are from Drogon, not Google Test.
|
||||
filter=-readability/check
|
||||
|
||||
# Don't warn about the use of C++11 or C++17 features.
|
||||
filter=-build/c++11
|
||||
filter=-build/c++17
|
||||
|
||||
filter=-build/include_subdir
|
||||
|
||||
# We prioritize clang-format for now.
|
||||
filter=-whitespace
|
||||
|
||||
# We don't require a username in TODO comments.
|
||||
filter=-readability/todo
|
||||
|
||||
# TODO: Fix these.
|
||||
filter=-legal/copyright
|
||||
filter=-build/namespaces
|
||||
filter=-build/include
|
||||
filter=-build/include_what_you_use
|
||||
filter=-runtime/explicit
|
||||
filter=-runtime/string
|
||||
filter=-runtime/int
|
||||
filter=-readability/casting
|
||||
filter=-readability/braces
|
||||
filter=-readability/fn_size
|
||||
filter=-runtime/threadsafe_fn
|
1512
ChangeLog.md
1512
ChangeLog.md
File diff suppressed because it is too large
Load Diff
27
Dockerfile
27
Dockerfile
@ -1,27 +0,0 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
RUN apt-get update -yqq \
|
||||
&& apt-get install -yqq --no-install-recommends software-properties-common \
|
||||
sudo curl wget cmake pkg-config locales git gcc-8 g++-8 \
|
||||
openssl libssl-dev libjsoncpp-dev uuid-dev zlib1g-dev libc-ares-dev\
|
||||
postgresql-server-dev-all libmariadbclient-dev libsqlite3-dev \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& locale-gen en_US.UTF-8
|
||||
|
||||
ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US:en \
|
||||
LC_ALL=en_US.UTF-8 \
|
||||
CC=gcc-8 \
|
||||
CXX=g++-8 \
|
||||
AR=gcc-ar-8 \
|
||||
RANLIB=gcc-ranlib-8 \
|
||||
IROOT=/install
|
||||
|
||||
ENV DROGON_ROOT="$IROOT/drogon"
|
||||
|
||||
ADD https://api.github.com/repos/an-tao/drogon/git/refs/heads/master $IROOT/version.json
|
||||
RUN git clone https://github.com/an-tao/drogon $DROGON_ROOT
|
||||
|
||||
WORKDIR $DROGON_ROOT
|
||||
|
||||
RUN ./build.sh
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 An Tao
|
||||
Copyright (c) 2019-2023 An Tao
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
64
README.md
64
README.md
@ -1,17 +1,16 @@
|
||||

|
||||

|
||||
|
||||
[](https://travis-ci.com/an-tao/drogon)
|
||||
[](https://ci.appveyor.com/project/an-tao/drogon/branch/master)
|
||||
[](https://lgtm.com/projects/g/an-tao/drogon/alerts/)
|
||||
[](https://lgtm.com/projects/g/an-tao/drogon/context:cpp)
|
||||
[](https://gitter.im/drogon-web/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://github.com/drogonframework/drogon/actions)
|
||||
[](https://conan.io/center/recipes/drogon)
|
||||
[](https://t.me/joinchat/_mMNGv0748ZkMDAx)
|
||||
[](https://discord.gg/3DvHY6Ewuj)
|
||||
[](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
|
||||
|
||||
English | [简体中文](./README.zh-CN.md)
|
||||
English | [简体中文](./README.zh-CN.md) | [繁體中文](./README.zh-TW.md)
|
||||
### Overview
|
||||
**Drogon** is a C++14/17-based HTTP application framework. Drogon can be used to easily build various types of web application server programs using C++. **Drogon** is the name of a dragon in the American TV series "Game of Thrones" that I really like.
|
||||
**Drogon** is a C++17/20 based HTTP application framework. Drogon can be used to easily build various types of web application server programs using C++. **Drogon** is the name of a dragon from the American TV series *Game of Thrones*, which I really enjoy.
|
||||
|
||||
Drogon is a cross-platform framework, It supports Linux, macOS, FreeBSD, and Windows. Its main features are as follows:
|
||||
Drogon is a cross-platform framework, It supports Linux, macOS, FreeBSD, OpenBSD, HaikuOS, and Windows. Its main features are as follows:
|
||||
|
||||
* Use a non-blocking I/O network lib based on epoll (kqueue under macOS/FreeBSD) to provide high-concurrency, high-performance network IO, please visit the [TFB Tests Results](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite) for more details;
|
||||
* Provide a completely asynchronous programming mode;
|
||||
@ -31,10 +30,12 @@ Drogon is a cross-platform framework, It supports Linux, macOS, FreeBSD, and Win
|
||||
* Provide a lightweight command line tool, drogon_ctl, to simplify the creation of various classes in Drogon and the generation of view code;
|
||||
* Support non-blocking I/O based asynchronously reading and writing database (PostgreSQL and MySQL(MariaDB) database);
|
||||
* Support asynchronously reading and writing sqlite3 database based on thread pool;
|
||||
* Support Redis with asynchronous reading and writing;
|
||||
* Support ARM Architecture;
|
||||
* Provide a convenient lightweight ORM implementation that supports for regular object-to-database bidirectional mapping;
|
||||
* Support plugins which can be installed by the configuration file at load time;
|
||||
* Support AOP with build-in joinpoints.
|
||||
* Support AOP with built-in joinpoints.
|
||||
* Support C++ coroutines
|
||||
|
||||
## A very simple example
|
||||
|
||||
@ -70,7 +71,7 @@ int main()
|
||||
Drogon provides some interfaces for adding controller logic directly in the main() function, for example, user can register a handler like this in Drogon:
|
||||
|
||||
```c++
|
||||
app.registerHandler("/test?username={name}",
|
||||
app().registerHandler("/test?username={name}",
|
||||
[](const HttpRequestPtr& req,
|
||||
std::function<void (const HttpResponsePtr &)> &&callback,
|
||||
const std::string &name)
|
||||
@ -94,7 +95,7 @@ using namespace drogon;
|
||||
class TestCtrl:public drogon::HttpSimpleController<TestCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
PATH_ADD("/test",Get);
|
||||
PATH_LIST_END
|
||||
@ -113,7 +114,7 @@ void TestCtrl::asyncHandleHttpRequest(const HttpRequestPtr& req,
|
||||
}
|
||||
```
|
||||
|
||||
**Most of the above programs can be automatically generated by the command line tool `drogon_ctl` provided by drogon** (The cammand is `drogon_ctl create controller TestCtrl`). All the user needs to do is add their own business logic. In the example, the controller returns a `Hello, world!` string when the client accesses the `http://ip/test` URL.
|
||||
**Most of the above programs can be automatically generated by the command line tool `drogon_ctl` provided by drogon** (The command is `drogon_ctl create controller TestCtrl`). All the user needs to do is add their own business logic. In the example, the controller returns a `Hello, world!` string when the client accesses the `http://ip/test` URL.
|
||||
|
||||
For JSON format response, we create the controller as follows:
|
||||
|
||||
@ -125,7 +126,7 @@ using namespace drogon;
|
||||
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
//list path definitions here;
|
||||
PATH_ADD("/json", Get);
|
||||
@ -182,7 +183,40 @@ As you can see, users can use the `HttpController` to map paths and parameters a
|
||||
|
||||
In addition, you can also find that all handler interfaces are in asynchronous mode, where the response is returned by a callback object. This design is for performance reasons because in asynchronous mode the drogon application can handle a large number of concurrent requests with a small number of threads.
|
||||
|
||||
After compiling all of the above source files, we get a very simple web application. This is a good start. **For more information, please visit the [wiki](https://github.com/an-tao/drogon/wiki/01-Overview) or [DocsForge](https://drogon.docsforge.com/master/overview/)**
|
||||
After compiling all of the above source files, we get a very simple web application. This is a good start. **For more information, please visit the [documentation](https://drogonframework.github.io/drogon-docs/#/) on GitHub**.
|
||||
|
||||
## Cross-compilation
|
||||
|
||||
Drogon supports cross-compilation, you should define the `CMAKE_SYSTEM_NAME` in toolchain file, for example:
|
||||
|
||||
```cmake
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
```
|
||||
|
||||
You can disable building options for examples and drogon_ctl by settings `BUILD_EXAMPLES` and `BUILD_CTL` to `OFF` in the toolchain file.
|
||||
|
||||
## Building options
|
||||
|
||||
Drogon provides some building options, you can enable or disable them by setting the corresponding variables to `ON` or `OFF` in the cmake command line, cmake file etc...
|
||||
|
||||
| Option name | Description | Default value |
|
||||
| :--- | :--- | :--- |
|
||||
| BUILD_CTL | Build drogon_ctl | ON |
|
||||
| BUILD_EXAMPLES | Build examples | ON |
|
||||
| BUILD_ORM | Build orm | ON |
|
||||
| COZ_PROFILING | Use coz for profiling | OFF |
|
||||
| BUILD_SHARED_LIBS | Build drogon as a shared lib | OFF |
|
||||
| BUILD_DOC | Build Doxygen documentation | OFF |
|
||||
| BUILD_BROTLI | Build Brotli | ON |
|
||||
| BUILD_YAML_CONFIG | Build yaml config | ON |
|
||||
| USE_SUBMODULE | Use trantor as a submodule | ON |
|
||||
|
||||
|
||||
## Contributions
|
||||
|
||||
This project exists thanks to all the people who contribute code.
|
||||
|
||||
<a href="https://github.com/drogonframework/drogon/graphs/contributors"><img src="https://contributors-svg.opencollective.com/drogon/contributors.svg?width=890&button=false" alt="Code contributors" /></a>
|
||||
|
||||
Every contribution is welcome. Please refer to the [contribution guidelines](CONTRIBUTING.md) for more information.
|
||||
|
@ -1,17 +1,17 @@
|
||||

|
||||

|
||||
|
||||
[](https://travis-ci.com/an-tao/drogon)
|
||||
[](https://lgtm.com/projects/g/an-tao/drogon/alerts/)
|
||||
[](https://lgtm.com/projects/g/an-tao/drogon/context:cpp)
|
||||
[](https://gitter.im/drogon-web/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://github.com/drogonframework/drogon/actions)
|
||||
[](https://conan.io/center/recipes/drogon)
|
||||
[](https://t.me/joinchat/_mMNGv0748ZkMDAx)
|
||||
[](https://discord.gg/3DvHY6Ewuj)
|
||||
[](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
|
||||
|
||||
[English](./README.md) | 简体中文
|
||||
[English](./README.md) | 简体中文 | [繁體中文](./README.zh-TW.md)
|
||||
|
||||
**Drogon**是一个基于C++14/17的Http应用框架,使用Drogon可以方便的使用C++构建各种类型的Web应用服务端程序。
|
||||
**Drogon**是一个基于C++17/20的Http应用框架,使用Drogon可以方便的使用C++构建各种类型的Web应用服务端程序。
|
||||
本版本库是github上[Drogon工程](https://github.com/an-tao/drogon)的镜像库。**Drogon**是作者非常喜欢的美剧《权力的游戏》中的一条龙的名字(汉译作卓耿),和龙有关但并不是dragon的误写,为了不至于引起不必要的误会这里说明一下。
|
||||
|
||||
Drogon是一个跨平台框架,它支持Linux,也支持macOS、FreeBSD,和Windows。它的主要特点如下:
|
||||
Drogon是一个跨平台框架,它支持Linux,也支持macOS、FreeBSD,OpenBSD,HaikuOS,和Windows。它的主要特点如下:
|
||||
|
||||
* 网络层使用基于epoll(macOS/FreeBSD下是kqueue)的非阻塞IO框架,提供高并发、高性能的网络IO。详细请见[TFB Tests Results](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite);
|
||||
* 全异步编程模式;
|
||||
@ -31,14 +31,16 @@ Drogon是一个跨平台框架,它支持Linux,也支持macOS、FreeBSD,和
|
||||
* 提供一个轻量的命令行工具drogon_ctl,帮助简化各种类的创建和视图代码的生成过程;
|
||||
* 基于非阻塞IO实现的异步数据库读写,目前支持PostgreSQL和MySQL(MariaDB)数据库;
|
||||
* 基于线程池实现sqlite3数据库的异步读写,提供与上文数据库相同的接口;
|
||||
* 支持Redis异步读写;
|
||||
* 支持ARM架构;
|
||||
* 方便的轻量级ORM实现,支持常规的对象到数据库的双向映射操作;
|
||||
* 支持插件,可通过配置文件在加载期动态拆装;
|
||||
* 支持内建插入点的AOP
|
||||
* 支持C++协程
|
||||
|
||||
## 一个非常简单的例子
|
||||
|
||||
不像大多数C++框架那样,drogon的主程序可以保持非常简单。 Drogon使用了一些小技巧是主程序和控制器解耦合. 控制器的路径路由设置可以在控制器类定义中或者配置文件中完成.
|
||||
不像大多数C++框架那样,drogon的主程序可以保持非常简单。 Drogon使用了一些小技巧使主程序和控制器解耦合. 控制器的路由设置可以在控制器类中定义或者配置文件中完成.
|
||||
|
||||
下面是一个典型的主程序的样子:
|
||||
|
||||
@ -70,7 +72,7 @@ int main()
|
||||
当然,Drogon也提供了一些接口,使用户可以在main()函数中直接添加控制器逻辑,比如,用户可以注册一个lambda处理器到drogon框架中,如下所示:
|
||||
|
||||
```c++
|
||||
app.registerHandler("/test?username={name}",
|
||||
app().registerHandler("/test?username={name}",
|
||||
[](const HttpRequestPtr& req,
|
||||
std::function<void (const HttpResponsePtr &)> &&callback,
|
||||
const std::string &name)
|
||||
@ -96,7 +98,7 @@ using namespace drogon;
|
||||
class TestCtrl:public drogon::HttpSimpleController<TestCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
PATH_ADD("/test",Get);
|
||||
PATH_LIST_END
|
||||
@ -127,7 +129,7 @@ using namespace drogon;
|
||||
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
//list path definitions here;
|
||||
PATH_ADD("/json", Get);
|
||||
@ -184,12 +186,20 @@ class User : public drogon::HttpController<User>
|
||||
|
||||
另外,你可以发现前面所有的处理函数接口都是异步的,处理器的响应是通过回调对象返回的。这种设计是出于对高性能的考虑,因为在异步模式下,可以使用少量的线程(比如和处理器核心数相等的线程)处理大量的并发请求。
|
||||
|
||||
编译上述的所有源文件后,我们得到了一个非常简单的web应用程序,这是一个不错的开始。**请访问[wiki](https://github.com/an-tao/drogon/wiki/01-Overview)或者[doxiz](https://doxiz.com/drogon/master/overview/)以获取更多的信息**
|
||||
编译上述的所有源文件后,我们得到了一个非常简单的web应用程序,这是一个不错的开始。**请访问GitHub上的[文档](https://drogonframework.github.io/drogon-docs/#/CHN/CHN-01-%E6%A6%82%E8%BF%B0)**
|
||||
|
||||
## 贡献方式
|
||||
|
||||
欢迎您的贡献。 请阅读[贡献指南](CONTRIBUTING.md)以获取更多的信息。
|
||||
|
||||
<a href="https://github.com/drogonframework/drogon/graphs/contributors"><img src="https://contributors-svg.opencollective.com/drogon/contributors.svg?width=890&button=false" alt="Code contributors" /></a>
|
||||
|
||||
## QQ交流群:1137909452
|
||||
|
||||
欢迎交流探讨。
|
||||
|
||||
## 微信公众号:
|
||||
|
||||

|
||||
|
||||
会不定期推送一些Drogon的使用技巧和更新信息,欢迎关注。
|
198
README.zh-TW.md
Normal file
198
README.zh-TW.md
Normal file
@ -0,0 +1,198 @@
|
||||

|
||||
|
||||
[](https://github.com/drogonframework/drogon/actions)
|
||||
[](https://conan.io/center/recipes/drogon)
|
||||
[](https://t.me/joinchat/_mMNGv0748ZkMDAx)
|
||||
[](https://discord.gg/3DvHY6Ewuj)
|
||||
[](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
|
||||
|
||||
[English](./README.md) | [简体中文](./README.zh-CN.md) | 繁體中文
|
||||
|
||||
**Drogon** 是一個基於 C++17/20 的 HTTP 應用程式框架,使用 Drogon 可以方便地用 C++ 建立各種類型的 Web App 伺服器端程式。
|
||||
|
||||
這個版本庫是 GitHub 上 [Drogon](https://github.com/an-tao/drogon) 的鏡像庫。**Drogon** 是作者非常喜歡的美劇《冰與火之歌:權力遊戲》中的一條龍的名字(中文譯作卓耿),和龍有關但並不是 dragon 的誤寫,為了避免不必要的誤會在此說明。
|
||||
|
||||
Drogon 是一個跨平台框架,支援 Linux、macOS、FreeBSD/OpenBSD、HaikuOS 和 Windows。主要特點如下:
|
||||
|
||||
* 網路層使用基於 epoll(macOS/FreeBSD 下是 kqueue)的非阻塞 IO 框架,提供高並行、高效能的網路 IO。詳細請見 [TFB Tests Results](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite);
|
||||
* 完全非同步的程式撰寫邏輯;
|
||||
* 支援 HTTP 1.0/1.1(伺服器端和用戶端);
|
||||
* 基於樣板(template)實作的簡單反射機制,使主程式框架、控制器(controller)和視圖(view)完全解耦;
|
||||
* 支援 cookies 和內建的 session;
|
||||
* 支援後端算繪,將控制器產生的資料交給視圖產生 HTML 頁面,視圖由 CSP 樣板檔案描述,透過 CSP 標籤將 C++ 程式碼嵌入 HTML 頁面,由 drogon 的命令列工具在編譯階段自動產生 C++ 程式碼並編譯;
|
||||
* 支援執行期的視圖頁面動態載入(動態編譯和載入 so 檔案);
|
||||
* 非常方便靈活的路徑(path)到控制器處理函式(handler)的對應方案;
|
||||
* 支援過濾器(filter)鏈,方便在控制器之前執行統一的邏輯(如登入驗證、HTTP Method 限制驗證等);
|
||||
* 支援 HTTPS(基於 OpenSSL);
|
||||
* 支援 WebSocket(伺服器端和用戶端);
|
||||
* 支援 JSON 格式的請求和回應,方便開發 RESTful API;
|
||||
* 支援檔案下載和上傳,支援 `sendfile` 系統呼叫;
|
||||
* 支援 Gzip/Brotli 壓縮傳輸;
|
||||
* 支援 pipelining;
|
||||
* 提供輕量的命令列工具 `drogon_ctl`,幫助簡化各種類別的建立和視圖程式碼的產生過程;
|
||||
* 非同步的讀寫資料庫,目前支援 PostgreSQL 和 MySQL(MariaDB)資料庫;
|
||||
* 支援非同步讀寫 Redis;
|
||||
* 基於執行緒池實作 sqlite3 資料庫的非同步讀寫,提供與上述資料庫相同的介面;
|
||||
* 支援 ARM 架構;
|
||||
* 方便的輕量級 ORM 實現,一般物件到資料庫的雙向對應;
|
||||
* 支援外掛,可透過設定檔案在載入時動態載入;
|
||||
* 支援內建插入點的 AOP;
|
||||
* 支援 C++ coroutine。
|
||||
|
||||
## 一個非常簡單的例子
|
||||
|
||||
不像大多數 C++ 框架,drogon 的主程式可以非常簡單。Drogon 使用了一些小技巧使主程式和控制器解耦。控制器的路由設定可以在控制器類別中定義或在設定檔案中完成。
|
||||
|
||||
下面是一個典型主程式的樣子:
|
||||
|
||||
```c++
|
||||
#include <drogon/drogon.h>
|
||||
using namespace drogon;
|
||||
int main()
|
||||
{
|
||||
app().setLogPath("./")
|
||||
.setLogLevel(trantor::Logger::kWarn)
|
||||
.addListener("0.0.0.0", 80)
|
||||
.setThreadNum(16)
|
||||
.enableRunAsDaemon()
|
||||
.run();
|
||||
}
|
||||
```
|
||||
|
||||
如果使用設定檔案,可以進一步簡化成:
|
||||
|
||||
```c++
|
||||
#include <drogon/drogon.h>
|
||||
using namespace drogon;
|
||||
int main()
|
||||
{
|
||||
app().loadConfigFile("./config.json").run();
|
||||
}
|
||||
```
|
||||
|
||||
當然,Drogon 也提供了一些函式,讓使用者可以在 `main()` 函式中直接加入控制器邏輯,例如,使用者可以註冊一個 lambda 處理常式到 drogon 框架中,如下所示:
|
||||
|
||||
```c++
|
||||
app().registerHandler("/test?username={name}",
|
||||
[](const HttpRequestPtr& req,
|
||||
std::function<void (const HttpResponsePtr &)> &&callback,
|
||||
const std::string &name)
|
||||
{
|
||||
Json::Value json;
|
||||
json["result"]="ok";
|
||||
json["message"]=std::string("hello,")+name;
|
||||
auto resp=HttpResponse::newHttpJsonResponse(json);
|
||||
callback(resp);
|
||||
},
|
||||
{Get,"LoginFilter"});
|
||||
```
|
||||
|
||||
這看起來很方便,但不適用於複雜的場景,試想如果有數十個或數百個處理函式要註冊進框架,`main()` 函式將變得難以閱讀。顯然,讓每個包含處理函式的類別在自己的定義中完成註冊是更好的選擇。所以,除非你的應用邏輯非常簡單,我們不建議使用上述介面,更好的做法是建立一個 HttpSimpleController 類別,如下:
|
||||
|
||||
```c++
|
||||
/// The TestCtrl.h file
|
||||
#pragma once
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
using namespace drogon;
|
||||
class TestCtrl:public drogon::HttpSimpleController<TestCtrl>
|
||||
{
|
||||
public:
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
PATH_ADD("/test",Get);
|
||||
PATH_LIST_END
|
||||
};
|
||||
|
||||
/// The TestCtrl.cc file
|
||||
#include "TestCtrl.h"
|
||||
void TestCtrl::asyncHandleHttpRequest(const HttpRequestPtr& req,
|
||||
std::function<void (const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
//write your application logic here
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("<p>Hello, world!</p>");
|
||||
resp->setExpiredTime(0);
|
||||
callback(resp);
|
||||
}
|
||||
```
|
||||
|
||||
**上述程式的大部分程式碼都可以由 `drogon_ctl` 指令產生**(使用指令 `drogon_ctl create controller TestCtr`)。使用者只需要加入自己的業務邏輯。在這個範例中,當用戶端存取 URL `http://ip/test` 時,控制器簡單地回傳一個 `Hello, world!` 頁面。
|
||||
|
||||
對於 JSON 格式的回應,我們可以這樣建立控制器:
|
||||
|
||||
```c++
|
||||
/// The header file
|
||||
#pragma once
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
using namespace drogon;
|
||||
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
|
||||
{
|
||||
public:
|
||||
void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
//list path definitions here;
|
||||
PATH_ADD("/json", Get);
|
||||
PATH_LIST_END
|
||||
};
|
||||
|
||||
/// The source file
|
||||
#include "JsonCtrl.h"
|
||||
void JsonCtrl::asyncHandleHttpRequest(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
Json::Value ret;
|
||||
ret["message"] = "Hello, World!";
|
||||
auto resp = HttpResponse::newHttpJsonResponse(ret);
|
||||
callback(resp);
|
||||
}
|
||||
```
|
||||
|
||||
讓我們更進一步,透過 HttpController 類別建立一個 RESTful API 的範例,如下所示(省略實作檔案):
|
||||
|
||||
```c++
|
||||
/// The header file
|
||||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api
|
||||
{
|
||||
namespace v1
|
||||
{
|
||||
class User : public drogon::HttpController<User>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
//use METHOD_ADD to add your custom processing function here;
|
||||
METHOD_ADD(User::getInfo, "/{id}", Get); //path is /api/v1/User/{arg1}
|
||||
METHOD_ADD(User::getDetailInfo, "/{id}/detailinfo", Get); //path is /api/v1/User/{arg1}/detailinfo
|
||||
METHOD_ADD(User::newUser, "/{name}", Post); //path is /api/v1/User/{arg1}
|
||||
METHOD_LIST_END
|
||||
//your declaration of processing function maybe like this:
|
||||
void getInfo(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int userId) const;
|
||||
void getDetailInfo(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int userId) const;
|
||||
void newUser(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, std::string &&userName);
|
||||
public:
|
||||
User()
|
||||
{
|
||||
LOG_DEBUG << "User constructor!";
|
||||
}
|
||||
};
|
||||
} // namespace v1
|
||||
} // namespace api
|
||||
```
|
||||
|
||||
如你所見,透過 `HttpController` 類別,使用者可以同時對應路徑和路徑參數,這對 RESTful API 應用來說非常方便。
|
||||
|
||||
另外,你可以發現前面所有的處理函式介面都是非同步的,處理器的回應是透過回呼物件回傳的。這種設計是考慮到效能,因為在非同步模式下,可以使用少量的執行緒(例如和處理器核心數相等的執行緒)處理大量的並行請求。
|
||||
|
||||
編譯上述所有原始檔案後,我們得到了一個非常簡單的網頁應用程式,這是一個不錯的開始。**請瀏覽 GitHub 上的[文件](https://drogonframework.github.io/drogon-docs/#/CHN/CHN-01-%E6%A6%82%E8%BF%B0)**
|
||||
|
||||
## 貢獻方式
|
||||
|
||||
歡迎您的貢獻。請閱讀[貢獻指南](CONTRIBUTING.md)以取得更多資訊。
|
||||
|
||||
<a href="https://github.com/drogonframework/drogon/graphs/contributors"><img src="https://contributors-svg.opencollective.com/drogon/contributors.svg?width=890&button=false" alt="Code contributors" /></a>
|
||||
|
||||
## QQ 交流群:1137909452
|
||||
|
||||
歡迎交流討論。
|
@ -1 +0,0 @@
|
||||
theme: jekyll-theme-cayman
|
28
build.sh
28
build.sh
@ -29,8 +29,10 @@ function build_drogon() {
|
||||
echo "Start building drogon ..."
|
||||
if [ $1 -eq 1 ]; then
|
||||
cmake .. -DBUILD_TESTING=YES $cmake_gen
|
||||
elif [ $1 -eq 2 ]; then
|
||||
cmake .. -DBUILD_TESTING=YES -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=1 $cmake_gen
|
||||
else
|
||||
cmake .. $cmake_gen
|
||||
cmake .. -DCMAKE_BUILD_TYPE=release $cmake_gen
|
||||
fi
|
||||
|
||||
#If errors then exit
|
||||
@ -46,7 +48,7 @@ function build_drogon() {
|
||||
fi
|
||||
|
||||
echo "Installing ..."
|
||||
sudo $make_program install
|
||||
$make_program install
|
||||
|
||||
#Go back to the current directory
|
||||
cd $current_dir
|
||||
@ -58,11 +60,17 @@ make_flags=''
|
||||
cmake_gen=''
|
||||
parallel=1
|
||||
|
||||
if [ $(uname) = 'FreeBSD' ]; then
|
||||
nproc=$(sysctl -n hw.ncpu)
|
||||
else
|
||||
nproc=$(nproc)
|
||||
fi
|
||||
case $(uname) in
|
||||
FreeBSD)
|
||||
nproc=$(sysctl -n hw.ncpu)
|
||||
;;
|
||||
Darwin)
|
||||
nproc=$(sysctl -n hw.ncpu) # sysctl -n hw.ncpu is the equivalent to nproc on macOS.
|
||||
;;
|
||||
*)
|
||||
nproc=$(nproc)
|
||||
;;
|
||||
esac
|
||||
|
||||
# simulate ninja's parallelism
|
||||
case nproc in
|
||||
@ -79,13 +87,15 @@ esac
|
||||
|
||||
if [ -f /bin/ninja ]; then
|
||||
make_program=ninja
|
||||
cmake_gen='-G Ninja'
|
||||
cmake_gen='-GNinja'
|
||||
else
|
||||
make_flags="$make_flags -j$parallel"
|
||||
fi
|
||||
|
||||
if [ "$1" = "-t" ]; then
|
||||
if [ "X$1" = "X-t" ]; then
|
||||
build_drogon 1
|
||||
elif [ "X$1" = "X-tshared" ]; then
|
||||
build_drogon 2
|
||||
else
|
||||
build_drogon 0
|
||||
fi
|
||||
|
72
cmake/DrogonUtilities.cmake
Normal file
72
cmake/DrogonUtilities.cmake
Normal file
@ -0,0 +1,72 @@
|
||||
# ##############################################################################
|
||||
# function drogon_create_views(target source_path output_path
|
||||
# [TRUE to use_path_as_namespace] [prefixed namespace])
|
||||
# ##############################################################################
|
||||
function(drogon_create_views arg)
|
||||
if(ARGC LESS 3)
|
||||
message(STATUS "arguments error when calling drogon_create_views")
|
||||
return()
|
||||
endif()
|
||||
file(MAKE_DIRECTORY ${ARGV2})
|
||||
file(GLOB_RECURSE SCP_LIST ${ARGV1}/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
file(RELATIVE_PATH
|
||||
inFile
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${cspFile})
|
||||
if(ARGC GREATER 3 AND ARGV3)
|
||||
string(REPLACE "/"
|
||||
"_"
|
||||
f1
|
||||
${inFile})
|
||||
string(REPLACE "\\"
|
||||
"_"
|
||||
f2
|
||||
${f1})
|
||||
string(REPLACE ".csp"
|
||||
""
|
||||
outputFile
|
||||
${f2})
|
||||
set(p2ns "")
|
||||
if("${ARGV3}" STREQUAL "TRUE")
|
||||
set(p2ns "--path-to-namespace")
|
||||
endif()
|
||||
if ( (ARGC EQUAL 5) AND ( NOT "${ARGV4}" STREQUAL "") )
|
||||
string(REPLACE "::" "_" nSpace ${ARGV4})
|
||||
set(outputFile "${nSpace}_${outputFile}")
|
||||
set(ns -n ${ARGV4})
|
||||
else()
|
||||
set(ns "")
|
||||
endif()
|
||||
add_custom_command(OUTPUT ${ARGV2}/${outputFile}.h ${ARGV2}/${outputFile}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS
|
||||
create
|
||||
view
|
||||
${inFile}
|
||||
${p2ns}
|
||||
-o
|
||||
${ARGV2}
|
||||
${ns}
|
||||
DEPENDS ${cspFile}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM)
|
||||
set(VIEWSRC ${VIEWSRC} ${ARGV2}/${outputFile}.cc)
|
||||
else()
|
||||
get_filename_component(classname ${cspFile} NAME_WE)
|
||||
add_custom_command(OUTPUT ${ARGV2}/${classname}.h ${ARGV2}/${classname}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS
|
||||
create
|
||||
view
|
||||
${inFile}
|
||||
-o
|
||||
${ARGV2}
|
||||
DEPENDS ${cspFile}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM)
|
||||
set(VIEWSRC ${VIEWSRC} ${ARGV2}/${classname}.cc)
|
||||
endif()
|
||||
endforeach()
|
||||
target_sources(${ARGV0} PRIVATE ${VIEWSRC})
|
||||
endfunction(drogon_create_views)
|
37
cmake/Packages.cmake
Normal file
37
cmake/Packages.cmake
Normal file
@ -0,0 +1,37 @@
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_PACKAGE_CONTACT "https://github.com/drogonframework/drogon")
|
||||
|
||||
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
|
||||
set(CPACK_PACKAGE_VERSION "${DROGON_VERSION}")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C++14/17 based HTTP web application framework running on Linux/macOS/Unix/Windows")
|
||||
|
||||
# DEB
|
||||
# Figure out dependencies automatically.
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
|
||||
# Should be set automatically, but it is not.
|
||||
execute_process(COMMAND dpkg --print-architecture
|
||||
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
# The default does not produce valid Debian package names.
|
||||
set(CPACK_DEBIAN_FILE_NAME
|
||||
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
|
||||
|
||||
# RPM
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
|
||||
|
||||
# Figure out dependencies automatically.
|
||||
set(CPACK_RPM_PACKAGE_AUTOREQ ON)
|
||||
|
||||
# Should be set automatically, but it is not.
|
||||
execute_process(COMMAND uname -m
|
||||
OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
set(CPACK_PACKAGE_FILE_NAME
|
||||
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
|
||||
|
||||
include(CPack)
|
79
cmake/ParseAndAddDrogonTests.cmake
Normal file
79
cmake/ParseAndAddDrogonTests.cmake
Normal file
@ -0,0 +1,79 @@
|
||||
#==================================================================================================#
|
||||
# Adapted and re-written from Catch2 to work with Drogon Test #
|
||||
# #
|
||||
# Usage #
|
||||
# 1. make sure this module is in the path or add this otherwise: #
|
||||
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") #
|
||||
# 2. make sure that you've enabled testing option for the project by the call: #
|
||||
# enable_testing() #
|
||||
# 3. add the lines to the script for testing target (sample CMakeLists.txt): #
|
||||
# project(testing_target) #
|
||||
# enable_testing() #
|
||||
# #
|
||||
# file(GLOB SOURCE_FILES "*.cpp") #
|
||||
# add_executable(${PROJECT_NAME} ${SOURCE_FILES}) #
|
||||
# #
|
||||
# include(ParseAndAddDrogonTests) #
|
||||
# ParseAndAddDrogonTests(${PROJECT_NAME}) #
|
||||
#==================================================================================================#
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.31)
|
||||
|
||||
# This removes the contents between
|
||||
# - block comments (i.e. /* ... */)
|
||||
# - full line comments (i.e. // ... )
|
||||
# contents have been read into '${CppCode}'.
|
||||
# !keep partial line comments
|
||||
function(RemoveComments CppCode)
|
||||
string(ASCII 2 CMakeBeginBlockComment)
|
||||
string(ASCII 3 CMakeEndBlockComment)
|
||||
string(REGEX REPLACE "/\\*" "${CMakeBeginBlockComment}" ${CppCode} "${${CppCode}}")
|
||||
string(REGEX REPLACE "\\*/" "${CMakeEndBlockComment}" ${CppCode} "${${CppCode}}")
|
||||
string(REGEX REPLACE "${CMakeBeginBlockComment}[^${CMakeEndBlockComment}]*${CMakeEndBlockComment}" "" ${CppCode} "${${CppCode}}")
|
||||
string(REGEX REPLACE "\n[ \t]*//+[^\n]+" "\n" ${CppCode} "${${CppCode}}")
|
||||
|
||||
set(${CppCode} "${${CppCode}}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Worker function
|
||||
function(ParseFile SourceFile TestTarget)
|
||||
set(FullSourcePath ${CMAKE_CURRENT_SOURCE_DIR}/${SourceFile})
|
||||
if(NOT EXISTS ${FullSourcePath})
|
||||
return()
|
||||
endif()
|
||||
file(STRINGS ${FullSourcePath} Contents NEWLINE_CONSUME)
|
||||
|
||||
# Remove block and fullline comments
|
||||
RemoveComments(Contents)
|
||||
|
||||
# Find definition of test names
|
||||
string(REGEX MATCHALL "[ \t]*DROGON_TEST[ \t]*\\\([a-zA-Z0-9_]+\\\)" Tests "${Contents}")
|
||||
|
||||
foreach(TestLine ${Tests})
|
||||
# Strip newlines
|
||||
string(REGEX REPLACE "\\\\\n|\n" "" TestLine "${TestLine}")
|
||||
|
||||
# Get the name of the test
|
||||
string(REGEX REPLACE "[ \t]*DROGON_TEST[ \t]*" "" TestLine "${TestLine}")
|
||||
string(REGEX MATCHALL "[a-zA-Z0-9_]+" TestName "${TestLine}")
|
||||
|
||||
# Validate that a test name and tags have been provided
|
||||
list(LENGTH TestName TestNameLength)
|
||||
if(NOT TestNameLength EQUAL 1)
|
||||
message(FATAL_ERROR "${TestName} in ${SourceFile} is not a valid test name."
|
||||
" Either a bug in the Drogon Test CMake parser or a bug in the test itself")
|
||||
endif()
|
||||
|
||||
# Add the test and set its properties
|
||||
add_test(NAME "${TestName}" COMMAND ${TestTarget} -r ${TestName} ${AdditionalCatchParameters})
|
||||
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# entry point
|
||||
function(ParseAndAddDrogonTests TestTarget)
|
||||
get_target_property(SourceFiles ${TestTarget} SOURCES)
|
||||
foreach(SourceFile ${SourceFiles})
|
||||
ParseFile(${SourceFile} ${TestTarget})
|
||||
endforeach()
|
||||
endfunction()
|
@ -14,9 +14,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
find_dependency(Jsoncpp REQUIRED)
|
||||
find_dependency(Trantor REQUIRED)
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32)
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" AND NOT WIN32)
|
||||
find_dependency(UUID REQUIRED)
|
||||
endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT WIN32)
|
||||
endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" AND NOT WIN32)
|
||||
find_dependency(ZLIB REQUIRED)
|
||||
if(@pg_FOUND@)
|
||||
find_dependency(pg)
|
||||
@ -27,21 +27,34 @@ endif()
|
||||
if(@MySQL_FOUND@)
|
||||
find_dependency(MySQL)
|
||||
endif()
|
||||
if(@Boost_FOUND@)
|
||||
find_dependency(Boost)
|
||||
endif()
|
||||
if(@Brotli_FOUND@)
|
||||
find_dependency(Brotli)
|
||||
endif()
|
||||
if(@COZ-PROFILER_FOUND@)
|
||||
find_dependency(coz-profiler)
|
||||
endif()
|
||||
if(@Hiredis_FOUND@)
|
||||
find_dependency(Hiredis)
|
||||
endif()
|
||||
if(@yaml-cpp_FOUND@)
|
||||
find_dependency(yaml-cpp)
|
||||
endif()
|
||||
if(@BUILD_SHARED_LIBS@)
|
||||
find_dependency(Threads)
|
||||
endif()
|
||||
if(@HAS_STD_FILESYSTEM_PATH@)
|
||||
find_dependency(Filesystem)
|
||||
find_package(Filesystem COMPONENTS Final REQUIRED)
|
||||
endif()
|
||||
|
||||
|
||||
# Our library dependencies (contains definitions for IMPORTED targets)
|
||||
|
||||
get_filename_component(DROGON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
if(NOT TARGET Drogon::Drogon)
|
||||
include("${DROGON_CMAKE_DIR}/DrogonTargets.cmake")
|
||||
include("${DROGON_CMAKE_DIR}/DrogonUtilities.cmake")
|
||||
include("${DROGON_CMAKE_DIR}/ParseAndAddDrogonTests.cmake")
|
||||
endif()
|
||||
|
||||
get_target_property(DROGON_INCLUDE_DIRS Drogon::Drogon INTERFACE_INCLUDE_DIRECTORIES)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#cmakedefine01 LIBPQ_SUPPORTS_BATCH_MODE
|
||||
#cmakedefine01 USE_MYSQL
|
||||
#cmakedefine01 USE_SQLITE3
|
||||
#cmakedefine01 HAS_STD_FILESYSTEM_PATH
|
||||
#cmakedefine OpenSSL_FOUND
|
||||
#cmakedefine Boost_FOUND
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define MAJOR @DROGON_MAJOR_VERSION@
|
||||
#define MINOR @DROGON_MINOR_VERSION@
|
||||
#define PATCH @DROGON_PATCH_VERSION@
|
||||
|
7
cmake/tests/check_has_std_filesystem_path.cc
Executable file
7
cmake/tests/check_has_std_filesystem_path.cc
Executable file
@ -0,0 +1,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::filesystem::path aPath("../");
|
||||
return 0;
|
||||
}
|
@ -2,11 +2,8 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
PQisInBatchMode(NULL);
|
||||
PQbatchIsAborted(NULL);
|
||||
PQqueriesInBatch(NULL);
|
||||
PQbeginBatchMode(NULL);
|
||||
PQendBatchMode(NULL);
|
||||
PQsendEndBatch(NULL);
|
||||
PQgetNextQuery(NULL);
|
||||
PQenterPipelineMode(NULL);
|
||||
PQexitPipelineMode(NULL);
|
||||
PQpipelineSync(NULL);
|
||||
PQpipelineStatus(NULL);
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_path(BROTLI_INCLUDE_DIR "brotli/decode.h")
|
||||
|
||||
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon)
|
||||
find_library(BROTLIDEC_LIBRARY NAMES brotlidec)
|
||||
find_library(BROTLIENC_LIBRARY NAMES brotlienc)
|
||||
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon brotlicommon-static)
|
||||
find_library(BROTLIDEC_LIBRARY NAMES brotlidec brotlidec-static)
|
||||
find_library(BROTLIENC_LIBRARY NAMES brotlienc brotlienc-static)
|
||||
|
||||
find_package_handle_standard_args(Brotli
|
||||
REQUIRED_VARS
|
||||
@ -37,8 +37,8 @@ find_package_handle_standard_args(Brotli
|
||||
"Could NOT find BROTLI")
|
||||
|
||||
set(BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR})
|
||||
set(BROTLI_LIBRARIES ${BROTLICOMMON_LIBRARY} ${BROTLIDEC_LIBRARY}
|
||||
${BROTLIENC_LIBRARY})
|
||||
set(BROTLI_LIBRARIES ${BROTLIDEC_LIBRARY}
|
||||
${BROTLIENC_LIBRARY} ${BROTLICOMMON_LIBRARY})
|
||||
|
||||
if(Brotli_FOUND)
|
||||
add_library(Brotli_lib INTERFACE IMPORTED)
|
||||
|
261
cmake_modules/FindFilesystem.cmake
Normal file
261
cmake_modules/FindFilesystem.cmake
Normal file
@ -0,0 +1,261 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
|
||||
FindFilesystem
|
||||
##############
|
||||
|
||||
This module supports the C++17 standard library's filesystem utilities. Use the
|
||||
:imp-target:`std::filesystem` imported target to
|
||||
|
||||
Options
|
||||
*******
|
||||
|
||||
The ``COMPONENTS`` argument to this module supports the following values:
|
||||
|
||||
.. find-component:: Experimental
|
||||
:name: fs.Experimental
|
||||
|
||||
Allows the module to find the "experimental" Filesystem TS version of the
|
||||
Filesystem library. This is the library that should be used with the
|
||||
``std::experimental::filesystem`` namespace.
|
||||
|
||||
.. find-component:: Final
|
||||
:name: fs.Final
|
||||
|
||||
Finds the final C++17 standard version of the filesystem library.
|
||||
|
||||
If no components are provided, behaves as if the
|
||||
:find-component:`fs.Final` component was specified.
|
||||
|
||||
If both :find-component:`fs.Experimental` and :find-component:`fs.Final` are
|
||||
provided, first looks for ``Final``, and falls back to ``Experimental`` in case
|
||||
of failure. If ``Final`` is found, :imp-target:`std::filesystem` and all
|
||||
:ref:`variables <fs.variables>` will refer to the ``Final`` version.
|
||||
|
||||
|
||||
Imported Targets
|
||||
****************
|
||||
|
||||
.. imp-target:: std::filesystem
|
||||
|
||||
The ``std::filesystem`` imported target is defined when any requested
|
||||
version of the C++ filesystem library has been found, whether it is
|
||||
*Experimental* or *Final*.
|
||||
|
||||
If no version of the filesystem library is available, this target will not
|
||||
be defined.
|
||||
|
||||
.. note::
|
||||
This target has ``cxx_std_17`` as an ``INTERFACE``
|
||||
:ref:`compile language standard feature <req-lang-standards>`. Linking
|
||||
to this target will automatically enable C++17 if no later standard
|
||||
version is already required on the linking target.
|
||||
|
||||
|
||||
.. _fs.variables:
|
||||
|
||||
Variables
|
||||
*********
|
||||
|
||||
.. variable:: CXX_FILESYSTEM_IS_EXPERIMENTAL
|
||||
|
||||
Set to ``TRUE`` when the :find-component:`fs.Experimental` version of C++
|
||||
filesystem library was found, otherwise ``FALSE``.
|
||||
|
||||
.. variable:: CXX_FILESYSTEM_HAVE_FS
|
||||
|
||||
Set to ``TRUE`` when a filesystem header was found.
|
||||
|
||||
.. variable:: CXX_FILESYSTEM_HEADER
|
||||
|
||||
Set to either ``filesystem`` or ``experimental/filesystem`` depending on
|
||||
whether :find-component:`fs.Final` or :find-component:`fs.Experimental` was
|
||||
found.
|
||||
|
||||
.. variable:: CXX_FILESYSTEM_NAMESPACE
|
||||
|
||||
Set to either ``std::filesystem`` or ``std::experimental::filesystem``
|
||||
depending on whether :find-component:`fs.Final` or
|
||||
:find-component:`fs.Experimental` was found.
|
||||
|
||||
|
||||
Examples
|
||||
********
|
||||
|
||||
Using `find_package(Filesystem)` with no component arguments:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
find_package(Filesystem REQUIRED)
|
||||
|
||||
add_executable(my-program main.cpp)
|
||||
target_link_libraries(my-program PRIVATE std::filesystem)
|
||||
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
|
||||
if(TARGET std::filesystem)
|
||||
# This module has already been processed. Don't do it again.
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Ignore filesystem check if version too low
|
||||
if(CMAKE_VERSION VERSION_LESS 3.10)
|
||||
set(CXX_FILESYSTEM_HAVE_FS FALSE CACHE BOOL "TRUE if we have the C++ filesystem headers")
|
||||
set(Filesystem_FOUND FALSE CACHE BOOL "TRUE if we can run a program using std::filesystem" FORCE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
include(CMakePushCheckState)
|
||||
include(CheckIncludeFileCXX)
|
||||
|
||||
# If we're not cross-compiling, try to run test executables.
|
||||
# Otherwise, assume that compile + link is a sufficient check.
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
include(CheckCXXSourceCompiles)
|
||||
macro(_cmcm_check_cxx_source code var)
|
||||
check_cxx_source_compiles("${code}" ${var})
|
||||
endmacro()
|
||||
else()
|
||||
include(CheckCXXSourceRuns)
|
||||
macro(_cmcm_check_cxx_source code var)
|
||||
check_cxx_source_runs("${code}" ${var})
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
cmake_push_check_state()
|
||||
|
||||
set(CMAKE_REQUIRED_QUIET ${Filesystem_FIND_QUIETLY})
|
||||
|
||||
# All of our tests required C++17 or later
|
||||
set(BACKUP_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Normalize and check the component list we were given
|
||||
set(want_components ${Filesystem_FIND_COMPONENTS})
|
||||
if(Filesystem_FIND_COMPONENTS STREQUAL "")
|
||||
set(want_components Final)
|
||||
endif()
|
||||
|
||||
# Warn on any unrecognized components
|
||||
set(extra_components ${want_components})
|
||||
list(REMOVE_ITEM extra_components Final Experimental)
|
||||
foreach(component IN LISTS extra_components)
|
||||
message(WARNING "Extraneous find_package component for Filesystem: ${component}")
|
||||
endforeach()
|
||||
|
||||
# Detect which of Experimental and Final we should look for
|
||||
set(find_experimental TRUE)
|
||||
set(find_final TRUE)
|
||||
if(NOT "Final" IN_LIST want_components)
|
||||
set(find_final FALSE)
|
||||
endif()
|
||||
if(NOT "Experimental" IN_LIST want_components)
|
||||
set(find_experimental FALSE)
|
||||
endif()
|
||||
|
||||
if(find_final)
|
||||
check_include_file_cxx("filesystem" _CXX_FILESYSTEM_HAVE_HEADER)
|
||||
mark_as_advanced(_CXX_FILESYSTEM_HAVE_HEADER)
|
||||
if(_CXX_FILESYSTEM_HAVE_HEADER)
|
||||
# We found the non-experimental header. Don't bother looking for the
|
||||
# experimental one.
|
||||
set(find_experimental FALSE)
|
||||
endif()
|
||||
else()
|
||||
set(_CXX_FILESYSTEM_HAVE_HEADER FALSE)
|
||||
endif()
|
||||
|
||||
if(find_experimental)
|
||||
check_include_file_cxx("experimental/filesystem" _CXX_FILESYSTEM_HAVE_EXPERIMENTAL_HEADER)
|
||||
mark_as_advanced(_CXX_FILESYSTEM_HAVE_EXPERIMENTAL_HEADER)
|
||||
else()
|
||||
set(_CXX_FILESYSTEM_HAVE_EXPERIMENTAL_HEADER FALSE)
|
||||
endif()
|
||||
|
||||
if(_CXX_FILESYSTEM_HAVE_HEADER)
|
||||
set(_have_fs TRUE)
|
||||
set(_fs_header filesystem)
|
||||
set(_fs_namespace std::filesystem)
|
||||
set(_is_experimental FALSE)
|
||||
elseif(_CXX_FILESYSTEM_HAVE_EXPERIMENTAL_HEADER)
|
||||
set(_have_fs TRUE)
|
||||
set(_fs_header experimental/filesystem)
|
||||
set(_fs_namespace std::experimental::filesystem)
|
||||
set(_is_experimental TRUE)
|
||||
else()
|
||||
set(_have_fs FALSE)
|
||||
endif()
|
||||
|
||||
set(CXX_FILESYSTEM_HAVE_FS ${_have_fs} CACHE BOOL "TRUE if we have the C++ filesystem headers")
|
||||
set(CXX_FILESYSTEM_HEADER ${_fs_header} CACHE STRING "The header that should be included to obtain the filesystem APIs")
|
||||
set(CXX_FILESYSTEM_NAMESPACE ${_fs_namespace} CACHE STRING "The C++ namespace that contains the filesystem APIs")
|
||||
set(CXX_FILESYSTEM_IS_EXPERIMENTAL ${_is_experimental} CACHE BOOL "TRUE if the C++ filesystem library is the experimental version")
|
||||
|
||||
set(_found FALSE)
|
||||
|
||||
if(CXX_FILESYSTEM_HAVE_FS)
|
||||
# We have some filesystem library available. Do link checks
|
||||
string(CONFIGURE [[
|
||||
#include <cstdio>
|
||||
#include <@CXX_FILESYSTEM_HEADER@>
|
||||
|
||||
int main() {
|
||||
auto cwd = @CXX_FILESYSTEM_NAMESPACE@::current_path();
|
||||
printf("%s", cwd.generic_string().c_str());
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
]] code @ONLY)
|
||||
|
||||
# HACK: Needed to compile correctly on Yocto Linux
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
|
||||
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
set(CMAKE_REQUIRED_FLAGS ${prev_req_flags} -std=c++17)
|
||||
endif ()
|
||||
# Check a simple filesystem program without any linker flags
|
||||
_cmcm_check_cxx_source("${code}" CXX_FILESYSTEM_NO_LINK_NEEDED)
|
||||
|
||||
set(can_link ${CXX_FILESYSTEM_NO_LINK_NEEDED})
|
||||
|
||||
if(NOT CXX_FILESYSTEM_NO_LINK_NEEDED)
|
||||
set(prev_libraries ${CMAKE_REQUIRED_LIBRARIES})
|
||||
# Add the libstdc++ flag
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${prev_libraries} -lstdc++fs)
|
||||
_cmcm_check_cxx_source("${code}" CXX_FILESYSTEM_STDCPPFS_NEEDED)
|
||||
set(can_link ${CXX_FILESYSTEM_STDCPPFS_NEEDED})
|
||||
if(NOT CXX_FILESYSTEM_STDCPPFS_NEEDED)
|
||||
# Try the libc++ flag
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${prev_libraries} -lc++fs)
|
||||
_cmcm_check_cxx_source("${code}" CXX_FILESYSTEM_CPPFS_NEEDED)
|
||||
set(can_link ${CXX_FILESYSTEM_CPPFS_NEEDED})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(can_link)
|
||||
add_library(std::filesystem INTERFACE IMPORTED)
|
||||
set_property(TARGET std::filesystem APPEND PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_17)
|
||||
set(_found TRUE)
|
||||
|
||||
if(CXX_FILESYSTEM_NO_LINK_NEEDED)
|
||||
# Nothing to add...
|
||||
elseif(CXX_FILESYSTEM_STDCPPFS_NEEDED)
|
||||
set_property(TARGET std::filesystem APPEND PROPERTY INTERFACE_LINK_LIBRARIES -lstdc++fs)
|
||||
elseif(CXX_FILESYSTEM_CPPFS_NEEDED)
|
||||
set_property(TARGET std::filesystem APPEND PROPERTY INTERFACE_LINK_LIBRARIES -lc++fs)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
cmake_pop_check_state()
|
||||
|
||||
set(Filesystem_FOUND ${_found} CACHE BOOL "TRUE if we can run a program using std::filesystem" FORCE)
|
||||
|
||||
if(Filesystem_FIND_REQUIRED AND NOT Filesystem_FOUND)
|
||||
message(FATAL_ERROR "Cannot run simple program using std::filesystem")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD "${BACKUP_CXX_STANDARD}")
|
41
cmake_modules/FindHiredis.cmake
Normal file
41
cmake_modules/FindHiredis.cmake
Normal file
@ -0,0 +1,41 @@
|
||||
# Try to find hiredis
|
||||
# Once done, this will define
|
||||
#
|
||||
# HIREDIS_FOUND - system has hiredis
|
||||
# HIREDIS_INCLUDE_DIRS - hiredis include directories
|
||||
# HIREDIS_LIBRARIES - libraries need to use hiredis
|
||||
|
||||
if (HIREDIS_INCLUDE_DIRS AND HIREDIS_LIBRARIES)
|
||||
set(HIREDIS_FIND_QUIETLY TRUE)
|
||||
set(Hiredis_FOUND TRUE)
|
||||
else ()
|
||||
find_path(
|
||||
HIREDIS_INCLUDE_DIR
|
||||
NAMES hiredis/hiredis.h
|
||||
HINTS ${HIREDIS_ROOT_DIR}
|
||||
PATH_SUFFIXES include)
|
||||
|
||||
find_library(
|
||||
HIREDIS_LIBRARY
|
||||
NAMES hiredis
|
||||
HINTS ${HIREDIS_ROOT_DIR}
|
||||
PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
set(HIREDIS_INCLUDE_DIRS ${HIREDIS_INCLUDE_DIR})
|
||||
set(HIREDIS_LIBRARIES ${HIREDIS_LIBRARY})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
Hiredis DEFAULT_MSG HIREDIS_LIBRARY HIREDIS_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(HIREDIS_LIBRARY HIREDIS_INCLUDE_DIR)
|
||||
endif ()
|
||||
|
||||
if(Hiredis_FOUND)
|
||||
add_library(Hiredis_lib INTERFACE IMPORTED)
|
||||
set_target_properties(Hiredis_lib
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${HIREDIS_INCLUDE_DIRS}"
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
"${HIREDIS_LIBRARIES}")
|
||||
endif(Hiredis_FOUND)
|
@ -44,13 +44,16 @@ if(Jsoncpp_FOUND)
|
||||
message(FATAL_ERROR "Error: jsoncpp lib is too old.....stop")
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
exec_program(
|
||||
cat
|
||||
ARGS
|
||||
"${JSONCPP_INCLUDE_DIRS}/json/version.h |grep JSONCPP_VERSION_STRING|sed s'/.*define/define/'|awk '{printf $3}'|sed s'/\"//g'"
|
||||
OUTPUT_VARIABLE
|
||||
jsoncpp_ver)
|
||||
message(STATUS "jsoncpp verson:" ${jsoncpp_ver})
|
||||
execute_process(
|
||||
COMMAND cat ${JSONCPP_INCLUDE_DIRS}/json/version.h
|
||||
COMMAND grep JSONCPP_VERSION_STRING
|
||||
COMMAND sed -e "s/.*define/define/"
|
||||
COMMAND awk "{ printf \$3 }"
|
||||
COMMAND sed -e "s/\"//g"
|
||||
OUTPUT_VARIABLE jsoncpp_ver)
|
||||
if(NOT Jsoncpp_FIND_QUIETLY)
|
||||
message(STATUS "jsoncpp version:" ${jsoncpp_ver})
|
||||
endif()
|
||||
if(jsoncpp_ver LESS 1.7)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
@ -58,7 +61,9 @@ if(Jsoncpp_FOUND)
|
||||
)
|
||||
endif(jsoncpp_ver LESS 1.7)
|
||||
endif()
|
||||
add_library(Jsoncpp_lib INTERFACE IMPORTED)
|
||||
if (NOT TARGET Jsoncpp_lib)
|
||||
add_library(Jsoncpp_lib INTERFACE IMPORTED)
|
||||
endif()
|
||||
set_target_properties(Jsoncpp_lib
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${JSONCPP_INCLUDE_DIRS}"
|
||||
|
@ -27,21 +27,49 @@
|
||||
# ##############################################################################
|
||||
|
||||
# -------------- FIND MYSQL_INCLUDE_DIRS ------------------
|
||||
find_path(MYSQL_INCLUDE_DIRS
|
||||
find_path(MARIADB_INCLUDE_DIRS
|
||||
NAMES mysql.h
|
||||
PATH_SUFFIXES mysql
|
||||
PATH_SUFFIXES mariadb
|
||||
PATHS /usr/include/mysql
|
||||
/usr/local/include/mysql
|
||||
/usr/include/mariadb
|
||||
/usr/local/include/mariadb
|
||||
/opt/mysql/mysql/include
|
||||
/opt/mysql/mysql/include/mysql
|
||||
/opt/mysql/include
|
||||
/opt/local/include/mysql5
|
||||
/usr/local/mysql/include
|
||||
/usr/local/mysql/include/mysql
|
||||
/usr/local/mariadb/include
|
||||
/usr/local/mariadb/include/mariadb
|
||||
/opt/rh/rh-mariadb105/root/usr/include
|
||||
/opt/rh/rh-mariadb105/root/usr/include/mysql
|
||||
$ENV{ProgramFiles}/MySQL/*/include
|
||||
$ENV{SystemDrive}/MySQL/*/include)
|
||||
|
||||
if(EXISTS "${MYSQL_INCLUDE_DIRS}/mysql.h")
|
||||
find_path(MYSQL_INCLUDE_DIRS
|
||||
NAMES mysql.h
|
||||
PATH_SUFFIXES mysql
|
||||
PATHS /usr/include/mysql
|
||||
/usr/local/include/mysql
|
||||
/usr/include/mariadb
|
||||
/usr/local/include/mariadb
|
||||
/opt/mysql/mysql/include
|
||||
/opt/mysql/mysql/include/mysql
|
||||
/opt/mysql/include
|
||||
/opt/local/include/mysql5
|
||||
/usr/local/mysql/include
|
||||
/usr/local/mysql/include/mysql
|
||||
/usr/local/mariadb/include
|
||||
/usr/local/mariadb/include/mariadb
|
||||
/opt/rh/rh-mariadb105/root/usr/include
|
||||
/opt/rh/rh-mariadb105/root/usr/include/mysql
|
||||
$ENV{ProgramFiles}/MySQL/*/include
|
||||
$ENV{SystemDrive}/MySQL/*/include)
|
||||
|
||||
if(EXISTS "${MARIADB_INCLUDE_DIRS}/mysql.h")
|
||||
set(MYSQL_INCLUDE_DIRS ${MARIADB_INCLUDE_DIRS})
|
||||
elseif(EXISTS "${MYSQL_INCLUDE_DIRS}/mysql.h")
|
||||
|
||||
elseif(EXISTS "${MYSQL_INCLUDE_DIRS}/mysql/mysql.h")
|
||||
set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDE_DIRS}/mysql)
|
||||
@ -71,15 +99,18 @@ if(WIN32)
|
||||
$ENV{SystemDrive}/MySQL/*/lib/${libsuffixDist})
|
||||
else(WIN32)
|
||||
find_library(MYSQL_LIBRARIES
|
||||
NAMES mysqlclient_r mariadbclient
|
||||
NAMES mysqlclient_r mariadbclient mariadb
|
||||
PATHS /usr/lib/mysql
|
||||
/usr/lib/mariadb
|
||||
/usr/local/lib/mysql
|
||||
/usr/local/lib/mariadb
|
||||
/usr/local/mysql/lib
|
||||
/usr/local/mysql/lib/mysql
|
||||
/opt/local/mysql5/lib
|
||||
/opt/local/lib/mysql5/mysql
|
||||
/opt/mysql/mysql/lib/mysql
|
||||
/opt/mysql/lib/mysql)
|
||||
/opt/mysql/lib/mysql
|
||||
/opt/rh/rh-mariadb105/root/usr/lib64)
|
||||
endif(WIN32)
|
||||
|
||||
if(MYSQL_INCLUDE_DIRS AND MYSQL_LIBRARIES)
|
||||
|
@ -14,7 +14,7 @@
|
||||
if(UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
|
||||
# in cache already
|
||||
set(UUID_FOUND TRUE)
|
||||
else(UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
|
||||
else()
|
||||
find_path(
|
||||
UUID_INCLUDE_DIR
|
||||
NAMES uuid.h
|
||||
@ -76,34 +76,34 @@ else(UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
|
||||
/opt/lib
|
||||
/usr/freeware/lib64)
|
||||
|
||||
if(NOT UUID_LIBRARY AND BSD)
|
||||
if(NOT UUID_LIBRARY AND (BSD OR APPLE))
|
||||
set(UUID_LIBRARY "")
|
||||
endif(NOT UUID_LIBRARY AND BSD)
|
||||
endif()
|
||||
|
||||
set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR})
|
||||
set(UUID_LIBRARIES ${UUID_LIBRARY})
|
||||
|
||||
if(UUID_INCLUDE_DIRS)
|
||||
if(BSD OR UUID_LIBRARIES)
|
||||
if((BSD OR APPLE) OR UUID_LIBRARIES)
|
||||
set(UUID_FOUND TRUE)
|
||||
endif(BSD OR UUID_LIBRARIES)
|
||||
endif(UUID_INCLUDE_DIRS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(UUID_FOUND)
|
||||
if(NOT UUID_FIND_QUIETLY)
|
||||
message(STATUS "Found UUID: ${UUID_LIBRARIES}")
|
||||
endif(NOT UUID_FIND_QUIETLY)
|
||||
else(UUID_FOUND)
|
||||
endif()
|
||||
else()
|
||||
if(UUID_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find UUID")
|
||||
endif(UUID_FIND_REQUIRED)
|
||||
endif(UUID_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced
|
||||
# view
|
||||
mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES)
|
||||
|
||||
endif(UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
|
||||
endif()
|
||||
|
||||
if(UUID_FOUND)
|
||||
add_library(UUID_lib INTERFACE IMPORTED)
|
||||
@ -112,7 +112,7 @@ if(UUID_FOUND)
|
||||
"${UUID_INCLUDE_DIRS}"
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
"${UUID_LIBRARIES}")
|
||||
else(UUID_FOUND)
|
||||
else()
|
||||
set(UUID_LIBRARIES)
|
||||
set(UUID_INCLUDE_DIRS)
|
||||
endif(UUID_FOUND)
|
||||
endif()
|
||||
|
16
conanfile.txt
Normal file
16
conanfile.txt
Normal file
@ -0,0 +1,16 @@
|
||||
[requires]
|
||||
jsoncpp/1.9.4
|
||||
zlib/1.2.11
|
||||
gtest/1.10.0
|
||||
sqlite3/3.40.1
|
||||
#libpq/13.2
|
||||
openssl/1.1.1t
|
||||
hiredis/1.0.0
|
||||
brotli/1.0.9
|
||||
|
||||
[generators]
|
||||
CMakeToolchain
|
||||
|
||||
[options]
|
||||
|
||||
[imports]
|
@ -2,10 +2,15 @@
|
||||
*/
|
||||
{
|
||||
/*
|
||||
//ssl:The global ssl files setting
|
||||
//ssl:The global SSL settings. "key" and "cert" are the path to the SSL key and certificate. While
|
||||
// "conf" is an array of 1 or 2-element tuples that supplies file style options for `SSL_CONF_cmd`.
|
||||
"ssl": {
|
||||
"cert": "../../trantor/trantor/tests/server.pem",
|
||||
"key": "../../trantor/trantor/tests/server.pem"
|
||||
"cert": "../../trantor/trantor/tests/server.crt",
|
||||
"key": "../../trantor/trantor/tests/server.key",
|
||||
"conf": [
|
||||
//["Options", "-SessionTicket"],
|
||||
//["Options", "Compression"]
|
||||
]
|
||||
},
|
||||
"listeners": [
|
||||
{
|
||||
@ -23,13 +28,18 @@
|
||||
//cert,key: Cert file path and key file path, empty by default,
|
||||
//if empty, use the global setting
|
||||
"cert": "",
|
||||
"key": ""
|
||||
"key": "",
|
||||
//use_old_tls: enable the TLS1.0/1.1, false by default
|
||||
"use_old_tls": false,
|
||||
"ssl_conf": [
|
||||
//["MinProtocol", "TLSv1.3"]
|
||||
]
|
||||
}
|
||||
],
|
||||
"db_clients": [
|
||||
{
|
||||
//name: Name of the client,'default' by default
|
||||
//"name":"",
|
||||
"name": "default",
|
||||
//rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
|
||||
"rdbms": "postgresql",
|
||||
//filename: Sqlite3 db file name
|
||||
@ -50,30 +60,76 @@
|
||||
//client_encoding: The character set used by the client. it is empty string by default which
|
||||
//means use the default character set.
|
||||
//"client_encoding": "",
|
||||
//connection_number: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
//number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
//connections per IO thread, otherwise it is the total number of all connections.
|
||||
"connection_number": 1
|
||||
"number_of_connections": 1,
|
||||
//timeout: -1.0 by default, in seconds, the timeout for executing a SQL query.
|
||||
//zero or negative value means no timeout.
|
||||
"timeout": -1.0,
|
||||
//auto_batch: this feature is only available for the PostgreSQL driver(version >= 14.0), see
|
||||
//the wiki for more details.
|
||||
"auto_batch": false
|
||||
//connect_options: extra options for the connection. Only works for PostgreSQL now.
|
||||
//For more information, see https://www.postgresql.org/docs/16/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
|
||||
//"connect_options": { "statement_timeout": "1s" }
|
||||
}
|
||||
],
|
||||
"redis_clients": [
|
||||
{
|
||||
//name: Name of the client,'default' by default
|
||||
"name": "default",
|
||||
//host: Server IP, 127.0.0.1 by default
|
||||
"host": "127.0.0.1",
|
||||
//port: Server port, 6379 by default
|
||||
"port": 6379,
|
||||
//username: '' by default which means 'default' in redis ACL
|
||||
"username": "",
|
||||
//passwd: '' by default
|
||||
"passwd": "",
|
||||
//db index: 0 by default
|
||||
"db": 0,
|
||||
//is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
//any synchronous interface of it.
|
||||
"is_fast": false,
|
||||
//number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
//connections per IO thread, otherwise it is the total number of all connections.
|
||||
"number_of_connections": 1,
|
||||
//timeout: -1.0 by default, in seconds, the timeout for executing a command.
|
||||
//zero or negative value means no timeout.
|
||||
"timeout": -1.0
|
||||
}
|
||||
],*/
|
||||
"app": {
|
||||
//threads_num: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
//number_of_threads: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
//is the number of CPU cores
|
||||
"threads_num": 1,
|
||||
"number_of_threads": 1,
|
||||
//enable_session: False by default
|
||||
"enable_session": true,
|
||||
"session_timeout": 0,
|
||||
//document_root: Root path of HTTP document, defaut path is ./
|
||||
//string value of SameSite attribute of the Set-Cookie HTTP response header
|
||||
//valid value is either 'Null' (default), 'Lax', 'Strict' or 'None'
|
||||
"session_same_site": "Null",
|
||||
//session_cookie_key: The cookie key of the session, "JSESSIONID" by default
|
||||
"session_cookie_key": "JSESSIONID",
|
||||
//session_max_age: The max age of the session cookie, -1 by default
|
||||
"session_max_age": -1,
|
||||
//document_root: Root path of HTTP document, default path is ./
|
||||
"document_root": "./",
|
||||
//home_page: Set the HTML file of the home page, the default value is "index.html"
|
||||
//If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
|
||||
//to the request for "/".
|
||||
"home_page": "index.html",
|
||||
//use_implicit_page: enable implicit pages if true, true by default
|
||||
"use_implicit_page": true,
|
||||
//implicit_page: Set the file which would the server access in a directory that a user accessed.
|
||||
//For example, by default, http://localhost/a-directory resolves to http://localhost/a-directory/index.html.
|
||||
"implicit_page": "index.html",
|
||||
//static_file_headers: Headers for static files
|
||||
/*"static_file_headers": [
|
||||
{
|
||||
{
|
||||
"name": "field-name",
|
||||
"value": "field-value"
|
||||
}
|
||||
}
|
||||
],*/
|
||||
//upload_path: The path to save the uploaded file. "uploads" by default.
|
||||
//If the path isn't prefixed with /, ./ or ../,
|
||||
@ -96,32 +152,42 @@
|
||||
"xap",
|
||||
"apk",
|
||||
"cur",
|
||||
"xml"
|
||||
"xml",
|
||||
"webp",
|
||||
"svg"
|
||||
],
|
||||
// mime: A dictionary that extends the internal MIME type support. Maps extensions into new MIME types
|
||||
// note: This option only adds MIME to the sever. `file_types` above have to be set for the server to serve them.
|
||||
"mime": {
|
||||
// "text/markdown": "md",
|
||||
// "text/gemini": ["gmi", "gemini"]
|
||||
},
|
||||
//locations: An array of locations of static files for GET requests.
|
||||
"locations": [{
|
||||
//uri_prefix: The URI prefix of the location prefixed with "/", the default value is "" that disables the location.
|
||||
//"uri_prefix": "/.well-known/acme-challenge/",
|
||||
//default_content_type: The default content type of the static files without
|
||||
//an extension. empty string by default.
|
||||
"default_content_type": "text/plain",
|
||||
//alias: The location in file system, if it is prefixed with "/", it
|
||||
//presents an absolute path, otherwise it presents a relative path to
|
||||
//the document_root path.
|
||||
//The default value is "" which means use the document root path as the location base path.
|
||||
"alias": "",
|
||||
//is_case_sensitive: indicates whether the URI prefix is case sensitive.
|
||||
"is_case_sensitive": false,
|
||||
//allow_all: true by default. If it is set to false, only static files with a valid extension can be accessed.
|
||||
"allow_all": true,
|
||||
//is_recursive: true by default. If it is set to false, files in sub directories can't be accessed.
|
||||
"is_recursive": true,
|
||||
//filters: string array, the filters applied to the location.
|
||||
"filters": []
|
||||
}],
|
||||
//max_connections: maximum connections number,100000 by default
|
||||
"locations": [
|
||||
{
|
||||
//uri_prefix: The URI prefix of the location prefixed with "/", the default value is "" that disables the location.
|
||||
//"uri_prefix": "/.well-known/acme-challenge/",
|
||||
//default_content_type: The default content type of the static files without
|
||||
//an extension. empty string by default.
|
||||
"default_content_type": "text/plain",
|
||||
//alias: The location in file system, if it is prefixed with "/", it
|
||||
//presents an absolute path, otherwise it presents a relative path to
|
||||
//the document_root path.
|
||||
//The default value is "" which means use the document root path as the location base path.
|
||||
"alias": "",
|
||||
//is_case_sensitive: indicates whether the URI prefix is case sensitive.
|
||||
"is_case_sensitive": false,
|
||||
//allow_all: true by default. If it is set to false, only static files with a valid extension can be accessed.
|
||||
"allow_all": true,
|
||||
//is_recursive: true by default. If it is set to false, files in sub directories can't be accessed.
|
||||
"is_recursive": true,
|
||||
//filters: string array, the filters applied to the location.
|
||||
"filters": []
|
||||
}
|
||||
],
|
||||
//max_connections: maximum number of connections, 100000 by default
|
||||
"max_connections": 100000,
|
||||
//max_connections_per_ip: maximum connections number per clinet,0 by default which means no limit
|
||||
//max_connections_per_ip: maximum number of connections per client, 0 by default which means no limit
|
||||
"max_connections_per_ip": 0,
|
||||
//Load_dynamic_views: False by default, when set to true, drogon
|
||||
//compiles and loads dynamically "CSP View Files" in directories defined
|
||||
@ -136,10 +202,23 @@
|
||||
//files is the path where the csp files locate. If the path isn't prefixed with /, it is relative
|
||||
//path of the current working directory.
|
||||
"dynamic_views_output_path": "",
|
||||
//json_parser_stack_limit: 1000 by default, the maximum number of stack depth when reading a json string by the jsoncpp library.
|
||||
"json_parser_stack_limit": 1000,
|
||||
//enable_unicode_escaping_in_json: true by default, enable unicode escaping in json.
|
||||
"enable_unicode_escaping_in_json": true,
|
||||
//float_precision_in_json: set precision of float number in json.
|
||||
"float_precision_in_json": {
|
||||
//precision: 0 by default, 0 means use the default precision of the jsoncpp lib.
|
||||
"precision": 0,
|
||||
//precision_type: must be "significant" or "decimal", defaults to "significant" that means
|
||||
//setting max number of significant digits in string, "decimal" means setting max number of
|
||||
//digits after "." in string
|
||||
"precision_type": "significant"
|
||||
},
|
||||
//log: Set log output, drogon output logs to stdout by default
|
||||
"log": {
|
||||
//use_spdlog: Use spdlog library to log
|
||||
"use_spdlog": false,
|
||||
//log_path: Log file path,empty by default,in which case,logs are output to the stdout
|
||||
//"log_path": "./",
|
||||
//logfile_base_name: Log file base name,empty by default which means drogon names logfile as
|
||||
@ -148,12 +227,19 @@
|
||||
//log_size_limit: 100000000 bytes by default,
|
||||
//When the log file size reaches "log_size_limit", the log file is switched.
|
||||
"log_size_limit": 100000000,
|
||||
//max_files: 0 by default,
|
||||
//When the number of old log files exceeds "max_files", the oldest file will be deleted. 0 means never delete.
|
||||
"max_files": 0,
|
||||
//log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
|
||||
//The TRACE level is only valid when built in DEBUG mode.
|
||||
"log_level": "DEBUG"
|
||||
"log_level": "DEBUG",
|
||||
//display_local_time: false by default, if true, the log time is displayed in local time
|
||||
"display_local_time": false
|
||||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//handle_sig_term: True by default
|
||||
"handle_sig_term": true,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if true, the program
|
||||
@ -167,17 +253,19 @@
|
||||
//0 means cache forever, the negative value means no cache
|
||||
"static_files_cache_time": 5,
|
||||
//simple_controllers_map: Used to configure mapping from path to simple controller
|
||||
"simple_controllers_map": [{
|
||||
"path": "/path/name",
|
||||
"controller": "controllerClassName",
|
||||
"http_methods": [
|
||||
"get",
|
||||
"post"
|
||||
],
|
||||
"filters": [
|
||||
"FilterClassName"
|
||||
]
|
||||
}],
|
||||
//"simple_controllers_map": [
|
||||
// {
|
||||
// "path": "/path/name",
|
||||
// "controller": "controllerClassName",
|
||||
// "http_methods": [
|
||||
// "get",
|
||||
// "post"
|
||||
// ],
|
||||
// "filters": [
|
||||
// "FilterClassName"
|
||||
// ]
|
||||
// }
|
||||
//],
|
||||
//idle_connection_timeout: Defaults to 60 seconds, the lifetime
|
||||
//of the connection without read or write
|
||||
"idle_connection_timeout": 60,
|
||||
@ -215,28 +303,57 @@
|
||||
"client_max_memory_body_size": "64K",
|
||||
//client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
|
||||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
"client_max_websocket_message_size": "128K"
|
||||
"client_max_websocket_message_size": "128K",
|
||||
//reuse_port: Defaults to false, users can run multiple processes listening on the same port at the same time.
|
||||
"reuse_port": false,
|
||||
// enabled_compressed_request: Defaults to false. If true the server will automatically decompress compressed request bodies.
|
||||
// Currently only gzip and br are supported. Note: max_memory_body_size and max_body_size applies twice for compressed requests.
|
||||
// Once when receiving and once when decompressing. i.e. if the decompressed body is larger than max_body_size, the request
|
||||
// will be rejected.
|
||||
"enabled_compressed_request": false,
|
||||
// enable_request_stream: Defaults to false. If true the server will enable stream mode for http requests.
|
||||
// See the wiki for more details.
|
||||
"enable_request_stream": false,
|
||||
},
|
||||
//plugins: Define all plugins running in the application
|
||||
"plugins": [{
|
||||
//name: The class name of the plugin
|
||||
//"name": "drogon::plugin::SecureSSLRedirector",
|
||||
//dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
"dependencies": [],
|
||||
//config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
//It can be commented out
|
||||
"config": {
|
||||
"ssl_redirect_exempt": [".*\\.jpg"],
|
||||
"secure_ssl_host": "localhost:8849"
|
||||
"plugins": [
|
||||
{
|
||||
//name: The class name of the plugin
|
||||
"name": "drogon::plugin::PromExporter",
|
||||
//dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
"dependencies": [],
|
||||
//config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
//It can be commented out
|
||||
"config": {
|
||||
"path": "/metrics"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drogon::plugin::AccessLogger",
|
||||
"dependencies": [],
|
||||
"config": {
|
||||
"use_spdlog": false,
|
||||
"log_path": "",
|
||||
"log_format": "",
|
||||
"log_file": "access.log",
|
||||
"log_size_limit": 0,
|
||||
"use_local_time": true,
|
||||
"log_index": 0,
|
||||
// "show_microseconds": true,
|
||||
// "custom_time_format": "",
|
||||
// "use_real_ip": false
|
||||
}
|
||||
}
|
||||
}],
|
||||
],
|
||||
//custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method.
|
||||
"custom_config": {
|
||||
"realm": "drogonRealm",
|
||||
"opaque": "drogonOpaque",
|
||||
"credentials": [{
|
||||
"user": "drogon",
|
||||
"password": "dr0g0n"
|
||||
}]
|
||||
"credentials": [
|
||||
{
|
||||
"user": "drogon",
|
||||
"password": "dr0g0n"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
318
config.example.yaml
Normal file
318
config.example.yaml
Normal file
@ -0,0 +1,318 @@
|
||||
# This is a YAML format configuration file
|
||||
|
||||
# ssl:The global SSL settings. "key" and "cert" are the path to the SSL key and certificate. While
|
||||
# "conf" is an array of 1 or 2-element tuples that supplies file style options for `SSL_CONF_cmd`.
|
||||
# ssl:
|
||||
# cert: ../../trantor/trantor/tests/server.crt
|
||||
# key: ../../trantor/trantor/tests/server.key
|
||||
# conf: [
|
||||
# # [Options, -SessionTicket],
|
||||
# # [Options, Compression]
|
||||
# ]
|
||||
# listeners:
|
||||
# # address: Ip address,0.0.0.0 by default
|
||||
# - address: 0.0.0.0
|
||||
# # port: Port number
|
||||
# port: 80
|
||||
# # https: If true, use https for security,false by default
|
||||
# https: false
|
||||
# - address: 0.0.0.0
|
||||
# port: 443
|
||||
# https: true
|
||||
# # cert,key: Cert file path and key file path, empty by default,
|
||||
# # if empty, use the global setting
|
||||
# cert: ''
|
||||
# key: ''
|
||||
# # use_old_tls: enable the TLS1.0/1.1, false by default
|
||||
# use_old_tls: false
|
||||
# ssl_conf: [
|
||||
# # [MinProtocol, TLSv1.3]
|
||||
# ]
|
||||
# db_clients:
|
||||
# # name: Name of the client,'default' by default
|
||||
# - name: default
|
||||
# # rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
|
||||
# rdbms: postgresql
|
||||
# # filename: Sqlite3 db file name
|
||||
# # filename: ''
|
||||
# # host: Server address,localhost by default
|
||||
# host: 127.0.0.1
|
||||
# # port: Server port, 5432 by default
|
||||
# port: 5432
|
||||
# # dbname: Database name
|
||||
# dbname: test
|
||||
# # user: 'postgres' by default
|
||||
# user: ''
|
||||
# # passwd: '' by default
|
||||
# passwd: ''
|
||||
# # is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
# # any synchronous interface of it.
|
||||
# is_fast: false
|
||||
# # client_encoding: The character set used by the client. it is empty string by default which
|
||||
# # means use the default character set.
|
||||
# # client_encoding: ''
|
||||
# # number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
# # connections per IO thread, otherwise it is the total number of all connections.
|
||||
# number_of_connections: 1
|
||||
# # timeout: -1 by default, in seconds, the timeout for executing a SQL query.
|
||||
# # zero or negative value means no timeout.
|
||||
# timeout: -1
|
||||
# # auto_batch: this feature is only available for the PostgreSQL driver(version >= 14.0), see
|
||||
# # the wiki for more details.
|
||||
# auto_batch: false
|
||||
# # connect_options: extra options for the connection. Only works for PostgreSQL now.
|
||||
# # For more information, see https://www.postgresql.org/docs/16/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
|
||||
# # connect_options:
|
||||
# # statement_timeout: '1s'
|
||||
# redis_clients:
|
||||
# # name: Name of the client,'default' by default
|
||||
# - name: default
|
||||
# # host: Server IP, 127.0.0.1 by default
|
||||
# host: 127.0.0.1
|
||||
# # port: Server port, 6379 by default
|
||||
# port: 6379
|
||||
# # username: '' by default which means 'default' in redis ACL
|
||||
# username: ''
|
||||
# # passwd: '' by default
|
||||
# passwd: ''
|
||||
# # db index: 0 by default
|
||||
# db: 0
|
||||
# # is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
# # any synchronous interface of it.
|
||||
# is_fast: false
|
||||
# # number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
# # connections per IO thread, otherwise it is the total number of all connections.
|
||||
# number_of_connections: 1
|
||||
# # timeout: -1.0 by default, in seconds, the timeout for executing a command.
|
||||
# # zero or negative value means no timeout.
|
||||
# timeout: -1
|
||||
app:
|
||||
# number_of_threads: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
# is the number of CPU cores
|
||||
number_of_threads: 1
|
||||
# enable_session: False by default
|
||||
enable_session: true
|
||||
session_timeout: 0
|
||||
# string value of SameSite attribute of the Set-Cookie HTTP response header
|
||||
# valid value is either 'Null' (default), 'Lax', 'Strict' or 'None'
|
||||
session_same_site: 'Null'
|
||||
# session_cookie_key: The cookie key of the session, "JSESSIONID" by default
|
||||
session_cookie_key: 'JSESSIONID'
|
||||
# session_max_age: The max age of the session cookie, -1 by default
|
||||
session_max_age: -1
|
||||
# document_root: Root path of HTTP document, default path is ./
|
||||
document_root: ./
|
||||
# home_page: Set the HTML file of the home page, the default value is "index.html"
|
||||
# If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
|
||||
# to the request for "/".
|
||||
home_page: index.html
|
||||
# use_implicit_page: enable implicit pages if true, true by default
|
||||
use_implicit_page: true
|
||||
# implicit_page: Set the file which would the server access in a directory that a user accessed.
|
||||
# For example, by default, http://localhost/a-directory resolves to http://localhost/a-directory/index.html.
|
||||
implicit_page: index.html
|
||||
# static_file_headers: Headers for static files
|
||||
# static_file_headers:
|
||||
# - name: field-name
|
||||
# value: field-value
|
||||
# upload_path: The path to save the uploaded file. "uploads" by default.
|
||||
# If the path isn't prefixed with /, ./ or ../,
|
||||
# it is relative path of document_root path
|
||||
upload_path: uploads
|
||||
# file_types:
|
||||
# HTTP download file types,The file types supported by drogon
|
||||
# by default are "html", "js", "css", "xml", "xsl", "txt", "svg",
|
||||
# "ttf", "otf", "woff2", "woff" , "eot", "png", "jpg", "jpeg",
|
||||
# "gif", "bmp", "ico", "icns", etc.
|
||||
file_types:
|
||||
- gif
|
||||
- png
|
||||
- jpg
|
||||
- js
|
||||
- css
|
||||
- html
|
||||
- ico
|
||||
- swf
|
||||
- xap
|
||||
- apk
|
||||
- cur
|
||||
- xml
|
||||
# mime: A dictionary that extends the internal MIME type support. Maps extensions into new MIME types
|
||||
# note: This option only adds MIME to the sever. `file_types` above have to be set for the server to serve them.
|
||||
mime: {
|
||||
# text/markdown: md
|
||||
# text/gemini:
|
||||
# - gmi
|
||||
# - gemini
|
||||
}
|
||||
# locations: An array of locations of static files for GET requests.
|
||||
locations:
|
||||
# uri_prefix: The URI prefix of the location prefixed with "/", the default value is "" that disables the location.
|
||||
- uri_prefix: '' # /.well-known/acme-challenge/
|
||||
# default_content_type: The default content type of the static files without
|
||||
# an extension. empty string by default.
|
||||
default_content_type: text/plain
|
||||
# alias: The location in file system, if it is prefixed with "/", it
|
||||
# presents an absolute path, otherwise it presents a relative path to
|
||||
# the document_root path.
|
||||
# The default value is "" which means use the document root path as the location base path.
|
||||
alias: ''
|
||||
# is_case_sensitive: indicates whether the URI prefix is case sensitive.
|
||||
is_case_sensitive: false
|
||||
# allow_all: true by default. If it is set to false, only static files with a valid extension can be accessed.
|
||||
allow_all: true
|
||||
# is_recursive: true by default. If it is set to false, files in sub directories can't be accessed.
|
||||
is_recursive: true
|
||||
# filters: string array, the filters applied to the location.
|
||||
filters: []
|
||||
# max_connections: maximum number of connections, 100000 by default
|
||||
max_connections: 100000
|
||||
# max_connections_per_ip: maximum number of connections per client, 0 by default which means no limit
|
||||
max_connections_per_ip: 0
|
||||
# Load_dynamic_views: False by default, when set to true, drogon
|
||||
# compiles and loads dynamically "CSP View Files" in directories defined
|
||||
# by "dynamic_views_path"
|
||||
load_dynamic_views: false
|
||||
# dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
|
||||
# it is relative path of document_root path
|
||||
dynamic_views_path:
|
||||
- ./views
|
||||
# dynamic_views_output_path: Default by an empty string which means the output path of source
|
||||
# files is the path where the csp files locate. If the path isn't prefixed with /, it is relative
|
||||
# path of the current working directory.
|
||||
dynamic_views_output_path: ''
|
||||
# json_parser_stack_limit: 1000 by default, the maximum number of stack depth when reading a json string by the jsoncpp library.
|
||||
json_parser_stack_limit: 1000
|
||||
# enable_unicode_escaping_in_json: true by default, enable unicode escaping in json.
|
||||
enable_unicode_escaping_in_json: true
|
||||
# float_precision_in_json: set precision of float number in json.
|
||||
float_precision_in_json:
|
||||
# precision: 0 by default, 0 means use the default precision of the jsoncpp lib.
|
||||
precision: 0
|
||||
# precision_type: must be "significant" or "decimal", defaults to "significant" that means
|
||||
# setting max number of significant digits in string, "decimal" means setting max number of
|
||||
# digits after "." in string
|
||||
precision_type: significant
|
||||
# log: Set log output, drogon output logs to stdout by default
|
||||
log:
|
||||
# use_spdlog: Use spdlog library to log
|
||||
use_spdlog: false
|
||||
# log_path: Log file path,empty by default,in which case,logs are output to the stdout
|
||||
# log_path: ./
|
||||
# logfile_base_name: Log file base name,empty by default which means drogon names logfile as
|
||||
# drogon.log ...
|
||||
logfile_base_name: ''
|
||||
# log_size_limit: 100000000 bytes by default,
|
||||
# When the log file size reaches "log_size_limit", the log file is switched.
|
||||
log_size_limit: 100000000
|
||||
# max_files: 0 by default,
|
||||
# When the number of old log files exceeds "max_files", the oldest file will be deleted. 0 means never delete.
|
||||
max_files: 0
|
||||
# log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
|
||||
# The TRACE level is only valid when built in DEBUG mode.
|
||||
log_level: DEBUG
|
||||
# display_local_time: false by default, if true, the log time is displayed in local time
|
||||
display_local_time: false
|
||||
# run_as_daemon: False by default
|
||||
run_as_daemon: false
|
||||
# handle_sig_term: True by default
|
||||
handle_sig_term: true
|
||||
# relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
relaunch_on_error: false
|
||||
# use_sendfile: True by default, if true, the program
|
||||
# uses sendfile() system-call to send static files to clients;
|
||||
use_sendfile: true
|
||||
# use_gzip: True by default, use gzip to compress the response body's content;
|
||||
use_gzip: true
|
||||
# use_brotli: False by default, use brotli to compress the response body's content;
|
||||
use_brotli: false
|
||||
# static_files_cache_time: 5 (seconds) by default, the time in which the static file response is cached,
|
||||
# 0 means cache forever, the negative value means no cache
|
||||
static_files_cache_time: 5
|
||||
# simple_controllers_map: Used to configure mapping from path to simple controller
|
||||
# simple_controllers_map:
|
||||
# - path: /path/name
|
||||
# controller: controllerClassName
|
||||
# http_methods:
|
||||
# - get
|
||||
# - post
|
||||
# filters:
|
||||
# - FilterClassName
|
||||
# idle_connection_timeout: Defaults to 60 seconds, the lifetime
|
||||
# of the connection without read or write
|
||||
idle_connection_timeout: 60
|
||||
# server_header_field: Set the 'Server' header field in each response sent by drogon,
|
||||
# empty string by default with which the 'Server' header field is set to "Server: drogon/version string\r\n"
|
||||
server_header_field: ''
|
||||
# enable_server_header: Set true to force drogon to add a 'Server' header to each HTTP response. The default
|
||||
# value is true.
|
||||
enable_server_header: true
|
||||
# enable_date_header: Set true to force drogon to add a 'Date' header to each HTTP response. The default
|
||||
# value is true.
|
||||
enable_date_header: true
|
||||
# keepalive_requests: Set the maximum number of requests that can be served through one keep-alive connection.
|
||||
# After the maximum number of requests are made, the connection is closed.
|
||||
# The default value of 0 means no limit.
|
||||
keepalive_requests: 0
|
||||
# pipelining_requests: Set the maximum number of unhandled requests that can be cached in pipelining buffer.
|
||||
# After the maximum number of requests are made, the connection is closed.
|
||||
# The default value of 0 means no limit.
|
||||
pipelining_requests: 0
|
||||
# gzip_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
# file with the extension ".gz" in the same path and send the compressed file to the client.
|
||||
# The default value of gzip_static is true.
|
||||
gzip_static: true
|
||||
# br_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
# file with the extension ".br" in the same path and send the compressed file to the client.
|
||||
# The default value of br_static is true.
|
||||
br_static: true
|
||||
# client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M".
|
||||
# One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
client_max_body_size: 1M
|
||||
# max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes.
|
||||
# If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
|
||||
# Setting it to "" means no limit.
|
||||
client_max_memory_body_size: 64K
|
||||
# client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
|
||||
# One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
client_max_websocket_message_size: 128K
|
||||
# reuse_port: Defaults to false, users can run multiple processes listening on the same port at the same time.
|
||||
reuse_port: false
|
||||
# enabled_compressed_request: Defaults to false. If true the server will automatically decompress compressed request bodies.
|
||||
# Currently only gzip and br are supported. Note: max_memory_body_size and max_body_size applies twice for compressed requests.
|
||||
# Once when receiving and once when decompressing. i.e. if the decompressed body is larger than max_body_size, the request
|
||||
# will be rejected.
|
||||
enabled_compressed_request: false
|
||||
# enable_request_stream: Defaults to false. If true the server will enable stream mode for http requests.
|
||||
# See the wiki for more details.
|
||||
enable_request_stream: false
|
||||
# plugins: Define all plugins running in the application
|
||||
plugins:
|
||||
# name: The class name of the plugin
|
||||
- name: drogon::plugin::PromExporter
|
||||
# dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
dependencies: []
|
||||
# config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
# It can be commented out
|
||||
config:
|
||||
path: /metrics
|
||||
- name: drogon::plugin::AccessLogger
|
||||
dependencies: []
|
||||
config:
|
||||
use_spdlog: false
|
||||
log_path: ''
|
||||
log_format: ''
|
||||
log_file: access.log
|
||||
log_size_limit: 0
|
||||
use_local_time: true
|
||||
log_index: 0
|
||||
# show_microseconds: true
|
||||
# custom_time_format: ''
|
||||
# use_real_ip: false
|
||||
# custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method.
|
||||
custom_config:
|
||||
realm: drogonRealm
|
||||
opaque: drogonOpaque
|
||||
credentials:
|
||||
- user: drogon
|
||||
password: dr0g0n
|
42
docker/alpine/Dockerfile
Normal file
42
docker/alpine/Dockerfile
Normal file
@ -0,0 +1,42 @@
|
||||
FROM alpine:3.14
|
||||
|
||||
ARG USER=drogon
|
||||
ARG UID=1000
|
||||
ARG GID=1000
|
||||
ARG USER_HOME=/drogon
|
||||
|
||||
ENV TZ=UTC
|
||||
|
||||
RUN apk update && apk --no-cache --upgrade add tzdata \
|
||||
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
|
||||
&& echo $TZ > /etc/timezone
|
||||
|
||||
RUN apk --no-cache --upgrade add \
|
||||
sudo curl wget cmake make pkgconfig git gcc g++ \
|
||||
openssl libressl-dev jsoncpp-dev util-linux-dev zlib-dev c-ares-dev \
|
||||
postgresql-dev mariadb-dev sqlite-dev hiredis-dev
|
||||
|
||||
RUN addgroup -S -g $GID $USER \
|
||||
&& adduser -D -u $UID -G $USER -h $USER_HOME $USER \
|
||||
&& mkdir -p /etc/sudoers.d \
|
||||
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
|
||||
&& chmod 0440 /etc/sudoers.d/$USER
|
||||
|
||||
USER $USER
|
||||
WORKDIR $USER_HOME
|
||||
|
||||
ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US:en \
|
||||
LC_ALL=en_US.UTF-8 \
|
||||
CC=gcc \
|
||||
CXX=g++ \
|
||||
AR=gcc-ar \
|
||||
RANLIB=gcc-ranlib \
|
||||
DROGON_INSTALLED_ROOT=$USER_HOME/install
|
||||
|
||||
RUN wget -O $USER_HOME/version.json https://api.github.com/repos/an-tao/drogon/git/refs/heads/master \
|
||||
&& git clone https://github.com/an-tao/drogon $DROGON_INSTALLED_ROOT
|
||||
|
||||
RUN cd $DROGON_INSTALLED_ROOT \
|
||||
&& sed -i 's/bash/sh/' ./build.sh \
|
||||
&& ./build.sh
|
32
docker/alpine/README.md
Normal file
32
docker/alpine/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
## Build Docker Image
|
||||
|
||||
```shell
|
||||
$ cd drogon/docker/alpine # from this repository
|
||||
$ docker build --no-cache --build-arg UID=`id -u` --build-arg GID=`id -g` -t drogon-alpine . # include last dot(.)
|
||||
```
|
||||
|
||||
## Create a Drogon Project
|
||||
|
||||
```shell
|
||||
$ cd ~/drogon_app # example
|
||||
$ docker run --rm -v="$PWD:/drogon/app" -w="/drogon/app" drogon-alpine drogon_ctl create project hello_world
|
||||
```
|
||||
|
||||
## Build the Project
|
||||
|
||||
```shell
|
||||
$ cd hello_world
|
||||
$ docker run --rm --volume="$PWD:/drogon/app" -w="/drogon/app/build" drogon-alpine sh -c "cmake .. && make"
|
||||
```
|
||||
|
||||
## Start Server
|
||||
|
||||
```shell
|
||||
$ docker run --name drogon_test --rm -u 0 -v="$PWD/build:/drogon/app" -w="/drogon/app" -p 8080:80 -d drogon-alpine ./hello_world # expose port 80 to 8080
|
||||
```
|
||||
|
||||
## Stop Server
|
||||
|
||||
```shell
|
||||
$ docker kill drogon_test
|
||||
```
|
21
docker/arch/Dockerfile
Normal file
21
docker/arch/Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM archlinux:base-20210307.0.16708
|
||||
|
||||
RUN pacman -Syu --noconfirm && pacman -S wget sudo cmake make git gcc jsoncpp postgresql mariadb-clients hiredis --noconfirm
|
||||
|
||||
ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US:en \
|
||||
LC_ALL=en_US.UTF-8 \
|
||||
CC=gcc \
|
||||
CXX=g++ \
|
||||
AR=gcc-ar \
|
||||
RANLIB=gcc-ranlib \
|
||||
IROOT=/install
|
||||
|
||||
ENV DROGON_ROOT="$IROOT/drogon"
|
||||
|
||||
ADD https://api.github.com/repos/an-tao/drogon/git/refs/heads/master $IROOT/version.json
|
||||
RUN git clone https://github.com/an-tao/drogon $DROGON_ROOT
|
||||
|
||||
WORKDIR $DROGON_ROOT
|
||||
|
||||
RUN ./build.sh
|
30
docker/ubuntu/Dockerfile
Normal file
30
docker/ubuntu/Dockerfile
Normal file
@ -0,0 +1,30 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ENV TZ=UTC
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
RUN apt-get update -yqq \
|
||||
&& apt-get install -yqq --no-install-recommends software-properties-common \
|
||||
sudo curl wget cmake make pkg-config locales git gcc-11 g++-11 \
|
||||
openssl libssl-dev libjsoncpp-dev uuid-dev zlib1g-dev libc-ares-dev\
|
||||
postgresql-server-dev-all libmariadb-dev libsqlite3-dev libhiredis-dev\
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& locale-gen en_US.UTF-8
|
||||
|
||||
ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US:en \
|
||||
LC_ALL=en_US.UTF-8 \
|
||||
CC=gcc-11 \
|
||||
CXX=g++-11 \
|
||||
AR=gcc-ar-11 \
|
||||
RANLIB=gcc-ranlib-11 \
|
||||
IROOT=/install
|
||||
|
||||
ENV DROGON_ROOT="$IROOT/drogon"
|
||||
|
||||
ADD https://api.github.com/repos/drogonframework/drogon/git/refs/heads/master $IROOT/version.json
|
||||
RUN git clone https://github.com/drogonframework/drogon $DROGON_ROOT
|
||||
|
||||
WORKDIR $DROGON_ROOT
|
||||
|
||||
RUN ./build.sh
|
@ -17,13 +17,33 @@ add_executable(_drogon_ctl
|
||||
create.cc
|
||||
create_view.cc)
|
||||
target_link_libraries(_drogon_ctl ${PROJECT_NAME})
|
||||
if (WIN32 AND BUILD_SHARED_LIBS)
|
||||
set(DROGON_FILE $<TARGET_FILE:drogon>)
|
||||
if (USE_SUBMODULE)
|
||||
set(TRANTOR_FILE $<TARGET_FILE:trantor>)
|
||||
else()
|
||||
set(TRANTOR_FILE $<TARGET_FILE:Trantor::Trantor>)
|
||||
endif()
|
||||
add_custom_command(TARGET _drogon_ctl POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCTL_FILE=${DROGON_FILE}
|
||||
-DINSTALL_BIN_DIR=$<TARGET_FILE_DIR:_drogon_ctl>
|
||||
-P
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CopyDlls.cmake)
|
||||
add_custom_command(TARGET _drogon_ctl POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCTL_FILE=${TRANTOR_FILE}
|
||||
-DINSTALL_BIN_DIR=$<TARGET_FILE_DIR:_drogon_ctl>
|
||||
-P
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CopyDlls.cmake)
|
||||
endif()
|
||||
file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/templates/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
message(STATUS "cspFile:" ${cspFile})
|
||||
get_filename_component(classname ${cspFile} NAME_WE)
|
||||
message(STATUS "view classname:" ${classname})
|
||||
add_custom_command(OUTPUT ${classname}.h ${classname}.cc
|
||||
COMMAND _drogon_ctl
|
||||
COMMAND $<TARGET_FILE:_drogon_ctl>
|
||||
ARGS
|
||||
create
|
||||
view
|
||||
@ -37,8 +57,11 @@ target_link_libraries(drogon_ctl PRIVATE ${PROJECT_NAME})
|
||||
target_include_directories(drogon_ctl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_dependencies(drogon_ctl _drogon_ctl)
|
||||
if(WIN32)
|
||||
target_link_libraries(drogon_ctl PRIVATE ws2_32 Rpcrt4)
|
||||
target_link_libraries(drogon_ctl PRIVATE ws2_32 rpcrt4 iphlpapi)
|
||||
endif(WIN32)
|
||||
if(APPLE)
|
||||
target_link_libraries(drogon_ctl PRIVATE resolv)
|
||||
endif()
|
||||
message(STATUS "bin:" ${INSTALL_BIN_DIR})
|
||||
install(TARGETS drogon_ctl RUNTIME DESTINATION ${INSTALL_BIN_DIR})
|
||||
if(WIN32)
|
||||
@ -47,6 +70,7 @@ if(WIN32)
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCTL_FILE=${CTL_FILE}
|
||||
-DINSTALL_BIN_DIR=${INSTALL_BIN_DIR}
|
||||
-DRENAME_EXE=ON
|
||||
-P
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CopyDlls.cmake)
|
||||
else(WIN32)
|
||||
|
@ -22,18 +22,22 @@ class CommandHandler : public virtual drogon::DrObjectBase
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) = 0;
|
||||
|
||||
virtual bool isTopCommand()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual std::string script()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
virtual std::string detail()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
virtual ~CommandHandler()
|
||||
{
|
||||
}
|
||||
|
@ -3,4 +3,6 @@ get_filename_component(CTL_PATH ${CTL_FILE} DIRECTORY)
|
||||
file(GLOB DLL_FILES ${CTL_PATH}/*.dll)
|
||||
file(COPY ${DLL_FILES} DESTINATION ${INSTALL_BIN_DIR})
|
||||
file(COPY ${CTL_FILE} DESTINATION ${INSTALL_BIN_DIR})
|
||||
file(RENAME ${INSTALL_BIN_DIR}/drogon_ctl.exe ${INSTALL_BIN_DIR}/dg_ctl.exe)
|
||||
if (RENAME_EXE)
|
||||
file(RENAME ${INSTALL_BIN_DIR}/drogon_ctl.exe ${INSTALL_BIN_DIR}/dg_ctl.exe)
|
||||
endif()
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* create.cc
|
||||
* An Tao
|
||||
* @file create.cc
|
||||
* @author An Tao
|
||||
*
|
||||
* Copyright 2018, An Tao. All rights reserved.
|
||||
* https://github.com/an-tao/drogon
|
||||
@ -18,13 +18,15 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
using namespace drogon_ctl;
|
||||
|
||||
std::string create::detail()
|
||||
{
|
||||
return "Use create command to create some source files of drogon webapp\n\n"
|
||||
"Usage:drogon_ctl create <view|controller|filter|project|model> "
|
||||
"[-options] <object name>\n\n"
|
||||
"drogon_ctl create view <csp file name> [-o <output path>]//create "
|
||||
"HttpView source files from csp file\n\n"
|
||||
"drogon_ctl create view <csp file name> [-o <output path>] [-n "
|
||||
"<namespace>] [--path-to-namespace] //create HttpView source files "
|
||||
"from csp files, namespace is prefixed of path-to-namespace\n\n"
|
||||
"drogon_ctl create controller [-s] <[namespace::]class_name> //"
|
||||
"create HttpSimpleController source files\n\n"
|
||||
"drogon_ctl create controller -h <[namespace::]class_name> //"
|
||||
@ -40,7 +42,8 @@ std::string create::detail()
|
||||
"create a plugin named class_name\n\n"
|
||||
"drogon_ctl create project <project_name> //"
|
||||
"create a project named project_name\n\n"
|
||||
"drogon_ctl create model <model_path> [--table=<table_name>] [-f]//"
|
||||
"drogon_ctl create model <model_path> [-o <output path>] "
|
||||
"[--table=<table_name>] [-f]//"
|
||||
"create model classes in model_path\n";
|
||||
}
|
||||
|
||||
|
@ -17,21 +17,25 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create : public DrObject<create>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create some source files(Use 'drogon_ctl help create' for more "
|
||||
"information)";
|
||||
}
|
||||
virtual bool isTopCommand() override
|
||||
|
||||
bool isTopCommand() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual std::string detail() override;
|
||||
|
||||
std::string detail() override;
|
||||
};
|
||||
} // namespace drogon_ctl
|
||||
|
@ -95,8 +95,11 @@ void create_controller::newSimpleControllerHeaderFile(
|
||||
const std::string &className)
|
||||
{
|
||||
file << "#pragma once\n";
|
||||
file << "\n";
|
||||
file << "#include <drogon/HttpSimpleController.h>\n";
|
||||
file << "\n";
|
||||
file << "using namespace drogon;\n";
|
||||
file << "\n";
|
||||
std::string class_name = className;
|
||||
std::string namepace_path = "/";
|
||||
auto pos = class_name.find("::");
|
||||
@ -111,19 +114,19 @@ void create_controller::newSimpleControllerHeaderFile(
|
||||
file << "{\n";
|
||||
pos = class_name.find("::");
|
||||
}
|
||||
file << "class " << class_name << ":public drogon::HttpSimpleController<"
|
||||
file << "class " << class_name << " : public drogon::HttpSimpleController<"
|
||||
<< class_name << ">\n";
|
||||
file << "{\n";
|
||||
file << " public:\n";
|
||||
file << " virtual void asyncHandleHttpRequest(const HttpRequestPtr& "
|
||||
file << " void asyncHandleHttpRequest(const HttpRequestPtr& "
|
||||
"req, std::function<void (const HttpResponsePtr &)> &&callback) "
|
||||
"override;\n";
|
||||
|
||||
file << " PATH_LIST_BEGIN\n";
|
||||
file << " //list path definitions here;\n";
|
||||
file << " // list path definitions here;\n";
|
||||
file << " "
|
||||
"//PATH_ADD(\"/"
|
||||
"path\",\"filter1\",\"filter2\",HttpMethod1,HttpMethod2...);\n";
|
||||
"// PATH_ADD(\"/"
|
||||
"path\", \"filter1\", \"filter2\", HttpMethod1, HttpMethod2...);\n";
|
||||
file << " PATH_LIST_END\n";
|
||||
file << "};\n";
|
||||
while (namespaceCount > 0)
|
||||
@ -132,26 +135,29 @@ void create_controller::newSimpleControllerHeaderFile(
|
||||
file << "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
void create_controller::newSimpleControllerSourceFile(
|
||||
std::ofstream &file,
|
||||
const std::string &className,
|
||||
const std::string &filename)
|
||||
{
|
||||
file << "#include \"" << filename << ".h\"\n";
|
||||
file << "\n";
|
||||
auto pos = className.rfind("::");
|
||||
auto class_name = className;
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
auto namespacename = className.substr(0, pos);
|
||||
file << "using namespace " << namespacename << ";\n";
|
||||
file << "\n";
|
||||
class_name = className.substr(pos + 2);
|
||||
}
|
||||
file << "void " << class_name
|
||||
<< "::asyncHandleHttpRequest(const HttpRequestPtr& req, "
|
||||
"std::function<void (const HttpResponsePtr &)> &&callback)\n";
|
||||
file << "{\n";
|
||||
file << " //write your application logic here\n";
|
||||
file << "}";
|
||||
file << " // write your application logic here\n";
|
||||
file << "}\n";
|
||||
}
|
||||
|
||||
void create_controller::newWebsockControllerHeaderFile(
|
||||
@ -159,8 +165,11 @@ void create_controller::newWebsockControllerHeaderFile(
|
||||
const std::string &className)
|
||||
{
|
||||
file << "#pragma once\n";
|
||||
file << "\n";
|
||||
file << "#include <drogon/WebSocketController.h>\n";
|
||||
file << "\n";
|
||||
file << "using namespace drogon;\n";
|
||||
file << "\n";
|
||||
std::string class_name = className;
|
||||
std::string namepace_path = "/";
|
||||
auto pos = class_name.find("::");
|
||||
@ -175,23 +184,22 @@ void create_controller::newWebsockControllerHeaderFile(
|
||||
file << "{\n";
|
||||
pos = class_name.find("::");
|
||||
}
|
||||
file << "class " << class_name << ":public drogon::WebSocketController<"
|
||||
file << "class " << class_name << " : public drogon::WebSocketController<"
|
||||
<< class_name << ">\n";
|
||||
file << "{\n";
|
||||
file << " public:\n";
|
||||
file
|
||||
<< " virtual void handleNewMessage(const WebSocketConnectionPtr&,\n";
|
||||
file << " void handleNewMessage(const WebSocketConnectionPtr&,\n";
|
||||
file << " std::string &&,\n";
|
||||
file << " const WebSocketMessageType &) "
|
||||
"override;\n";
|
||||
file << " virtual void handleNewConnection(const HttpRequestPtr &,\n";
|
||||
file << " void handleNewConnection(const HttpRequestPtr &,\n";
|
||||
file << " const "
|
||||
"WebSocketConnectionPtr&)override;\n";
|
||||
file << " virtual void handleConnectionClosed(const "
|
||||
"WebSocketConnectionPtr&)override;\n";
|
||||
"WebSocketConnectionPtr&) override;\n";
|
||||
file << " void handleConnectionClosed(const "
|
||||
"WebSocketConnectionPtr&) override;\n";
|
||||
file << " WS_PATH_LIST_BEGIN\n";
|
||||
file << " //list path definitions here;\n";
|
||||
file << " //WS_PATH_ADD(\"/path\",\"filter1\",\"filter2\",...);\n";
|
||||
file << " // list path definitions here;\n";
|
||||
file << " // WS_PATH_ADD(\"/path\", \"filter1\", \"filter2\", ...);\n";
|
||||
file << " WS_PATH_LIST_END\n";
|
||||
file << "};\n";
|
||||
while (namespaceCount > 0)
|
||||
@ -200,37 +208,42 @@ void create_controller::newWebsockControllerHeaderFile(
|
||||
file << "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
void create_controller::newWebsockControllerSourceFile(
|
||||
std::ofstream &file,
|
||||
const std::string &className,
|
||||
const std::string &filename)
|
||||
{
|
||||
file << "#include \"" << filename << ".h\"\n";
|
||||
file << "\n";
|
||||
auto pos = className.rfind("::");
|
||||
auto class_name = className;
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
auto namespacename = className.substr(0, pos);
|
||||
file << "using namespace " << namespacename << ";\n";
|
||||
file << "\n";
|
||||
class_name = className.substr(pos + 2);
|
||||
}
|
||||
file << "void " << class_name
|
||||
<< "::handleNewMessage(const WebSocketConnectionPtr& wsConnPtr, "
|
||||
"std::string &&message, const WebSocketMessageType &type)\n";
|
||||
file << "{\n";
|
||||
file << " //write your application logic here\n";
|
||||
file << " // write your application logic here\n";
|
||||
file << "}\n";
|
||||
file << "\n";
|
||||
file << "void " << class_name
|
||||
<< "::handleNewConnection(const HttpRequestPtr &req,const "
|
||||
<< "::handleNewConnection(const HttpRequestPtr &req, const "
|
||||
"WebSocketConnectionPtr& wsConnPtr)\n";
|
||||
file << "{\n";
|
||||
file << " //write your application logic here\n";
|
||||
file << " // write your application logic here\n";
|
||||
file << "}\n";
|
||||
file << "\n";
|
||||
file << "void " << class_name
|
||||
<< "::handleConnectionClosed(const WebSocketConnectionPtr& "
|
||||
"wsConnPtr)\n";
|
||||
file << "{\n";
|
||||
file << " //write your application logic here\n";
|
||||
file << " // write your application logic here\n";
|
||||
file << "}\n";
|
||||
}
|
||||
|
||||
@ -239,8 +252,11 @@ void create_controller::newHttpControllerHeaderFile(
|
||||
const std::string &className)
|
||||
{
|
||||
file << "#pragma once\n";
|
||||
file << "\n";
|
||||
file << "#include <drogon/HttpController.h>\n";
|
||||
file << "\n";
|
||||
file << "using namespace drogon;\n";
|
||||
file << "\n";
|
||||
std::string class_name = className;
|
||||
std::string namepace_path = "/";
|
||||
auto pos = class_name.find("::");
|
||||
@ -255,33 +271,33 @@ void create_controller::newHttpControllerHeaderFile(
|
||||
file << "{\n";
|
||||
pos = class_name.find("::");
|
||||
}
|
||||
file << "class " << class_name << ":public drogon::HttpController<"
|
||||
file << "class " << class_name << " : public drogon::HttpController<"
|
||||
<< class_name << ">\n";
|
||||
file << "{\n";
|
||||
file << " public:\n";
|
||||
file << " METHOD_LIST_BEGIN\n";
|
||||
file << " //use METHOD_ADD to add your custom processing function "
|
||||
file << " // use METHOD_ADD to add your custom processing function "
|
||||
"here;\n";
|
||||
file << " //METHOD_ADD(" << class_name
|
||||
<< "::get,\"/{2}/{1}\",Get);"
|
||||
"//path is "
|
||||
file << " // METHOD_ADD(" << class_name
|
||||
<< "::get, \"/{2}/{1}\", Get);"
|
||||
" // path is "
|
||||
<< namepace_path << class_name << "/{arg2}/{arg1}\n";
|
||||
file << " //METHOD_ADD(" << class_name
|
||||
<< "::your_method_name,\"/{1}/{2}/list\",Get);"
|
||||
"//path is "
|
||||
file << " // METHOD_ADD(" << class_name
|
||||
<< "::your_method_name, \"/{1}/{2}/list\", Get);"
|
||||
" // path is "
|
||||
<< namepace_path << class_name << "/{arg1}/{arg2}/list\n";
|
||||
file << " //ADD_METHOD_TO(" << class_name
|
||||
<< "::your_method_name,\"/absolute/path/{1}/{2}/list\",Get);"
|
||||
"//path is /absolute/path/{arg1}/{arg2}/list\n";
|
||||
file << " // ADD_METHOD_TO(" << class_name
|
||||
<< "::your_method_name, \"/absolute/path/{1}/{2}/list\", Get);"
|
||||
" // path is /absolute/path/{arg1}/{arg2}/list\n";
|
||||
file << "\n";
|
||||
file << " METHOD_LIST_END\n";
|
||||
file << " // your declaration of processing function maybe like this:\n";
|
||||
file << " // void get(const HttpRequestPtr& req,"
|
||||
"std::function<void (const HttpResponsePtr &)> &&callback,int "
|
||||
"p1,std::string p2);\n";
|
||||
file << " // void your_method_name(const HttpRequestPtr& req,"
|
||||
"std::function<void (const HttpResponsePtr &)> &&callback,double "
|
||||
"p1,int p2) const;\n";
|
||||
file << " // void get(const HttpRequestPtr& req, "
|
||||
"std::function<void (const HttpResponsePtr &)> &&callback, int "
|
||||
"p1, std::string p2);\n";
|
||||
file << " // void your_method_name(const HttpRequestPtr& req, "
|
||||
"std::function<void (const HttpResponsePtr &)> &&callback, double "
|
||||
"p1, int p2) const;\n";
|
||||
file << "};\n";
|
||||
while (namespaceCount > 0)
|
||||
{
|
||||
@ -289,22 +305,25 @@ void create_controller::newHttpControllerHeaderFile(
|
||||
file << "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
void create_controller::newHttpControllerSourceFile(
|
||||
std::ofstream &file,
|
||||
const std::string &className,
|
||||
const std::string &filename)
|
||||
{
|
||||
file << "#include \"" << filename << ".h\"\n";
|
||||
file << "\n";
|
||||
auto pos = className.rfind("::");
|
||||
auto class_name = className;
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
auto namespacename = className.substr(0, pos);
|
||||
file << "using namespace " << namespacename << ";\n";
|
||||
file << "\n";
|
||||
class_name = className.substr(pos + 2);
|
||||
}
|
||||
|
||||
file << "//add definition of your processing function here\n";
|
||||
file << "// Add definition of your processing function here\n";
|
||||
}
|
||||
|
||||
void create_controller::createController(std::vector<std::string> &httpClasses,
|
||||
@ -360,20 +379,21 @@ void create_controller::createController(const std::string &className,
|
||||
}
|
||||
if (type == Http)
|
||||
{
|
||||
std::cout << "create a http controller:" << className << std::endl;
|
||||
std::cout << "Create a http controller: " << className << std::endl;
|
||||
newHttpControllerHeaderFile(oHeadFile, className);
|
||||
newHttpControllerSourceFile(oSourceFile, className, ctlName);
|
||||
}
|
||||
else if (type == Simple)
|
||||
{
|
||||
std::cout << "create a http simple controller:" << className
|
||||
std::cout << "Create a http simple controller: " << className
|
||||
<< std::endl;
|
||||
newSimpleControllerHeaderFile(oHeadFile, className);
|
||||
newSimpleControllerSourceFile(oSourceFile, className, ctlName);
|
||||
}
|
||||
else if (type == WebSocket)
|
||||
{
|
||||
std::cout << "create a websocket controller:" << className << std::endl;
|
||||
std::cout << "Create a websocket controller: " << className
|
||||
<< std::endl;
|
||||
newWebsockControllerHeaderFile(oHeadFile, className);
|
||||
newWebsockControllerSourceFile(oSourceFile, className, ctlName);
|
||||
}
|
||||
@ -444,8 +464,8 @@ void create_controller::createARestfulController(const std::string &className,
|
||||
std::cerr << err.what() << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::cout << "create a http restful API controller:" << className
|
||||
std::cout << "Create a http restful API controller: " << className
|
||||
<< std::endl;
|
||||
std::cout << "file name: " << ctlName << ".h and " << ctlName << ".cc"
|
||||
std::cout << "File name: " << ctlName << ".h and " << ctlName << ".cc"
|
||||
<< std::endl;
|
||||
}
|
@ -18,14 +18,16 @@
|
||||
#include <drogon/DrTemplateBase.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create_controller : public DrObject<create_controller>,
|
||||
public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create controller files";
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ static void createFilterSourceFile(std::ofstream &file,
|
||||
data.insert("filename", fileName);
|
||||
file << templ->genText(data);
|
||||
}
|
||||
|
||||
void create_filter::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
if (parameters.size() < 1)
|
||||
|
@ -17,13 +17,15 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create_filter : public DrObject<create_filter>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create filter class files";
|
||||
}
|
||||
|
@ -36,12 +36,83 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace drogon_ctl;
|
||||
|
||||
static std::string toLower(const std::string &str)
|
||||
{
|
||||
auto ret = str;
|
||||
std::transform(ret.begin(), ret.end(), ret.begin(), tolower);
|
||||
std::transform(ret.begin(), ret.end(), ret.begin(), [](unsigned char c) {
|
||||
return tolower(c);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::string escapeConnString(const std::string &str)
|
||||
{
|
||||
bool beQuoted = str.empty() || (str.find(' ') != std::string::npos);
|
||||
|
||||
std::string escaped;
|
||||
escaped.reserve(str.size());
|
||||
for (auto ch : str)
|
||||
{
|
||||
if (ch == '\'')
|
||||
escaped.push_back('\\');
|
||||
else if (ch == '\\')
|
||||
escaped.push_back('\\');
|
||||
escaped.push_back(ch);
|
||||
}
|
||||
|
||||
if (beQuoted)
|
||||
return "'" + escaped + "'";
|
||||
return escaped;
|
||||
}
|
||||
|
||||
std::string drogon_ctl::escapeIdentifier(const std::string &identifier,
|
||||
const std::string &rdbms)
|
||||
{
|
||||
if (rdbms != "postgresql")
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
|
||||
return "\\\"" + identifier + "\\\"";
|
||||
}
|
||||
|
||||
static std::map<std::string, std::vector<ConvertMethod>> getConvertMethods(
|
||||
const Json::Value &convertColumns)
|
||||
{
|
||||
std::map<std::string, std::vector<ConvertMethod>> ret;
|
||||
auto enabled = convertColumns.get("enabled", false).asBool();
|
||||
if (!enabled)
|
||||
{
|
||||
return ret;
|
||||
} // endif
|
||||
auto items = convertColumns["items"];
|
||||
if (items.isNull())
|
||||
{
|
||||
return ret;
|
||||
} // endif
|
||||
if (!items.isArray())
|
||||
{
|
||||
std::cerr << "items of convert must be an array" << std::endl;
|
||||
exit(1);
|
||||
} // endif
|
||||
for (auto &convertColumn : items)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConvertMethod c(convertColumn);
|
||||
ret[c.tableName()].push_back(c);
|
||||
} // try
|
||||
catch (const std::runtime_error &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
exit(1);
|
||||
} // catch
|
||||
} // for
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::map<std::string, std::vector<Relationship>> getRelationships(
|
||||
const Json::Value &relationships)
|
||||
{
|
||||
@ -80,6 +151,19 @@ static std::map<std::string, std::vector<Relationship>> getRelationships(
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool drogon_ctl::ConvertMethod::shouldConvert(const std::string &tableName,
|
||||
const std::string &colName) const
|
||||
{
|
||||
if (tableName == "*")
|
||||
{
|
||||
return colName == colName_;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (tableName == tableName_ && colName == colName_);
|
||||
} // endif
|
||||
}
|
||||
|
||||
#if USE_POSTGRESQL
|
||||
void create_model::createModelClassFromPG(
|
||||
const std::string &path,
|
||||
@ -87,26 +171,28 @@ void create_model::createModelClassFromPG(
|
||||
const std::string &tableName,
|
||||
const std::string &schema,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships)
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethods)
|
||||
{
|
||||
auto className = nameTransform(tableName, true);
|
||||
HttpViewData data;
|
||||
data["className"] = className;
|
||||
data["tableName"] = toLower(tableName);
|
||||
data["tableName"] = tableName;
|
||||
data["hasPrimaryKey"] = (int)0;
|
||||
data["primaryKeyName"] = "";
|
||||
data["dbName"] = dbname_;
|
||||
data["rdbms"] = std::string("postgresql");
|
||||
data["relationships"] = relationships;
|
||||
data["convertMethods"] = convertMethods;
|
||||
if (schema != "public")
|
||||
{
|
||||
data["schema"] = schema;
|
||||
}
|
||||
std::vector<ColumnInfo> cols;
|
||||
*client << "SELECT * \
|
||||
FROM information_schema.columns \
|
||||
WHERE table_schema = $1 \
|
||||
AND table_name = $2"
|
||||
*client << "SELECT * "
|
||||
"FROM information_schema.columns "
|
||||
"WHERE table_schema = $1 "
|
||||
"AND table_name = $2"
|
||||
<< schema << tableName << Mode::Blocking >>
|
||||
[&](const Result &r) {
|
||||
if (r.size() == 0)
|
||||
@ -140,9 +226,7 @@ void create_model::createModelClassFromPG(
|
||||
info.colType_ = "int32_t";
|
||||
info.colLength_ = 4;
|
||||
}
|
||||
else if (type == "bigint" ||
|
||||
type == "numeric") /// TODO:Use int64 to represent
|
||||
/// numeric type?
|
||||
else if (type == "bigint")
|
||||
{
|
||||
info.colType_ = "int64_t";
|
||||
info.colLength_ = 8;
|
||||
@ -181,6 +265,10 @@ void create_model::createModelClassFromPG(
|
||||
{
|
||||
info.colType_ = "std::vector<char>";
|
||||
}
|
||||
else if (type.find("numeric") != std::string::npos)
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
}
|
||||
else
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
@ -207,14 +295,14 @@ void create_model::createModelClassFromPG(
|
||||
exit(1);
|
||||
};
|
||||
size_t pkNumber = 0;
|
||||
*client << "SELECT \
|
||||
pg_constraint.conname AS pk_name,\
|
||||
pg_constraint.conkey AS pk_vector \
|
||||
FROM pg_constraint \
|
||||
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
|
||||
WHERE \
|
||||
pg_class.relname = $1 \
|
||||
AND pg_constraint.contype = 'p'"
|
||||
*client << "SELECT "
|
||||
"pg_constraint.conname AS pk_name,"
|
||||
"pg_constraint.conkey AS pk_vector "
|
||||
"FROM pg_constraint "
|
||||
"INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid "
|
||||
"WHERE "
|
||||
"pg_class.relname = $1 "
|
||||
"AND pg_constraint.contype = 'p'"
|
||||
<< tableName << Mode::Blocking >>
|
||||
[&](bool isNull,
|
||||
const std::string &pkName,
|
||||
@ -231,16 +319,18 @@ void create_model::createModelClassFromPG(
|
||||
data["hasPrimaryKey"] = (int)pkNumber;
|
||||
if (pkNumber == 1)
|
||||
{
|
||||
*client << "SELECT \
|
||||
pg_attribute.attname AS colname,\
|
||||
pg_type.typname AS typename,\
|
||||
pg_constraint.contype AS contype \
|
||||
FROM pg_constraint \
|
||||
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
|
||||
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
|
||||
AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] \
|
||||
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
|
||||
WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
|
||||
*client << "SELECT "
|
||||
"pg_attribute.attname AS colname,"
|
||||
"pg_type.typname AS typename,"
|
||||
"pg_constraint.contype AS contype "
|
||||
"FROM pg_constraint "
|
||||
"INNER JOIN pg_class ON pg_constraint.conrelid = "
|
||||
"pg_class.oid "
|
||||
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
|
||||
"pg_class.oid "
|
||||
"AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] "
|
||||
"INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid "
|
||||
"WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
|
||||
<< tableName << Mode::Blocking >>
|
||||
[&](bool isNull,
|
||||
const std::string &colName,
|
||||
@ -265,24 +355,29 @@ void create_model::createModelClassFromPG(
|
||||
}
|
||||
else if (pkNumber > 1)
|
||||
{
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
||||
for (size_t i = 1; i <= pkNumber; ++i)
|
||||
{
|
||||
*client << "SELECT \
|
||||
pg_attribute.attname AS colname,\
|
||||
pg_type.typname AS typename,\
|
||||
pg_constraint.contype AS contype \
|
||||
FROM pg_constraint \
|
||||
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
|
||||
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
|
||||
AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] \
|
||||
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
|
||||
WHERE pg_class.relname = $2 and pg_constraint.contype='p'"
|
||||
*client << "SELECT "
|
||||
"pg_attribute.attname AS colname,"
|
||||
"pg_type.typname AS typename,"
|
||||
"pg_constraint.contype AS contype "
|
||||
"FROM pg_constraint "
|
||||
"INNER JOIN pg_class ON pg_constraint.conrelid = "
|
||||
"pg_class.oid "
|
||||
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
|
||||
"pg_class.oid "
|
||||
"AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] "
|
||||
"INNER JOIN pg_type ON pg_type.oid = "
|
||||
"pg_attribute.atttypid "
|
||||
"WHERE pg_class.relname = $2 and "
|
||||
"pg_constraint.contype='p'"
|
||||
<< (int)i << tableName << Mode::Blocking >>
|
||||
[&](bool isNull, std::string colName, const std::string &type) {
|
||||
if (isNull)
|
||||
return;
|
||||
pkNames.push_back(colName);
|
||||
pkValNames.push_back(nameTransform(colName, false));
|
||||
for (auto &col : cols)
|
||||
{
|
||||
if (col.colName_ == colName)
|
||||
@ -299,6 +394,7 @@ void create_model::createModelClassFromPG(
|
||||
}
|
||||
data["primaryKeyName"] = pkNames;
|
||||
data["primaryKeyType"] = pkTypes;
|
||||
data["primaryKeyValNames"] = pkValNames;
|
||||
}
|
||||
|
||||
data["columns"] = cols;
|
||||
@ -311,12 +407,14 @@ void create_model::createModelClassFromPG(
|
||||
sourceFile << templ->genText(data);
|
||||
createRestfulAPIController(data, restfulApiConfig);
|
||||
}
|
||||
|
||||
void create_model::createModelFromPG(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const std::string &schema,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships)
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethods)
|
||||
{
|
||||
*client << "SELECT a.oid,"
|
||||
"a.relname AS name,"
|
||||
@ -341,7 +439,8 @@ void create_model::createModelFromPG(
|
||||
tableName,
|
||||
schema,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
} >>
|
||||
[](const DrogonDbException &e) {
|
||||
@ -357,7 +456,8 @@ void create_model::createModelClassFromMysql(
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships)
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethods)
|
||||
{
|
||||
auto className = nameTransform(tableName, true);
|
||||
HttpViewData data;
|
||||
@ -368,9 +468,10 @@ void create_model::createModelClassFromMysql(
|
||||
data["dbName"] = dbname_;
|
||||
data["rdbms"] = std::string("mysql");
|
||||
data["relationships"] = relationships;
|
||||
data["convertMethods"] = convertMethods;
|
||||
std::vector<ColumnInfo> cols;
|
||||
int i = 0;
|
||||
*client << "desc " + tableName << Mode::Blocking >>
|
||||
*client << "desc `" + tableName + "`" << Mode::Blocking >>
|
||||
[&i, &cols](bool isNull,
|
||||
const std::string &field,
|
||||
const std::string &type,
|
||||
@ -399,6 +500,11 @@ void create_model::createModelClassFromMysql(
|
||||
info.colType_ = "int16_t";
|
||||
info.colLength_ = 2;
|
||||
}
|
||||
else if (type.find("mediumint") == 0)
|
||||
{
|
||||
info.colType_ = "int32_t";
|
||||
info.colLength_ = 3;
|
||||
}
|
||||
else if (type.find("int") == 0)
|
||||
{
|
||||
info.colType_ = "int32_t";
|
||||
@ -444,7 +550,8 @@ void create_model::createModelClassFromMysql(
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
}
|
||||
if (type.find("unsigned") != std::string::npos)
|
||||
if (type.find("unsigned") != std::string::npos &&
|
||||
info.colType_ != "std::string")
|
||||
{
|
||||
info.colType_ = "u" + info.colType_;
|
||||
}
|
||||
@ -464,12 +571,13 @@ void create_model::createModelClassFromMysql(
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
exit(1);
|
||||
};
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
||||
for (auto const &col : cols)
|
||||
{
|
||||
if (col.isPrimaryKey_)
|
||||
{
|
||||
pkNames.push_back(col.colName_);
|
||||
pkValNames.push_back(nameTransform(col.colName_, false));
|
||||
pkTypes.push_back(col.colType_);
|
||||
}
|
||||
}
|
||||
@ -483,6 +591,7 @@ void create_model::createModelClassFromMysql(
|
||||
{
|
||||
data["primaryKeyName"] = pkNames;
|
||||
data["primaryKeyType"] = pkTypes;
|
||||
data["primaryKeyValNames"] = pkValNames;
|
||||
}
|
||||
data["columns"] = cols;
|
||||
std::ofstream headerFile(path + "/" + className + ".h", std::ofstream::out);
|
||||
@ -494,11 +603,13 @@ void create_model::createModelClassFromMysql(
|
||||
sourceFile << templ->genText(data);
|
||||
createRestfulAPIController(data, restfulApiConfig);
|
||||
}
|
||||
|
||||
void create_model::createModelFromMysql(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships)
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethods)
|
||||
{
|
||||
*client << "show tables" << Mode::Blocking >> [&](bool isNull,
|
||||
std::string &&tableName) {
|
||||
@ -509,7 +620,8 @@ void create_model::createModelFromMysql(
|
||||
client,
|
||||
tableName,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
} >> [](const DrogonDbException &e) {
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
@ -523,7 +635,8 @@ void create_model::createModelClassFromSqlite3(
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships)
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethods)
|
||||
{
|
||||
HttpViewData data;
|
||||
auto className = nameTransform(tableName, true);
|
||||
@ -534,6 +647,7 @@ void create_model::createModelClassFromSqlite3(
|
||||
data["dbName"] = std::string("sqlite3");
|
||||
data["rdbms"] = std::string("sqlite3");
|
||||
data["relationships"] = relationships;
|
||||
data["convertMethods"] = convertMethods;
|
||||
std::vector<ColumnInfo> cols;
|
||||
std::string sql = "PRAGMA table_info(" + tableName + ");";
|
||||
*client << sql << Mode::Blocking >> [&](const Result &result) {
|
||||
@ -541,9 +655,12 @@ void create_model::createModelClassFromSqlite3(
|
||||
for (auto &row : result)
|
||||
{
|
||||
bool notnull = row["notnull"].as<bool>();
|
||||
bool primary = row["pk"].as<bool>();
|
||||
bool primary = row["pk"].as<int>();
|
||||
auto type = row["type"].as<std::string>();
|
||||
std::transform(type.begin(), type.end(), type.begin(), tolower);
|
||||
std::transform(type.begin(),
|
||||
type.end(),
|
||||
type.begin(),
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
ColumnInfo info;
|
||||
info.index_ = index++;
|
||||
info.dbType_ = "sqlite3";
|
||||
@ -555,25 +672,35 @@ void create_model::createModelClassFromSqlite3(
|
||||
info.isPrimaryKey_ = primary;
|
||||
if (primary)
|
||||
{
|
||||
*client << "SELECT sql FROM sqlite_master WHERE name=? and "
|
||||
"(type='table' or type='view');"
|
||||
<< tableName << Mode::Blocking >>
|
||||
[&](bool isNull, std::string sql) {
|
||||
if (!isNull)
|
||||
{
|
||||
std::transform(sql.begin(),
|
||||
sql.end(),
|
||||
sql.begin(),
|
||||
tolower);
|
||||
if (sql.find("autoincrement") != std::string::npos)
|
||||
if (type == "integer")
|
||||
{
|
||||
info.isAutoVal_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*client << "SELECT sql FROM sqlite_master WHERE name=? and "
|
||||
"(type='table' or type='view');"
|
||||
<< tableName << Mode::Blocking >>
|
||||
[&](bool isNull, std::string sql) {
|
||||
if (!isNull)
|
||||
{
|
||||
info.isAutoVal_ = true;
|
||||
std::transform(sql.begin(),
|
||||
sql.end(),
|
||||
sql.begin(),
|
||||
[](unsigned char c) {
|
||||
return tolower(c);
|
||||
});
|
||||
if (sql.find("autoincrement") !=
|
||||
std::string::npos)
|
||||
{
|
||||
info.isAutoVal_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} >>
|
||||
[](const DrogonDbException &e) {
|
||||
} >>
|
||||
[](const DrogonDbException &e) {
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
auto defaultVal = row["dflt_value"].as<std::string>();
|
||||
if (!defaultVal.empty())
|
||||
@ -583,7 +710,7 @@ void create_model::createModelClassFromSqlite3(
|
||||
|
||||
if (type.find("int") != std::string::npos)
|
||||
{
|
||||
info.colType_ = "uint64_t";
|
||||
info.colType_ = "int64_t";
|
||||
info.colLength_ = 8;
|
||||
}
|
||||
else if (type.find("char") != std::string::npos || type == "text" ||
|
||||
@ -606,6 +733,10 @@ void create_model::createModelClassFromSqlite3(
|
||||
{
|
||||
info.colType_ = "std::vector<char>";
|
||||
}
|
||||
else if (type == "datetime" || type == "date")
|
||||
{
|
||||
info.colType_ = "::trantor::Date";
|
||||
}
|
||||
else
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
@ -616,44 +747,50 @@ void create_model::createModelClassFromSqlite3(
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
exit(1);
|
||||
};
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
||||
for (auto const &col : cols)
|
||||
{
|
||||
if (col.isPrimaryKey_)
|
||||
{
|
||||
pkNames.push_back(col.colName_);
|
||||
pkTypes.push_back(col.colType_);
|
||||
pkValNames.push_back(nameTransform(col.colName_, false));
|
||||
}
|
||||
}
|
||||
data["hasPrimaryKey"] = (int)pkNames.size();
|
||||
if (pkNames.size() == 1)
|
||||
{
|
||||
data["primaryKeyName"] = pkNames[0];
|
||||
data["primaryKeyType"] = pkTypes[0];
|
||||
}
|
||||
else if (pkNames.size() > 1)
|
||||
{
|
||||
for (auto &col : cols)
|
||||
{
|
||||
col.isAutoVal_ = false;
|
||||
}
|
||||
|
||||
data["hasPrimaryKey"] = (int)pkNames.size();
|
||||
if (pkNames.size() == 1)
|
||||
{
|
||||
data["primaryKeyName"] = pkNames[0];
|
||||
data["primaryKeyType"] = pkTypes[0];
|
||||
}
|
||||
else if (pkNames.size() > 1)
|
||||
{
|
||||
data["primaryKeyName"] = pkNames;
|
||||
data["primaryKeyType"] = pkTypes;
|
||||
}
|
||||
data["columns"] = cols;
|
||||
std::ofstream headerFile(path + "/" + className + ".h",
|
||||
std::ofstream::out);
|
||||
std::ofstream sourceFile(path + "/" + className + ".cc",
|
||||
std::ofstream::out);
|
||||
auto templ = DrTemplateBase::newTemplate("model_h.csp");
|
||||
headerFile << templ->genText(data);
|
||||
templ = DrTemplateBase::newTemplate("model_cc.csp");
|
||||
sourceFile << templ->genText(data);
|
||||
createRestfulAPIController(data, restfulApiConfig);
|
||||
data["primaryKeyName"] = pkNames;
|
||||
data["primaryKeyType"] = pkTypes;
|
||||
data["primaryKeyValNames"] = pkValNames;
|
||||
}
|
||||
data["columns"] = cols;
|
||||
std::ofstream headerFile(path + "/" + className + ".h", std::ofstream::out);
|
||||
std::ofstream sourceFile(path + "/" + className + ".cc",
|
||||
std::ofstream::out);
|
||||
auto templ = DrTemplateBase::newTemplate("model_h.csp");
|
||||
headerFile << templ->genText(data);
|
||||
templ = DrTemplateBase::newTemplate("model_cc.csp");
|
||||
sourceFile << templ->genText(data);
|
||||
createRestfulAPIController(data, restfulApiConfig);
|
||||
}
|
||||
|
||||
void create_model::createModelFromSqlite3(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships)
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethods)
|
||||
{
|
||||
*client << "SELECT name FROM sqlite_master WHERE name!='sqlite_sequence' "
|
||||
"and (type='table' or type='view') ORDER BY name;"
|
||||
@ -666,7 +803,8 @@ void create_model::createModelFromSqlite3(
|
||||
client,
|
||||
tableName,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
} >>
|
||||
[](const DrogonDbException &e) {
|
||||
@ -681,9 +819,14 @@ void create_model::createModel(const std::string &path,
|
||||
const std::string &singleModelName)
|
||||
{
|
||||
auto dbType = config.get("rdbms", "no dbms").asString();
|
||||
std::transform(dbType.begin(), dbType.end(), dbType.begin(), tolower);
|
||||
std::transform(dbType.begin(),
|
||||
dbType.end(),
|
||||
dbType.begin(),
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
auto restfulApiConfig = config["restful_api_controllers"];
|
||||
auto relationships = getRelationships(config["relationships"]);
|
||||
auto convertMethods = getConvertMethods(config["convert"]);
|
||||
drogon::utils::createPath(path);
|
||||
if (dbType == "postgresql")
|
||||
{
|
||||
#if USE_POSTGRESQL
|
||||
@ -713,20 +856,20 @@ void create_model::createModel(const std::string &path,
|
||||
|
||||
auto connStr =
|
||||
utils::formattedString("host=%s port=%u dbname=%s user=%s",
|
||||
host.c_str(),
|
||||
escapeConnString(host).c_str(),
|
||||
port,
|
||||
dbname.c_str(),
|
||||
user.c_str());
|
||||
escapeConnString(dbname).c_str(),
|
||||
escapeConnString(user).c_str());
|
||||
if (!password.empty())
|
||||
{
|
||||
connStr += " password=";
|
||||
connStr += password;
|
||||
connStr += escapeConnString(password);
|
||||
}
|
||||
auto characterSet = config.get("client_encoding", "").asString();
|
||||
if (!characterSet.empty())
|
||||
{
|
||||
connStr += " client_encoding=";
|
||||
connStr += characterSet;
|
||||
connStr += escapeConnString(characterSet);
|
||||
}
|
||||
|
||||
auto schema = config.get("schema", "public").asString();
|
||||
@ -753,8 +896,12 @@ void create_model::createModel(const std::string &path,
|
||||
{
|
||||
auto tables = config["tables"];
|
||||
if (!tables || tables.size() == 0)
|
||||
createModelFromPG(
|
||||
path, client, schema, restfulApiConfig, relationships);
|
||||
createModelFromPG(path,
|
||||
client,
|
||||
schema,
|
||||
restfulApiConfig,
|
||||
relationships,
|
||||
convertMethods);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
@ -763,14 +910,15 @@ void create_model::createModel(const std::string &path,
|
||||
std::transform(tableName.begin(),
|
||||
tableName.end(),
|
||||
tableName.begin(),
|
||||
tolower);
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
std::cout << "table name:" << tableName << std::endl;
|
||||
createModelClassFromPG(path,
|
||||
client,
|
||||
tableName,
|
||||
schema,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -781,7 +929,8 @@ void create_model::createModel(const std::string &path,
|
||||
singleModelName,
|
||||
schema,
|
||||
restfulApiConfig,
|
||||
relationships[singleModelName]);
|
||||
relationships[singleModelName],
|
||||
convertMethods[singleModelName]);
|
||||
}
|
||||
#else
|
||||
std::cerr
|
||||
@ -819,20 +968,20 @@ void create_model::createModel(const std::string &path,
|
||||
|
||||
auto connStr =
|
||||
utils::formattedString("host=%s port=%u dbname=%s user=%s",
|
||||
host.c_str(),
|
||||
escapeConnString(host).c_str(),
|
||||
port,
|
||||
dbname.c_str(),
|
||||
user.c_str());
|
||||
escapeConnString(dbname).c_str(),
|
||||
escapeConnString(user).c_str());
|
||||
if (!password.empty())
|
||||
{
|
||||
connStr += " password=";
|
||||
connStr += password;
|
||||
connStr += escapeConnString(password);
|
||||
}
|
||||
auto characterSet = config.get("client_encoding", "").asString();
|
||||
if (!characterSet.empty())
|
||||
{
|
||||
connStr += " client_encoding=";
|
||||
connStr += characterSet;
|
||||
connStr += escapeConnString(characterSet);
|
||||
}
|
||||
DbClientPtr client = drogon::orm::DbClient::newMysqlClient(connStr, 1);
|
||||
std::cout << "Connect to server..." << std::endl;
|
||||
@ -860,7 +1009,8 @@ void create_model::createModel(const std::string &path,
|
||||
createModelFromMysql(path,
|
||||
client,
|
||||
restfulApiConfig,
|
||||
relationships);
|
||||
relationships,
|
||||
convertMethods);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
@ -869,13 +1019,14 @@ void create_model::createModel(const std::string &path,
|
||||
std::transform(tableName.begin(),
|
||||
tableName.end(),
|
||||
tableName.begin(),
|
||||
tolower);
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
std::cout << "table name:" << tableName << std::endl;
|
||||
createModelClassFromMysql(path,
|
||||
client,
|
||||
tableName,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -885,7 +1036,8 @@ void create_model::createModel(const std::string &path,
|
||||
client,
|
||||
singleModelName,
|
||||
restfulApiConfig,
|
||||
relationships[singleModelName]);
|
||||
relationships[singleModelName],
|
||||
convertMethods[singleModelName]);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -904,7 +1056,7 @@ void create_model::createModel(const std::string &path,
|
||||
<< "/model.json " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::string connStr = "filename=" + filename;
|
||||
std::string connStr = "filename=" + escapeConnString(filename);
|
||||
DbClientPtr client =
|
||||
drogon::orm::DbClient::newSqlite3Client(connStr, 1);
|
||||
std::cout << "Connect..." << std::endl;
|
||||
@ -932,7 +1084,8 @@ void create_model::createModel(const std::string &path,
|
||||
createModelFromSqlite3(path,
|
||||
client,
|
||||
restfulApiConfig,
|
||||
relationships);
|
||||
relationships,
|
||||
convertMethods);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
@ -941,13 +1094,14 @@ void create_model::createModel(const std::string &path,
|
||||
std::transform(tableName.begin(),
|
||||
tableName.end(),
|
||||
tableName.begin(),
|
||||
tolower);
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
std::cout << "table name:" << tableName << std::endl;
|
||||
createModelClassFromSqlite3(path,
|
||||
client,
|
||||
tableName,
|
||||
restfulApiConfig,
|
||||
relationships[tableName]);
|
||||
relationships[tableName],
|
||||
convertMethods[tableName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -957,7 +1111,8 @@ void create_model::createModel(const std::string &path,
|
||||
client,
|
||||
singleModelName,
|
||||
restfulApiConfig,
|
||||
relationships[singleModelName]);
|
||||
relationships[singleModelName],
|
||||
convertMethods[singleModelName]);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -978,6 +1133,7 @@ void create_model::createModel(const std::string &path,
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void create_model::createModel(const std::string &path,
|
||||
const std::string &singleModelName)
|
||||
{
|
||||
@ -1018,7 +1174,9 @@ void create_model::createModel(const std::string &path,
|
||||
try
|
||||
{
|
||||
infile >> configJsonRoot;
|
||||
createModel(path, configJsonRoot, singleModelName);
|
||||
createModel(outputPath_.empty() ? path : outputPath_,
|
||||
configJsonRoot,
|
||||
singleModelName);
|
||||
}
|
||||
catch (const std::exception &exception)
|
||||
{
|
||||
@ -1056,6 +1214,22 @@ void create_model::handleCommand(std::vector<std::string> ¶meters)
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (auto iter = parameters.begin(); iter != parameters.end();)
|
||||
{
|
||||
auto &file = *iter;
|
||||
if (file == "-o" || file == "--output")
|
||||
{
|
||||
iter = parameters.erase(iter);
|
||||
if (iter != parameters.end())
|
||||
{
|
||||
outputPath_ = *iter;
|
||||
iter = parameters.erase(iter);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
for (auto const &path : parameters)
|
||||
{
|
||||
createModel(path, singleModelName);
|
||||
@ -1080,7 +1254,10 @@ void create_model::createRestfulAPIController(
|
||||
restfulApiConfig.get("resource_uri", "/*").asString(),
|
||||
regex,
|
||||
modelClassName);
|
||||
std::transform(resource.begin(), resource.end(), resource.begin(), tolower);
|
||||
std::transform(resource.begin(),
|
||||
resource.end(),
|
||||
resource.begin(),
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
auto ctrlClassName =
|
||||
std::regex_replace(restfulApiConfig.get("class_name", "/*").asString(),
|
||||
regex,
|
||||
|
@ -47,7 +47,9 @@ struct ColumnInfo
|
||||
inline std::string nameTransform(const std::string &origName, bool isType)
|
||||
{
|
||||
auto str = origName;
|
||||
std::transform(str.begin(), str.end(), str.begin(), tolower);
|
||||
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) {
|
||||
return tolower(c);
|
||||
});
|
||||
std::string::size_type startPos = 0;
|
||||
std::string::size_type pos;
|
||||
std::string ret;
|
||||
@ -75,10 +77,15 @@ inline std::string nameTransform(const std::string &origName, bool isType)
|
||||
ret[0] += ('A' - 'a');
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string escapeIdentifier(const std::string &identifier,
|
||||
const std::string &rdbms);
|
||||
|
||||
class PivotTable
|
||||
{
|
||||
public:
|
||||
PivotTable() = default;
|
||||
|
||||
PivotTable(const Json::Value &json)
|
||||
: tableName_(json.get("table_name", "").asString())
|
||||
{
|
||||
@ -97,6 +104,7 @@ class PivotTable
|
||||
throw std::runtime_error("target_key can't be empty");
|
||||
}
|
||||
}
|
||||
|
||||
PivotTable reverse() const
|
||||
{
|
||||
PivotTable pivot;
|
||||
@ -105,14 +113,17 @@ class PivotTable
|
||||
pivot.targetKey_ = originalKey_;
|
||||
return pivot;
|
||||
}
|
||||
|
||||
const std::string &tableName() const
|
||||
{
|
||||
return tableName_;
|
||||
}
|
||||
|
||||
const std::string &originalKey() const
|
||||
{
|
||||
return originalKey_;
|
||||
}
|
||||
|
||||
const std::string &targetKey() const
|
||||
{
|
||||
return targetKey_;
|
||||
@ -123,6 +134,80 @@ class PivotTable
|
||||
std::string originalKey_;
|
||||
std::string targetKey_;
|
||||
};
|
||||
|
||||
class ConvertMethod
|
||||
{
|
||||
public:
|
||||
ConvertMethod(const Json::Value &convert)
|
||||
{
|
||||
tableName_ = convert.get("table", "*").asString();
|
||||
colName_ = convert.get("column", "*").asString();
|
||||
|
||||
auto method = convert["method"];
|
||||
if (method.isNull())
|
||||
{
|
||||
throw std::runtime_error("method - object is missing.");
|
||||
} // endif
|
||||
if (!method.isObject())
|
||||
{
|
||||
throw std::runtime_error("method is not an object.");
|
||||
} // endif
|
||||
methodBeforeDbWrite_ = method.get("before_db_write", "").asString();
|
||||
methodAfterDbRead_ = method.get("after_db_read", "").asString();
|
||||
|
||||
auto includeFiles = convert["includes"];
|
||||
if (includeFiles.isNull())
|
||||
{
|
||||
return;
|
||||
} // endif
|
||||
if (!includeFiles.isArray())
|
||||
{
|
||||
throw std::runtime_error("includes must be an array");
|
||||
} // endif
|
||||
for (auto &i : includeFiles)
|
||||
{
|
||||
includeFiles_.push_back(i.asString());
|
||||
} // for
|
||||
}
|
||||
|
||||
ConvertMethod() = default;
|
||||
|
||||
bool shouldConvert(const std::string &tableName,
|
||||
const std::string &colName) const;
|
||||
|
||||
const std::string &tableName() const
|
||||
{
|
||||
return tableName_;
|
||||
}
|
||||
|
||||
const std::string &colName() const
|
||||
{
|
||||
return colName_;
|
||||
}
|
||||
|
||||
const std::string &methodBeforeDbWrite() const
|
||||
{
|
||||
return methodBeforeDbWrite_;
|
||||
}
|
||||
|
||||
const std::string &methodAfterDbRead() const
|
||||
{
|
||||
return methodAfterDbRead_;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &includeFiles() const
|
||||
{
|
||||
return includeFiles_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string tableName_{"*"};
|
||||
std::string colName_{"*"};
|
||||
std::string methodBeforeDbWrite_;
|
||||
std::string methodAfterDbRead_;
|
||||
std::vector<std::string> includeFiles_;
|
||||
};
|
||||
|
||||
class Relationship
|
||||
{
|
||||
public:
|
||||
@ -132,6 +217,7 @@ class Relationship
|
||||
HasMany,
|
||||
ManyToMany
|
||||
};
|
||||
|
||||
Relationship(const Json::Value &relationship)
|
||||
{
|
||||
auto type = relationship.get("type", "has one").asString();
|
||||
@ -193,7 +279,9 @@ class Relationship
|
||||
pivotTable_ = PivotTable(pivot);
|
||||
}
|
||||
}
|
||||
|
||||
Relationship() = default;
|
||||
|
||||
Relationship reverse() const
|
||||
{
|
||||
Relationship r;
|
||||
@ -215,38 +303,47 @@ class Relationship
|
||||
r.pivotTable_ = pivotTable_.reverse();
|
||||
return r;
|
||||
}
|
||||
|
||||
Type type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
bool enableReverse() const
|
||||
{
|
||||
return enableReverse_;
|
||||
}
|
||||
|
||||
const std::string &originalTableName() const
|
||||
{
|
||||
return originalTableName_;
|
||||
}
|
||||
|
||||
const std::string &originalTableAlias() const
|
||||
{
|
||||
return originalTableAlias_;
|
||||
}
|
||||
|
||||
const std::string &originalKey() const
|
||||
{
|
||||
return originalKey_;
|
||||
}
|
||||
|
||||
const std::string &targetTableName() const
|
||||
{
|
||||
return targetTableName_;
|
||||
}
|
||||
|
||||
const std::string &targetTableAlias() const
|
||||
{
|
||||
return targetTableAlias_;
|
||||
}
|
||||
|
||||
const std::string &targetKey() const
|
||||
{
|
||||
return targetKey_;
|
||||
}
|
||||
|
||||
const PivotTable &pivotTable() const
|
||||
{
|
||||
return pivotTable_;
|
||||
@ -263,11 +360,13 @@ class Relationship
|
||||
bool enableReverse_{false};
|
||||
PivotTable pivotTable_;
|
||||
};
|
||||
|
||||
class create_model : public DrObject<create_model>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create Model classes files";
|
||||
}
|
||||
@ -279,18 +378,22 @@ class create_model : public DrObject<create_model>, public CommandHandler
|
||||
const Json::Value &config,
|
||||
const std::string &singleModelName);
|
||||
#if USE_POSTGRESQL
|
||||
void createModelClassFromPG(const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const std::string &schema,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships);
|
||||
void createModelClassFromPG(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const std::string &schema,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethods);
|
||||
|
||||
void createModelFromPG(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const std::string &schema,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships);
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethods);
|
||||
#endif
|
||||
#if USE_MYSQL
|
||||
void createModelClassFromMysql(
|
||||
@ -298,12 +401,14 @@ class create_model : public DrObject<create_model>, public CommandHandler
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships);
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethods);
|
||||
void createModelFromMysql(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships);
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethods);
|
||||
#endif
|
||||
#if USE_SQLITE3
|
||||
void createModelClassFromSqlite3(
|
||||
@ -311,16 +416,19 @@ class create_model : public DrObject<create_model>, public CommandHandler
|
||||
const DbClientPtr &client,
|
||||
const std::string &tableName,
|
||||
const Json::Value &restfulApiConfig,
|
||||
const std::vector<Relationship> &relationships);
|
||||
const std::vector<Relationship> &relationships,
|
||||
const std::vector<ConvertMethod> &convertMethod);
|
||||
void createModelFromSqlite3(
|
||||
const std::string &path,
|
||||
const DbClientPtr &client,
|
||||
const Json::Value &restfulApiConfig,
|
||||
std::map<std::string, std::vector<Relationship>> &relationships);
|
||||
std::map<std::string, std::vector<Relationship>> &relationships,
|
||||
std::map<std::string, std::vector<ConvertMethod>> &convertMethod);
|
||||
#endif
|
||||
void createRestfulAPIController(const DrTemplateData &tableInfo,
|
||||
const Json::Value &restfulApiConfig);
|
||||
std::string dbname_;
|
||||
bool forceOverwrite_{false};
|
||||
std::string outputPath_;
|
||||
};
|
||||
} // namespace drogon_ctl
|
||||
|
@ -69,6 +69,7 @@ static void createPluginSourceFile(std::ofstream &file,
|
||||
data.insert("filename", fileName);
|
||||
file << templ->genText(data);
|
||||
}
|
||||
|
||||
void create_plugin::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
if (parameters.size() < 1)
|
||||
|
@ -17,13 +17,15 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create_plugin : public DrObject<create_plugin>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create plugin class files";
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ void create_project::handleCommand(std::vector<std::string> ¶meters)
|
||||
auto pName = parameters[0];
|
||||
createProject(pName);
|
||||
}
|
||||
|
||||
static void newCmakeFile(std::ofstream &cmakeFile,
|
||||
const std::string &projectName)
|
||||
{
|
||||
@ -46,27 +47,52 @@ static void newCmakeFile(std::ofstream &cmakeFile,
|
||||
auto templ = DrTemplateBase::newTemplate("cmake.csp");
|
||||
cmakeFile << templ->genText(data);
|
||||
}
|
||||
|
||||
static void newMainFile(std::ofstream &mainFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("demoMain");
|
||||
mainFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newGitIgFile(std::ofstream &gitFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("gitignore.csp");
|
||||
gitFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newConfigFile(std::ofstream &configFile)
|
||||
static void newConfigJsonFile(std::ofstream &configJsonFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("config");
|
||||
configFile << templ->genText();
|
||||
auto templ = DrTemplateBase::newTemplate("config_json");
|
||||
configJsonFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newConfigYamlFile(std::ofstream &configYamlFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("config_yaml");
|
||||
configYamlFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newModelConfigFile(std::ofstream &configFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("model_json");
|
||||
configFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newTestMainFile(std::ofstream &mainFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("test_main");
|
||||
mainFile << templ->genText();
|
||||
}
|
||||
|
||||
static void newTestCmakeFile(std::ofstream &testCmakeFile,
|
||||
const std::string &projectName)
|
||||
{
|
||||
HttpViewData data;
|
||||
data.insert("ProjectName", projectName);
|
||||
auto templ = DrTemplateBase::newTemplate("test_cmake");
|
||||
testCmakeFile << templ->genText(data);
|
||||
}
|
||||
|
||||
void create_project::createProject(const std::string &projectName)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -100,11 +126,18 @@ void create_project::createProject(const std::string &projectName)
|
||||
drogon::utils::createPath("plugins");
|
||||
drogon::utils::createPath("build");
|
||||
drogon::utils::createPath("models");
|
||||
drogon::utils::createPath("test");
|
||||
|
||||
std::ofstream gitFile(".gitignore", std::ofstream::out);
|
||||
newGitIgFile(gitFile);
|
||||
std::ofstream configFile("config.json", std::ofstream::out);
|
||||
newConfigFile(configFile);
|
||||
std::ofstream configJsonFile("config.json", std::ofstream::out);
|
||||
newConfigJsonFile(configJsonFile);
|
||||
std::ofstream configYamlFile("config.yaml", std::ofstream::out);
|
||||
newConfigYamlFile(configYamlFile);
|
||||
std::ofstream modelConfigFile("models/model.json", std::ofstream::out);
|
||||
newModelConfigFile(modelConfigFile);
|
||||
std::ofstream testMainFile("test/test_main.cc", std::ofstream::out);
|
||||
newTestMainFile(testMainFile);
|
||||
std::ofstream testCmakeFile("test/CMakeLists.txt", std::ofstream::out);
|
||||
newTestCmakeFile(testCmakeFile, projectName);
|
||||
}
|
||||
|
@ -16,13 +16,15 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create_project : public DrObject<create_project>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create a project";
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* create_view.cc
|
||||
* An Tao
|
||||
* @file create_view.cc
|
||||
* @author An Tao
|
||||
*
|
||||
* Copyright 2018, An Tao. All rights reserved.
|
||||
* https://github.com/an-tao/drogon
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
#include "create_view.h"
|
||||
#include "cmd.h"
|
||||
#include <drogon/utils/Utilities.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@ -52,6 +53,7 @@ static std::string &replace_all(std::string &str,
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static void parseCxxLine(std::ofstream &oSrcFile,
|
||||
const std::string &line,
|
||||
const std::string &streamName,
|
||||
@ -65,6 +67,7 @@ static void parseCxxLine(std::ofstream &oSrcFile,
|
||||
oSrcFile << tmp << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
static void outputVal(std::ofstream &oSrcFile,
|
||||
const std::string &streamName,
|
||||
const std::string &viewDataName,
|
||||
@ -75,12 +78,12 @@ static void outputVal(std::ofstream &oSrcFile,
|
||||
<< "\"];\n";
|
||||
oSrcFile << " if(val.type()==typeid(const char *)){\n";
|
||||
oSrcFile << " " << streamName
|
||||
<< "<<*any_cast<const char *>(&val);\n";
|
||||
<< "<<*(std::any_cast<const char *>(&val));\n";
|
||||
oSrcFile << " }else "
|
||||
"if(val.type()==typeid(std::string)||val.type()==typeid(const "
|
||||
"std::string)){\n";
|
||||
oSrcFile << " " << streamName
|
||||
<< "<<*any_cast<const std::string>(&val);\n";
|
||||
<< "<<*(std::any_cast<const std::string>(&val));\n";
|
||||
oSrcFile << " }\n";
|
||||
oSrcFile << "}\n";
|
||||
}
|
||||
@ -117,7 +120,7 @@ static void parseLine(std::ofstream &oSrcFile,
|
||||
{
|
||||
// std::cout<<"blank line!"<<std::endl;
|
||||
// std::cout<<streamName<<"<<\"\\n\";\n";
|
||||
if (returnFlag)
|
||||
if (returnFlag && !cxx_flag)
|
||||
oSrcFile << streamName << "<<\"\\n\";\n";
|
||||
return;
|
||||
}
|
||||
@ -247,9 +250,9 @@ static void parseLine(std::ofstream &oSrcFile,
|
||||
|
||||
void create_view::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
for (auto iter = parameters.begin(); iter != parameters.end(); iter++)
|
||||
for (auto iter = parameters.begin(); iter != parameters.end();)
|
||||
{
|
||||
auto file = *iter;
|
||||
auto &file = *iter;
|
||||
if (file == "-o" || file == "--output")
|
||||
{
|
||||
iter = parameters.erase(iter);
|
||||
@ -258,28 +261,84 @@ void create_view::handleCommand(std::vector<std::string> ¶meters)
|
||||
outputPath_ = *iter;
|
||||
iter = parameters.erase(iter);
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
else if (file == "-n" || file == "--namespace")
|
||||
{
|
||||
iter = parameters.erase(iter);
|
||||
if (iter != parameters.end())
|
||||
{
|
||||
namespaces_ = utils::splitString(*iter, "::");
|
||||
iter = parameters.erase(iter);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (file == "--path-to-namespace")
|
||||
{
|
||||
iter = parameters.erase(iter);
|
||||
pathToNamespaceFlag_ = true;
|
||||
continue;
|
||||
}
|
||||
else if (file[0] == '-')
|
||||
{
|
||||
std::cout << ARGS_ERROR_STR << std::endl;
|
||||
return;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
createViewFiles(parameters);
|
||||
}
|
||||
|
||||
void create_view::createViewFiles(std::vector<std::string> &cspFileNames)
|
||||
{
|
||||
for (auto const &file : cspFileNames)
|
||||
{
|
||||
std::cout << "create view:" << file << std::endl;
|
||||
createViewFile(file);
|
||||
if (createViewFile(file) != 0)
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int create_view::createViewFile(const std::string &script_filename)
|
||||
{
|
||||
std::cout << "create HttpView Class file by " << script_filename
|
||||
<< std::endl;
|
||||
if (pathToNamespaceFlag_)
|
||||
{
|
||||
std::string::size_type pos1 = 0, pos2 = 0;
|
||||
if (script_filename.length() >= 2 && script_filename[0] == '.' &&
|
||||
(script_filename[1] == '/' || script_filename[1] == '\\'))
|
||||
{
|
||||
pos1 = pos2 = 2;
|
||||
}
|
||||
else if (script_filename.length() >= 1 &&
|
||||
(script_filename[0] == '/' || script_filename[0] == '\\'))
|
||||
{
|
||||
pos1 = pos2 = 1;
|
||||
}
|
||||
while (pos2 < script_filename.length() - 1)
|
||||
{
|
||||
if (script_filename[pos2] == '/' || script_filename[pos2] == '\\')
|
||||
{
|
||||
if (pos2 > pos1)
|
||||
{
|
||||
namespaces_.push_back(
|
||||
script_filename.substr(pos1, pos2 - pos1));
|
||||
}
|
||||
pos1 = ++pos2;
|
||||
}
|
||||
else
|
||||
{
|
||||
++pos2;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string npPrefix;
|
||||
for (auto &np : namespaces_)
|
||||
{
|
||||
npPrefix += np;
|
||||
npPrefix += "_";
|
||||
}
|
||||
std::ifstream infile(script_filename.c_str(), std::ifstream::in);
|
||||
if (infile)
|
||||
{
|
||||
@ -292,8 +351,10 @@ int create_view::createViewFile(const std::string &script_filename)
|
||||
className = className.substr(pos + 1);
|
||||
}
|
||||
std::cout << "className=" << className << std::endl;
|
||||
std::string headFileName = outputPath_ + "/" + className + ".h";
|
||||
std::string sourceFilename = outputPath_ + "/" + className + ".cc";
|
||||
std::string headFileName =
|
||||
outputPath_ + "/" + npPrefix + className + ".h";
|
||||
std::string sourceFilename =
|
||||
outputPath_ + "/" + npPrefix + className + ".cc";
|
||||
std::ofstream oHeadFile(headFileName.c_str(), std::ofstream::out);
|
||||
std::ofstream oSourceFile(sourceFilename.c_str(),
|
||||
std::ofstream::out);
|
||||
@ -305,7 +366,7 @@ int create_view::createViewFile(const std::string &script_filename)
|
||||
}
|
||||
|
||||
newViewHeaderFile(oHeadFile, className);
|
||||
newViewSourceFile(oSourceFile, className, infile);
|
||||
newViewSourceFile(oSourceFile, className, npPrefix, infile);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -317,28 +378,40 @@ int create_view::createViewFile(const std::string &script_filename)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void create_view::newViewHeaderFile(std::ofstream &file,
|
||||
const std::string &className)
|
||||
{
|
||||
file << "//this file is generated by program automatically,don't modify "
|
||||
"it!\n";
|
||||
file << "#include <drogon/DrTemplate.h>\n";
|
||||
file << "using namespace drogon;\n";
|
||||
file << "class " << className << ":public DrTemplate<" << className
|
||||
for (auto &np : namespaces_)
|
||||
{
|
||||
file << "namespace " << np << "\n";
|
||||
file << "{\n";
|
||||
}
|
||||
file << "class " << className << ":public drogon::DrTemplate<" << className
|
||||
<< ">\n";
|
||||
file << "{\npublic:\n\t" << className << "(){};\n\tvirtual ~" << className
|
||||
<< "(){};\n\t"
|
||||
"virtual std::string genText(const DrTemplateData &) override;\n};";
|
||||
"virtual std::string genText(const drogon::DrTemplateData &) "
|
||||
"override;\n};\n";
|
||||
for (std::size_t i = 0; i < namespaces_.size(); ++i)
|
||||
{
|
||||
file << "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
void create_view::newViewSourceFile(std::ofstream &file,
|
||||
const std::string &className,
|
||||
const std::string &namespacePrefix,
|
||||
std::ifstream &infile)
|
||||
{
|
||||
file << "//this file is generated by program(drogon_ctl) "
|
||||
"automatically,don't modify it!\n";
|
||||
file << "#include \"" << className << ".h\"\n";
|
||||
file << "#include \"" << namespacePrefix << className << ".h\"\n";
|
||||
file << "#include <drogon/utils/OStringStream.h>\n";
|
||||
file << "#include <drogon/utils/Utilities.h>\n";
|
||||
file << "#include <string>\n";
|
||||
file << "#include <map>\n";
|
||||
file << "#include <vector>\n";
|
||||
@ -350,6 +423,7 @@ void create_view::newViewSourceFile(std::ofstream &file,
|
||||
file << "#include <list>\n";
|
||||
file << "#include <deque>\n";
|
||||
file << "#include <queue>\n";
|
||||
|
||||
// Find layout tag
|
||||
std::string layoutName;
|
||||
std::regex layoutReg("<%layout[ \\t]+(((?!%\\}).)*[^ \\t])[ \\t]*%>");
|
||||
@ -378,7 +452,7 @@ void create_view::newViewSourceFile(std::ofstream &file,
|
||||
std::transform(lowerBuffer.begin(),
|
||||
lowerBuffer.end(),
|
||||
lowerBuffer.begin(),
|
||||
::tolower);
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
if ((pos = lowerBuffer.find(cxx_include)) != std::string::npos)
|
||||
{
|
||||
// std::cout<<"haha find it!"<<endl;
|
||||
@ -419,8 +493,23 @@ void create_view::newViewSourceFile(std::ofstream &file,
|
||||
infile.seekg(0, std::ifstream::beg);
|
||||
}
|
||||
|
||||
// std::cout<<"file pos:"<<infile.tellg()<<std::endl;
|
||||
|
||||
if (!namespaces_.empty())
|
||||
{
|
||||
file << "using namespace ";
|
||||
for (std::size_t i = 0; i < namespaces_.size(); ++i)
|
||||
{
|
||||
if (i != namespaces_.size() - 1)
|
||||
{
|
||||
file << namespaces_[i] << "::";
|
||||
}
|
||||
else
|
||||
{
|
||||
file << namespaces_[i] << ";";
|
||||
}
|
||||
}
|
||||
file << "\n";
|
||||
}
|
||||
file << "using namespace drogon;\n";
|
||||
std::string viewDataName = className + "_view_data";
|
||||
// virtual std::string genText(const DrTemplateData &)
|
||||
file << "std::string " << className << "::genText(const DrTemplateData& "
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* create_view.h
|
||||
* An Tao
|
||||
* @file create_view.h
|
||||
* @author An Tao
|
||||
*
|
||||
* Copyright 2018, An Tao. All rights reserved.
|
||||
* https://github.com/an-tao/drogon
|
||||
@ -17,24 +17,29 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class create_view : public DrObject<create_view>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "create view class files";
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string outputPath_{"."};
|
||||
std::vector<std::string> namespaces_;
|
||||
bool pathToNamespaceFlag_{false};
|
||||
void createViewFiles(std::vector<std::string> &cspFileNames);
|
||||
int createViewFile(const std::string &script_filename);
|
||||
void newViewHeaderFile(std::ofstream &file, const std::string &className);
|
||||
void newViewSourceFile(std::ofstream &file,
|
||||
const std::string &className,
|
||||
const std::string &namespacePrefix,
|
||||
std::ifstream &infile);
|
||||
};
|
||||
} // namespace drogon_ctl
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
using namespace drogon_ctl;
|
||||
|
||||
void help::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
if (parameters.size() == 0)
|
||||
|
@ -17,17 +17,20 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class help : public DrObject<help>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "display this message";
|
||||
}
|
||||
virtual bool isTopCommand() override
|
||||
|
||||
bool isTopCommand() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* main.cc
|
||||
* An Tao
|
||||
* @file main.cc
|
||||
* @author An Tao
|
||||
*
|
||||
* Copyright 2018, An Tao. All rights reserved.
|
||||
* https://github.com/an-tao/drogon
|
||||
@ -19,13 +19,13 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
if (argc < 2)
|
||||
{
|
||||
std::vector<std::string> args = {"help"};
|
||||
args = {"help"};
|
||||
exeCommand(args);
|
||||
return 0;
|
||||
}
|
||||
std::vector<std::string> args;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
|
@ -18,12 +18,17 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <iomanip>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <json/json.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace drogon_ctl;
|
||||
|
||||
std::string press::detail()
|
||||
{
|
||||
return "Use press command to do stress testing\n"
|
||||
@ -31,17 +36,19 @@ std::string press::detail()
|
||||
" -n num number of requests(default : 1)\n"
|
||||
" -t num number of threads(default : 1)\n"
|
||||
" -c num concurrent connections(default : 1)\n"
|
||||
// " -k keep alive(default: no)\n"
|
||||
" -q no progress indication(default: no)\n\n"
|
||||
" -k disable SSL certificate validation(default: enable)\n"
|
||||
" -f customize http request json file(default: disenable)\n"
|
||||
" -q no progress indication(default: show)\n\n"
|
||||
"example: drogon_ctl press -n 10000 -c 100 -t 4 -q "
|
||||
"http://localhost:8080/index.html\n";
|
||||
"http://localhost:8080/index.html -f ./http_request.json\n";
|
||||
}
|
||||
|
||||
void outputErrorAndExit(const string_view &err)
|
||||
void outputErrorAndExit(const std::string_view &err)
|
||||
{
|
||||
std::cout << err << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void press::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
for (auto iter = parameters.begin(); iter != parameters.end(); iter++)
|
||||
@ -149,11 +156,29 @@ void press::handleCommand(std::vector<std::string> ¶meters)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// else if (param == "-k")
|
||||
// {
|
||||
// keepAlive_ = true;
|
||||
// continue;
|
||||
// }
|
||||
else if (param.find("-f") == 0)
|
||||
{
|
||||
if (param == "-f")
|
||||
{
|
||||
++iter;
|
||||
if (iter == parameters.end())
|
||||
{
|
||||
outputErrorAndExit("No http request json file!");
|
||||
}
|
||||
httpRequestJsonFile_ = *iter;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
httpRequestJsonFile_ = param.substr(2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (param == "-k")
|
||||
{
|
||||
certValidation_ = false;
|
||||
continue;
|
||||
}
|
||||
else if (param == "-q")
|
||||
{
|
||||
processIndication_ = false;
|
||||
@ -168,15 +193,15 @@ void press::handleCommand(std::vector<std::string> ¶meters)
|
||||
// std::cout << "c=" << numOfConnections_ << std::endl;
|
||||
// std::cout << "q=" << processIndication_ << std::endl;
|
||||
// std::cout << "url=" << url_ << std::endl;
|
||||
if (url_.empty() || url_.find("http") != 0 ||
|
||||
url_.find("://") == std::string::npos)
|
||||
if (url_.empty() || url_.compare(0, 4, "http") != 0 ||
|
||||
(url_.compare(4, 3, "://") != 0 && url_.compare(4, 4, "s://") != 0))
|
||||
{
|
||||
outputErrorAndExit("Invalid URL");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto pos = url_.find("://");
|
||||
auto posOfPath = url_.find("/", pos + 3);
|
||||
auto posOfPath = url_.find('/', pos + 3);
|
||||
if (posOfPath == std::string::npos)
|
||||
{
|
||||
host_ = url_;
|
||||
@ -188,6 +213,118 @@ void press::handleCommand(std::vector<std::string> ¶meters)
|
||||
path_ = url_.substr(posOfPath);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
http_request.json
|
||||
{
|
||||
"method": "POST",
|
||||
"header": {
|
||||
"token": "e2e9d0fe-dd14-4eaf-8ac1-0997730a805d"
|
||||
},
|
||||
"body": {
|
||||
"passwd": "123456",
|
||||
"account": "10001"
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (!httpRequestJsonFile_.empty())
|
||||
{
|
||||
Json::Value httpRequestJson;
|
||||
std::ifstream httpRequestFile(httpRequestJsonFile_,
|
||||
std::ifstream::binary);
|
||||
if (!httpRequestFile.is_open())
|
||||
{
|
||||
outputErrorAndExit(std::string{"No "} + httpRequestJsonFile_);
|
||||
}
|
||||
httpRequestFile >> httpRequestJson;
|
||||
|
||||
if (!httpRequestJson.isMember("method"))
|
||||
{
|
||||
outputErrorAndExit("No contain method");
|
||||
}
|
||||
|
||||
auto methodStr = httpRequestJson["method"].asString();
|
||||
std::transform(methodStr.begin(),
|
||||
methodStr.end(),
|
||||
methodStr.begin(),
|
||||
::toupper);
|
||||
|
||||
auto toHttpMethod = [&]() -> drogon::HttpMethod {
|
||||
if (methodStr == "GET")
|
||||
{
|
||||
return drogon::HttpMethod::Get;
|
||||
}
|
||||
else if (methodStr == "POST")
|
||||
{
|
||||
return drogon::HttpMethod::Post;
|
||||
}
|
||||
else if (methodStr == "HEAD")
|
||||
{
|
||||
return drogon::HttpMethod::Head;
|
||||
}
|
||||
else if (methodStr == "PUT")
|
||||
{
|
||||
return drogon::HttpMethod::Put;
|
||||
}
|
||||
else if (methodStr == "DELETE")
|
||||
{
|
||||
return drogon::HttpMethod::Delete;
|
||||
}
|
||||
else if (methodStr == "OPTIONS")
|
||||
{
|
||||
return drogon::HttpMethod::Options;
|
||||
}
|
||||
else if (methodStr == "PATCH")
|
||||
{
|
||||
return drogon::HttpMethod::Patch;
|
||||
}
|
||||
else
|
||||
{
|
||||
outputErrorAndExit("invalid method");
|
||||
}
|
||||
return drogon::HttpMethod::Get;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> header;
|
||||
if (httpRequestJson.isMember("header"))
|
||||
{
|
||||
auto &jsonValue = httpRequestJson["header"];
|
||||
for (const auto &key : jsonValue.getMemberNames())
|
||||
{
|
||||
if (jsonValue[key].isString())
|
||||
{
|
||||
header[key] = jsonValue[key].asString();
|
||||
}
|
||||
else
|
||||
{
|
||||
header[key] = jsonValue[key].toStyledString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string body;
|
||||
if (httpRequestJson.isMember("body"))
|
||||
{
|
||||
Json::FastWriter fastWriter;
|
||||
body = fastWriter.write(httpRequestJson["body"]);
|
||||
}
|
||||
|
||||
createHttpRequestFunc_ = [this,
|
||||
method = toHttpMethod(),
|
||||
body = std::move(body),
|
||||
header =
|
||||
std::move(header)]() -> HttpRequestPtr {
|
||||
auto request = HttpRequest::newHttpRequest();
|
||||
request->setPath(path_);
|
||||
request->setMethod(method);
|
||||
for (const auto &[field, val] : header)
|
||||
request->addHeader(field, val);
|
||||
if (!body.empty())
|
||||
request->setBody(body);
|
||||
return request;
|
||||
};
|
||||
}
|
||||
|
||||
// std::cout << "host=" << host_ << std::endl;
|
||||
// std::cout << "path=" << path_ << std::endl;
|
||||
doTesting();
|
||||
@ -214,8 +351,10 @@ void press::createRequestAndClients()
|
||||
loopPool_->start();
|
||||
for (size_t i = 0; i < numOfConnections_; ++i)
|
||||
{
|
||||
auto client =
|
||||
HttpClient::newHttpClient(host_, loopPool_->getNextLoop());
|
||||
auto client = HttpClient::newHttpClient(host_,
|
||||
loopPool_->getNextLoop(),
|
||||
false,
|
||||
certValidation_);
|
||||
client->enableCookies();
|
||||
clients_.push_back(client);
|
||||
}
|
||||
@ -228,9 +367,19 @@ void press::sendRequest(const HttpClientPtr &client)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto request = HttpRequest::newHttpRequest();
|
||||
request->setPath(path_);
|
||||
request->setMethod(Get);
|
||||
|
||||
HttpRequestPtr request;
|
||||
if (createHttpRequestFunc_)
|
||||
{
|
||||
request = createHttpRequestFunc_();
|
||||
}
|
||||
else
|
||||
{
|
||||
request = HttpRequest::newHttpRequest();
|
||||
request->setPath(path_);
|
||||
request->setMethod(Get);
|
||||
}
|
||||
|
||||
// std::cout << "send!" << std::endl;
|
||||
client->sendRequest(
|
||||
request,
|
||||
@ -282,7 +431,6 @@ void press::sendRequest(const HttpClientPtr &client)
|
||||
|
||||
void press::outputResults()
|
||||
{
|
||||
static std::mutex mtx;
|
||||
size_t totalSent = 0;
|
||||
size_t totalRecv = 0;
|
||||
for (auto &client : clients_)
|
||||
@ -294,7 +442,7 @@ void press::outputResults()
|
||||
auto microSecs = now.microSecondsSinceEpoch() -
|
||||
statistics_.startDate_.microSecondsSinceEpoch();
|
||||
double seconds = (double)microSecs / 1000000.0;
|
||||
size_t rps = static_cast<size_t>(statistics_.numOfGoodResponse_ / seconds);
|
||||
auto rps = static_cast<size_t>(statistics_.numOfGoodResponse_ / seconds);
|
||||
std::cout << std::endl;
|
||||
std::cout << "TOTALS: " << numOfConnections_ << " connect, "
|
||||
<< numOfRequests_ << " requests, "
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <drogon/HttpClient.h>
|
||||
#include <trantor/utils/Date.h>
|
||||
#include <trantor/net/EventLoopThreadPool.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
@ -39,26 +40,32 @@ struct Statistics
|
||||
trantor::Date startDate_;
|
||||
trantor::Date endDate_;
|
||||
};
|
||||
|
||||
class press : public DrObject<press>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "Do stress testing(Use 'drogon_ctl help press' for more "
|
||||
"information)";
|
||||
}
|
||||
virtual bool isTopCommand() override
|
||||
|
||||
bool isTopCommand() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual std::string detail() override;
|
||||
|
||||
std::string detail() override;
|
||||
|
||||
private:
|
||||
size_t numOfThreads_{1};
|
||||
size_t numOfRequests_{1};
|
||||
size_t numOfConnections_{1};
|
||||
// bool keepAlive_ = false;
|
||||
std::string httpRequestJsonFile_;
|
||||
std::function<HttpRequestPtr()> createHttpRequestFunc_;
|
||||
bool certValidation_{true};
|
||||
bool processIndication_{true};
|
||||
std::string url_;
|
||||
std::string host_;
|
||||
|
@ -1,59 +1,75 @@
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project([[ProjectName]] CXX)
|
||||
|
||||
include(CheckIncludeFileCXX)
|
||||
|
||||
check_include_file_cxx(any HAS_ANY)
|
||||
check_include_file_cxx(string_view HAS_STRING_VIEW)
|
||||
if(HAS_ANY AND HAS_STRING_VIEW)
|
||||
check_include_file_cxx(coroutine HAS_COROUTINE)
|
||||
if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
|
||||
# Do nothing
|
||||
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
elseif (HAS_ANY AND HAS_STRING_VIEW)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
else()
|
||||
else ()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cc)
|
||||
|
||||
##########
|
||||
# If you include the drogon source code locally in your project, use this method to add drogon
|
||||
# ##############################################################################
|
||||
# If you include the drogon source code locally in your project, use this method
|
||||
# to add drogon
|
||||
# add_subdirectory(drogon)
|
||||
# target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||
##########
|
||||
|
||||
#
|
||||
# and comment out the following lines
|
||||
find_package(Drogon CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
|
||||
|
||||
if(CMAKE_CXX_STANDARD LESS 17)
|
||||
#With C++14, use boost to support any and string_view
|
||||
message(STATUS "use c++14")
|
||||
find_package(Boost 1.61.0 REQUIRED)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
|
||||
else()
|
||||
# ##############################################################################
|
||||
|
||||
if (CMAKE_CXX_STANDARD LESS 17)
|
||||
message(FATAL_ERROR "c++17 or higher is required")
|
||||
elseif (CMAKE_CXX_STANDARD LESS 20)
|
||||
message(STATUS "use c++17")
|
||||
endif()
|
||||
else ()
|
||||
message(STATUS "use c++20")
|
||||
endif ()
|
||||
|
||||
aux_source_directory(controllers CTL_SRC)
|
||||
aux_source_directory(filters FILTER_SRC)
|
||||
aux_source_directory(plugins PLUGIN_SRC)
|
||||
aux_source_directory(models MODEL_SRC)
|
||||
|
||||
file(GLOB_RECURSE SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
message(STATUS "cspFile:" ${cspFile})
|
||||
get_filename_component(classname ${cspFile} NAME_WE)
|
||||
message(STATUS "view classname:" ${classname})
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${classname}.h ${classname}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS create view ${cspFile}
|
||||
DEPENDS ${cspFile}
|
||||
VERBATIM )
|
||||
set(VIEWSRC ${VIEWSRC} ${classname}.cc)
|
||||
endforeach()
|
||||
drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
# use the following line to create views with namespaces.
|
||||
# drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
|
||||
# ${CMAKE_CURRENT_BINARY_DIR} TRUE)
|
||||
# use the following line to create views with namespace CHANGE_ME prefixed
|
||||
# and path namespaces.
|
||||
# drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
|
||||
# ${CMAKE_CURRENT_BINARY_DIR} TRUE CHANGE_ME)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models)
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC})
|
||||
################################
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/models)
|
||||
target_sources(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${SRC_DIR}
|
||||
${CTL_SRC}
|
||||
${FILTER_SRC}
|
||||
${PLUGIN_SRC}
|
||||
${MODEL_SRC})
|
||||
# ##############################################################################
|
||||
# uncomment the following line for dynamically loading views
|
||||
#set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS ON)
|
||||
# set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS ON)
|
||||
|
||||
# ##############################################################################
|
||||
|
||||
add_subdirectory(test)
|
||||
|
350
drogon_ctl/templates/config_json.csp
Normal file
350
drogon_ctl/templates/config_json.csp
Normal file
@ -0,0 +1,350 @@
|
||||
/* This is a JSON format configuration file
|
||||
*/
|
||||
{
|
||||
/*
|
||||
//ssl:The global SSL settings. "key" and "cert" are the path to the SSL key and certificate. While
|
||||
// "conf" is an array of 1 or 2-element tuples that supplies file style options for `SSL_CONF_cmd`.
|
||||
"ssl": {
|
||||
"cert": "../../trantor/trantor/tests/server.crt",
|
||||
"key": "../../trantor/trantor/tests/server.key",
|
||||
"conf": [
|
||||
//["Options", "-SessionTicket"],
|
||||
//["Options", "Compression"]
|
||||
]
|
||||
},
|
||||
"listeners": [
|
||||
{
|
||||
//address: Ip address,0.0.0.0 by default
|
||||
"address": "0.0.0.0",
|
||||
//port: Port number
|
||||
"port": 80,
|
||||
//https: If true, use https for security,false by default
|
||||
"https": false
|
||||
},
|
||||
{
|
||||
"address": "0.0.0.0",
|
||||
"port": 443,
|
||||
"https": true,
|
||||
//cert,key: Cert file path and key file path, empty by default,
|
||||
//if empty, use the global setting
|
||||
"cert": "",
|
||||
"key": "",
|
||||
//use_old_tls: enable the TLS1.0/1.1, false by default
|
||||
"use_old_tls": false,
|
||||
"ssl_conf": [
|
||||
//["MinProtocol", "TLSv1.3"]
|
||||
]
|
||||
}
|
||||
],
|
||||
"db_clients": [
|
||||
{
|
||||
//name: Name of the client,'default' by default
|
||||
"name": "default",
|
||||
//rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
|
||||
"rdbms": "postgresql",
|
||||
//filename: Sqlite3 db file name
|
||||
//"filename":"",
|
||||
//host: Server address,localhost by default
|
||||
"host": "127.0.0.1",
|
||||
//port: Server port, 5432 by default
|
||||
"port": 5432,
|
||||
//dbname: Database name
|
||||
"dbname": "test",
|
||||
//user: 'postgres' by default
|
||||
"user": "",
|
||||
//passwd: '' by default
|
||||
"passwd": "",
|
||||
//is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
//any synchronous interface of it.
|
||||
"is_fast": false,
|
||||
//client_encoding: The character set used by the client. it is empty string by default which
|
||||
//means use the default character set.
|
||||
//"client_encoding": "",
|
||||
//number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
//connections per IO thread, otherwise it is the total number of all connections.
|
||||
"number_of_connections": 1,
|
||||
//timeout: -1.0 by default, in seconds, the timeout for executing a SQL query.
|
||||
//zero or negative value means no timeout.
|
||||
"timeout": -1.0,
|
||||
//auto_batch: this feature is only available for the PostgreSQL driver(version >= 14.0), see
|
||||
//the wiki for more details.
|
||||
"auto_batch": false
|
||||
//connect_options: extra options for the connection. Only works for PostgreSQL now.
|
||||
//For more information, see https://www.postgresql.org/docs/16/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
|
||||
//"connect_options": { "statement_timeout": "1s" }
|
||||
}
|
||||
],
|
||||
"redis_clients": [
|
||||
{
|
||||
//name: Name of the client,'default' by default
|
||||
"name": "default",
|
||||
//host: Server IP, 127.0.0.1 by default
|
||||
"host": "127.0.0.1",
|
||||
//port: Server port, 6379 by default
|
||||
"port": 6379,
|
||||
//username: '' by default which means 'default' in redis ACL
|
||||
"username": "",
|
||||
//passwd: '' by default
|
||||
"passwd": "",
|
||||
//db index: 0 by default
|
||||
"db": 0,
|
||||
//is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
//any synchronous interface of it.
|
||||
"is_fast": false,
|
||||
//number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
//connections per IO thread, otherwise it is the total number of all connections.
|
||||
"number_of_connections": 1,
|
||||
//timeout: -1.0 by default, in seconds, the timeout for executing a command.
|
||||
//zero or negative value means no timeout.
|
||||
"timeout": -1.0
|
||||
}
|
||||
],*/
|
||||
"app": {
|
||||
//number_of_threads: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
//is the number of CPU cores
|
||||
"number_of_threads": 1,
|
||||
//enable_session: False by default
|
||||
"enable_session": false,
|
||||
"session_timeout": 0,
|
||||
//string value of SameSite attribute of the Set-Cookie HTTP response header
|
||||
//valid value is either 'Null' (default), 'Lax', 'Strict' or 'None'
|
||||
"session_same_site" : "Null",
|
||||
//session_cookie_key: The cookie key of the session, "JSESSIONID" by default
|
||||
"session_cookie_key": "JSESSIONID",
|
||||
//session_max_age: The max age of the session cookie, -1 by default
|
||||
"session_max_age": -1,
|
||||
//document_root: Root path of HTTP document, default path is ./
|
||||
"document_root": "./",
|
||||
//home_page: Set the HTML file of the home page, the default value is "index.html"
|
||||
//If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
|
||||
//to the request for "/".
|
||||
"home_page": "index.html",
|
||||
//use_implicit_page: enable implicit pages if true, true by default
|
||||
"use_implicit_page": true,
|
||||
//implicit_page: Set the file which would the server access in a directory that a user accessed.
|
||||
//For example, by default, http://localhost/a-directory resolves to http://localhost/a-directory/index.html.
|
||||
"implicit_page": "index.html",
|
||||
//static_file_headers: Headers for static files
|
||||
/*"static_file_headers": [
|
||||
{
|
||||
"name": "field-name",
|
||||
"value": "field-value"
|
||||
}
|
||||
],*/
|
||||
//upload_path: The path to save the uploaded file. "uploads" by default.
|
||||
//If the path isn't prefixed with /, ./ or ../,
|
||||
//it is relative path of document_root path
|
||||
"upload_path": "uploads",
|
||||
/* file_types:
|
||||
* HTTP download file types,The file types supported by drogon
|
||||
* by default are "html", "js", "css", "xml", "xsl", "txt", "svg",
|
||||
* "ttf", "otf", "woff2", "woff" , "eot", "png", "jpg", "jpeg",
|
||||
* "gif", "bmp", "ico", "icns", etc. */
|
||||
"file_types": [
|
||||
"gif",
|
||||
"png",
|
||||
"jpg",
|
||||
"js",
|
||||
"css",
|
||||
"html",
|
||||
"ico",
|
||||
"swf",
|
||||
"xap",
|
||||
"apk",
|
||||
"cur",
|
||||
"xml",
|
||||
"webp",
|
||||
"svg"
|
||||
],
|
||||
// mime: A dictionary that extends the internal MIME type support. Maps extensions into new MIME types
|
||||
// note: This option only adds MIME to the sever. `file_types` above have to be set for the server to serve them.
|
||||
"mime": {
|
||||
// "text/markdown": "md",
|
||||
// "text/gemini": ["gmi", "gemini"]
|
||||
},
|
||||
//locations: An array of locations of static files for GET requests.
|
||||
"locations": [
|
||||
{
|
||||
//uri_prefix: The URI prefix of the location prefixed with "/", the default value is "" that disables the location.
|
||||
//"uri_prefix": "/.well-known/acme-challenge/",
|
||||
//default_content_type: The default content type of the static files without
|
||||
//an extension. empty string by default.
|
||||
"default_content_type": "text/plain",
|
||||
//alias: The location in file system, if it is prefixed with "/", it
|
||||
//presents an absolute path, otherwise it presents a relative path to
|
||||
//the document_root path.
|
||||
//The default value is "" which means use the document root path as the location base path.
|
||||
"alias": "",
|
||||
//is_case_sensitive: indicates whether the URI prefix is case sensitive.
|
||||
"is_case_sensitive": false,
|
||||
//allow_all: true by default. If it is set to false, only static files with a valid extension can be accessed.
|
||||
"allow_all": true,
|
||||
//is_recursive: true by default. If it is set to false, files in sub directories can't be accessed.
|
||||
"is_recursive": true,
|
||||
//filters: string array, the filters applied to the location.
|
||||
"filters": []
|
||||
}
|
||||
],
|
||||
//max_connections: maximum number of connections, 100000 by default
|
||||
"max_connections": 100000,
|
||||
//max_connections_per_ip: maximum number of connections per client, 0 by default which means no limit
|
||||
"max_connections_per_ip": 0,
|
||||
//Load_dynamic_views: False by default, when set to true, drogon
|
||||
//compiles and loads dynamically "CSP View Files" in directories defined
|
||||
//by "dynamic_views_path"
|
||||
"load_dynamic_views": false,
|
||||
//dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
|
||||
//it is relative path of document_root path
|
||||
"dynamic_views_path": [
|
||||
"./views"
|
||||
],
|
||||
//dynamic_views_output_path: Default by an empty string which means the output path of source
|
||||
//files is the path where the csp files locate. If the path isn't prefixed with /, it is relative
|
||||
//path of the current working directory.
|
||||
"dynamic_views_output_path": "",
|
||||
//json_parser_stack_limit: 1000 by default, the maximum number of stack depth when reading a json string by the jsoncpp library.
|
||||
"json_parser_stack_limit": 1000,
|
||||
//enable_unicode_escaping_in_json: true by default, enable unicode escaping in json.
|
||||
"enable_unicode_escaping_in_json": true,
|
||||
//float_precision_in_json: set precision of float number in json.
|
||||
"float_precision_in_json": {
|
||||
//precision: 0 by default, 0 means use the default precision of the jsoncpp lib.
|
||||
"precision": 0,
|
||||
//precision_type: must be "significant" or "decimal", defaults to "significant" that means
|
||||
//setting max number of significant digits in string, "decimal" means setting max number of
|
||||
//digits after "." in string
|
||||
"precision_type": "significant"
|
||||
},
|
||||
//log: Set log output, drogon output logs to stdout by default
|
||||
"log": {
|
||||
//use_spdlog: Use spdlog library to log
|
||||
"use_spdlog": false,
|
||||
//log_path: Log file path,empty by default,in which case,logs are output to the stdout
|
||||
//"log_path": "./",
|
||||
//logfile_base_name: Log file base name,empty by default which means drogon names logfile as
|
||||
//drogon.log ...
|
||||
"logfile_base_name": "",
|
||||
//log_size_limit: 100000000 bytes by default,
|
||||
//When the log file size reaches "log_size_limit", the log file is switched.
|
||||
"log_size_limit": 100000000,
|
||||
//max_files: 0 by default,
|
||||
//When the number of old log files exceeds "max_files", the oldest file will be deleted. 0 means never delete.
|
||||
"max_files": 0,
|
||||
//log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
|
||||
//The TRACE level is only valid when built in DEBUG mode.
|
||||
"log_level": "DEBUG",
|
||||
//display_local_time: false by default, if true, the log time is displayed in local time
|
||||
"display_local_time": false
|
||||
},
|
||||
//run_as_daemon: False by default
|
||||
"run_as_daemon": false,
|
||||
//handle_sig_term: True by default
|
||||
"handle_sig_term": true,
|
||||
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
"relaunch_on_error": false,
|
||||
//use_sendfile: True by default, if true, the program
|
||||
//uses sendfile() system-call to send static files to clients;
|
||||
"use_sendfile": true,
|
||||
//use_gzip: True by default, use gzip to compress the response body's content;
|
||||
"use_gzip": true,
|
||||
//use_brotli: False by default, use brotli to compress the response body's content;
|
||||
"use_brotli": false,
|
||||
//static_files_cache_time: 5 (seconds) by default, the time in which the static file response is cached,
|
||||
//0 means cache forever, the negative value means no cache
|
||||
"static_files_cache_time": 5,
|
||||
//simple_controllers_map: Used to configure mapping from path to simple controller
|
||||
//"simple_controllers_map": [
|
||||
// {
|
||||
// "path": "/path/name",
|
||||
// "controller": "controllerClassName",
|
||||
// "http_methods": [
|
||||
// "get",
|
||||
// "post"
|
||||
// ],
|
||||
// "filters": [
|
||||
// "FilterClassName"
|
||||
// ]
|
||||
// }
|
||||
//],
|
||||
//idle_connection_timeout: Defaults to 60 seconds, the lifetime
|
||||
//of the connection without read or write
|
||||
"idle_connection_timeout": 60,
|
||||
//server_header_field: Set the 'Server' header field in each response sent by drogon,
|
||||
//empty string by default with which the 'Server' header field is set to "Server: drogon/version string\r\n"
|
||||
"server_header_field": "",
|
||||
//enable_server_header: Set true to force drogon to add a 'Server' header to each HTTP response. The default
|
||||
//value is true.
|
||||
"enable_server_header": true,
|
||||
//enable_date_header: Set true to force drogon to add a 'Date' header to each HTTP response. The default
|
||||
//value is true.
|
||||
"enable_date_header": true,
|
||||
//keepalive_requests: Set the maximum number of requests that can be served through one keep-alive connection.
|
||||
//After the maximum number of requests are made, the connection is closed.
|
||||
//The default value of 0 means no limit.
|
||||
"keepalive_requests": 0,
|
||||
//pipelining_requests: Set the maximum number of unhandled requests that can be cached in pipelining buffer.
|
||||
//After the maximum number of requests are made, the connection is closed.
|
||||
//The default value of 0 means no limit.
|
||||
"pipelining_requests": 0,
|
||||
//gzip_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
//file with the extension ".gz" in the same path and send the compressed file to the client.
|
||||
//The default value of gzip_static is true.
|
||||
"gzip_static": true,
|
||||
//br_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
//file with the extension ".br" in the same path and send the compressed file to the client.
|
||||
//The default value of br_static is true.
|
||||
"br_static": true,
|
||||
//client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M".
|
||||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
"client_max_body_size": "1M",
|
||||
//max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes.
|
||||
//If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
|
||||
//Setting it to "" means no limit.
|
||||
"client_max_memory_body_size": "64K",
|
||||
//client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
|
||||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
"client_max_websocket_message_size": "128K",
|
||||
//reuse_port: Defaults to false, users can run multiple processes listening on the same port at the same time.
|
||||
"reuse_port": false,
|
||||
// enabled_compressed_request: Defaults to false. If true the server will automatically decompress compressed request bodies.
|
||||
// Currently only gzip and br are supported. Note: max_memory_body_size and max_body_size applies twice for compressed requests.
|
||||
// Once when receiving and once when decompressing. i.e. if the decompressed body is larger than max_body_size, the request
|
||||
// will be rejected.
|
||||
"enabled_compressed_request": false,
|
||||
// enable_request_stream: Defaults to false. If true the server will enable stream mode for http requests.
|
||||
// See the wiki for more details.
|
||||
"enable_request_stream": false,
|
||||
},
|
||||
//plugins: Define all plugins running in the application
|
||||
"plugins": [
|
||||
{
|
||||
//name: The class name of the plugin
|
||||
"name": "drogon::plugin::PromExporter",
|
||||
//dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
"dependencies": [],
|
||||
//config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
//It can be commented out
|
||||
"config": {
|
||||
"path": "/metrics"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drogon::plugin::AccessLogger",
|
||||
"dependencies": [],
|
||||
"config": {
|
||||
"use_spdlog": false,
|
||||
"log_path": "",
|
||||
"log_format": "",
|
||||
"log_file": "access.log",
|
||||
"log_size_limit": 0,
|
||||
"use_local_time": true,
|
||||
"log_index": 0,
|
||||
// "show_microseconds": true,
|
||||
// "custom_time_format": "",
|
||||
// "use_real_ip": false
|
||||
}
|
||||
}
|
||||
],
|
||||
//custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method.
|
||||
"custom_config": {}
|
||||
}
|
313
drogon_ctl/templates/config_yaml.csp
Normal file
313
drogon_ctl/templates/config_yaml.csp
Normal file
@ -0,0 +1,313 @@
|
||||
# This is a YAML format configuration file
|
||||
|
||||
# ssl:The global SSL settings. "key" and "cert" are the path to the SSL key and certificate. While
|
||||
# "conf" is an array of 1 or 2-element tuples that supplies file style options for `SSL_CONF_cmd`.
|
||||
# ssl:
|
||||
# cert: ../../trantor/trantor/tests/server.crt
|
||||
# key: ../../trantor/trantor/tests/server.key
|
||||
# conf: [
|
||||
# # [Options, -SessionTicket],
|
||||
# # [Options, Compression]
|
||||
# ]
|
||||
# listeners:
|
||||
# # address: Ip address,0.0.0.0 by default
|
||||
# - address: 0.0.0.0
|
||||
# # port: Port number
|
||||
# port: 80
|
||||
# # https: If true, use https for security,false by default
|
||||
# https: false
|
||||
# - address: 0.0.0.0
|
||||
# port: 443
|
||||
# https: true
|
||||
# # cert,key: Cert file path and key file path, empty by default,
|
||||
# # if empty, use the global setting
|
||||
# cert: ''
|
||||
# key: ''
|
||||
# # use_old_tls: enable the TLS1.0/1.1, false by default
|
||||
# use_old_tls: false
|
||||
# ssl_conf: [
|
||||
# # [MinProtocol, TLSv1.3]
|
||||
# ]
|
||||
# db_clients:
|
||||
# # name: Name of the client,'default' by default
|
||||
# - name: default
|
||||
# # rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
|
||||
# rdbms: postgresql
|
||||
# # filename: Sqlite3 db file name
|
||||
# # filename: ''
|
||||
# # host: Server address,localhost by default
|
||||
# host: 127.0.0.1
|
||||
# # port: Server port, 5432 by default
|
||||
# port: 5432
|
||||
# # dbname: Database name
|
||||
# dbname: test
|
||||
# # user: 'postgres' by default
|
||||
# user: ''
|
||||
# # passwd: '' by default
|
||||
# passwd: ''
|
||||
# # is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
# # any synchronous interface of it.
|
||||
# is_fast: false
|
||||
# # client_encoding: The character set used by the client. it is empty string by default which
|
||||
# # means use the default character set.
|
||||
# # client_encoding: ''
|
||||
# # number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
# # connections per IO thread, otherwise it is the total number of all connections.
|
||||
# number_of_connections: 1
|
||||
# # timeout: -1 by default, in seconds, the timeout for executing a SQL query.
|
||||
# # zero or negative value means no timeout.
|
||||
# timeout: -1
|
||||
# # auto_batch: this feature is only available for the PostgreSQL driver(version >= 14.0), see
|
||||
# # the wiki for more details.
|
||||
# auto_batch: false
|
||||
# # connect_options: extra options for the connection. Only works for PostgreSQL now.
|
||||
# # For more information, see https://www.postgresql.org/docs/16/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
|
||||
# # connect_options:
|
||||
# # statement_timeout: '1s'
|
||||
# redis_clients:
|
||||
# # name: Name of the client,'default' by default
|
||||
# - name: default
|
||||
# # host: Server IP, 127.0.0.1 by default
|
||||
# host: 127.0.0.1
|
||||
# # port: Server port, 6379 by default
|
||||
# port: 6379
|
||||
# # username: '' by default which means 'default' in redis ACL
|
||||
# username: ''
|
||||
# # passwd: '' by default
|
||||
# passwd: ''
|
||||
# # db index: 0 by default
|
||||
# db: 0
|
||||
# # is_fast: false by default, if it is true, the client is faster but user can't call
|
||||
# # any synchronous interface of it.
|
||||
# is_fast: false
|
||||
# # number_of_connections: 1 by default, if the 'is_fast' is true, the number is the number of
|
||||
# # connections per IO thread, otherwise it is the total number of all connections.
|
||||
# number_of_connections: 1
|
||||
# # timeout: -1.0 by default, in seconds, the timeout for executing a command.
|
||||
# # zero or negative value means no timeout.
|
||||
# timeout: -1
|
||||
app:
|
||||
# number_of_threads: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
|
||||
# is the number of CPU cores
|
||||
number_of_threads: 1
|
||||
# enable_session: False by default
|
||||
enable_session: false
|
||||
session_timeout: 0
|
||||
# string value of SameSite attribute of the Set-Cookie HTTP response header
|
||||
# valid value is either 'Null' (default), 'Lax', 'Strict' or 'None'
|
||||
session_same_site: 'Null'
|
||||
# session_cookie_key: The cookie key of the session, "JSESSIONID" by default
|
||||
session_cookie_key: 'JSESSIONID'
|
||||
# session_max_age: The max age of the session cookie, -1 by default
|
||||
session_max_age: -1
|
||||
# document_root: Root path of HTTP document, default path is ./
|
||||
document_root: ./
|
||||
# home_page: Set the HTML file of the home page, the default value is "index.html"
|
||||
# If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
|
||||
# to the request for "/".
|
||||
home_page: index.html
|
||||
# use_implicit_page: enable implicit pages if true, true by default
|
||||
use_implicit_page: true
|
||||
# implicit_page: Set the file which would the server access in a directory that a user accessed.
|
||||
# For example, by default, http://localhost/a-directory resolves to http://localhost/a-directory/index.html.
|
||||
implicit_page: index.html
|
||||
# static_file_headers: Headers for static files
|
||||
# static_file_headers:
|
||||
# - name: field-name
|
||||
# value: field-value
|
||||
# upload_path: The path to save the uploaded file. "uploads" by default.
|
||||
# If the path isn't prefixed with /, ./ or ../,
|
||||
# it is relative path of document_root path
|
||||
upload_path: uploads
|
||||
# file_types:
|
||||
# HTTP download file types,The file types supported by drogon
|
||||
# by default are "html", "js", "css", "xml", "xsl", "txt", "svg",
|
||||
# "ttf", "otf", "woff2", "woff" , "eot", "png", "jpg", "jpeg",
|
||||
# "gif", "bmp", "ico", "icns", etc.
|
||||
file_types:
|
||||
- gif
|
||||
- png
|
||||
- jpg
|
||||
- js
|
||||
- css
|
||||
- html
|
||||
- ico
|
||||
- swf
|
||||
- xap
|
||||
- apk
|
||||
- cur
|
||||
- xml
|
||||
# mime: A dictionary that extends the internal MIME type support. Maps extensions into new MIME types
|
||||
# note: This option only adds MIME to the sever. `file_types` above have to be set for the server to serve them.
|
||||
mime: {
|
||||
# text/markdown: md
|
||||
# text/gemini:
|
||||
# - gmi
|
||||
# - gemini
|
||||
}
|
||||
# locations: An array of locations of static files for GET requests.
|
||||
locations:
|
||||
# uri_prefix: The URI prefix of the location prefixed with "/", the default value is "" that disables the location.
|
||||
- uri_prefix: '' # /.well-known/acme-challenge/
|
||||
# default_content_type: The default content type of the static files without
|
||||
# an extension. empty string by default.
|
||||
default_content_type: text/plain
|
||||
# alias: The location in file system, if it is prefixed with "/", it
|
||||
# presents an absolute path, otherwise it presents a relative path to
|
||||
# the document_root path.
|
||||
# The default value is "" which means use the document root path as the location base path.
|
||||
alias: ''
|
||||
# is_case_sensitive: indicates whether the URI prefix is case sensitive.
|
||||
is_case_sensitive: false
|
||||
# allow_all: true by default. If it is set to false, only static files with a valid extension can be accessed.
|
||||
allow_all: true
|
||||
# is_recursive: true by default. If it is set to false, files in sub directories can't be accessed.
|
||||
is_recursive: true
|
||||
# filters: string array, the filters applied to the location.
|
||||
filters: []
|
||||
# max_connections: maximum number of connections, 100000 by default
|
||||
max_connections: 100000
|
||||
# max_connections_per_ip: maximum number of connections per client, 0 by default which means no limit
|
||||
max_connections_per_ip: 0
|
||||
# Load_dynamic_views: False by default, when set to true, drogon
|
||||
# compiles and loads dynamically "CSP View Files" in directories defined
|
||||
# by "dynamic_views_path"
|
||||
load_dynamic_views: false
|
||||
# dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
|
||||
# it is relative path of document_root path
|
||||
dynamic_views_path:
|
||||
- ./views
|
||||
# dynamic_views_output_path: Default by an empty string which means the output path of source
|
||||
# files is the path where the csp files locate. If the path isn't prefixed with /, it is relative
|
||||
# path of the current working directory.
|
||||
dynamic_views_output_path: ''
|
||||
# json_parser_stack_limit: 1000 by default, the maximum number of stack depth when reading a json string by the jsoncpp library.
|
||||
json_parser_stack_limit: 1000
|
||||
# enable_unicode_escaping_in_json: true by default, enable unicode escaping in json.
|
||||
enable_unicode_escaping_in_json: true
|
||||
# float_precision_in_json: set precision of float number in json.
|
||||
float_precision_in_json:
|
||||
# precision: 0 by default, 0 means use the default precision of the jsoncpp lib.
|
||||
precision: 0
|
||||
# precision_type: must be "significant" or "decimal", defaults to "significant" that means
|
||||
# setting max number of significant digits in string, "decimal" means setting max number of
|
||||
# digits after "." in string
|
||||
precision_type: significant
|
||||
# log: Set log output, drogon output logs to stdout by default
|
||||
log:
|
||||
# use_spdlog: Use spdlog library to log
|
||||
use_spdlog: false
|
||||
# log_path: Log file path,empty by default,in which case,logs are output to the stdout
|
||||
# log_path: ./
|
||||
# logfile_base_name: Log file base name,empty by default which means drogon names logfile as
|
||||
# drogon.log ...
|
||||
logfile_base_name: ''
|
||||
# log_size_limit: 100000000 bytes by default,
|
||||
# When the log file size reaches "log_size_limit", the log file is switched.
|
||||
log_size_limit: 100000000
|
||||
# max_files: 0 by default,
|
||||
# When the number of old log files exceeds "max_files", the oldest file will be deleted. 0 means never delete.
|
||||
max_files: 0
|
||||
# log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
|
||||
# The TRACE level is only valid when built in DEBUG mode.
|
||||
log_level: DEBUG
|
||||
# display_local_time: false by default, if true, the log time is displayed in local time
|
||||
display_local_time: false
|
||||
# run_as_daemon: False by default
|
||||
run_as_daemon: false
|
||||
# handle_sig_term: True by default
|
||||
handle_sig_term: true
|
||||
# relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
|
||||
relaunch_on_error: false
|
||||
# use_sendfile: True by default, if true, the program
|
||||
# uses sendfile() system-call to send static files to clients;
|
||||
use_sendfile: true
|
||||
# use_gzip: True by default, use gzip to compress the response body's content;
|
||||
use_gzip: true
|
||||
# use_brotli: False by default, use brotli to compress the response body's content;
|
||||
use_brotli: false
|
||||
# static_files_cache_time: 5 (seconds) by default, the time in which the static file response is cached,
|
||||
# 0 means cache forever, the negative value means no cache
|
||||
static_files_cache_time: 5
|
||||
# simple_controllers_map: Used to configure mapping from path to simple controller
|
||||
# simple_controllers_map:
|
||||
# - path: /path/name
|
||||
# controller: controllerClassName
|
||||
# http_methods:
|
||||
# - get
|
||||
# - post
|
||||
# filters:
|
||||
# - FilterClassName
|
||||
# idle_connection_timeout: Defaults to 60 seconds, the lifetime
|
||||
# of the connection without read or write
|
||||
idle_connection_timeout: 60
|
||||
# server_header_field: Set the 'Server' header field in each response sent by drogon,
|
||||
# empty string by default with which the 'Server' header field is set to "Server: drogon/version string\r\n"
|
||||
server_header_field: ''
|
||||
# enable_server_header: Set true to force drogon to add a 'Server' header to each HTTP response. The default
|
||||
# value is true.
|
||||
enable_server_header: true
|
||||
# enable_date_header: Set true to force drogon to add a 'Date' header to each HTTP response. The default
|
||||
# value is true.
|
||||
enable_date_header: true
|
||||
# keepalive_requests: Set the maximum number of requests that can be served through one keep-alive connection.
|
||||
# After the maximum number of requests are made, the connection is closed.
|
||||
# The default value of 0 means no limit.
|
||||
keepalive_requests: 0
|
||||
# pipelining_requests: Set the maximum number of unhandled requests that can be cached in pipelining buffer.
|
||||
# After the maximum number of requests are made, the connection is closed.
|
||||
# The default value of 0 means no limit.
|
||||
pipelining_requests: 0
|
||||
# gzip_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
# file with the extension ".gz" in the same path and send the compressed file to the client.
|
||||
# The default value of gzip_static is true.
|
||||
gzip_static: true
|
||||
# br_static: If it is set to true, when the client requests a static file, drogon first finds the compressed
|
||||
# file with the extension ".br" in the same path and send the compressed file to the client.
|
||||
# The default value of br_static is true.
|
||||
br_static: true
|
||||
# client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M".
|
||||
# One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
client_max_body_size: 1M
|
||||
# max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes.
|
||||
# If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
|
||||
# Setting it to "" means no limit.
|
||||
client_max_memory_body_size: 64K
|
||||
# client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
|
||||
# One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
|
||||
client_max_websocket_message_size: 128K
|
||||
# reuse_port: Defaults to false, users can run multiple processes listening on the same port at the same time.
|
||||
reuse_port: false
|
||||
# enabled_compressed_request: Defaults to false. If true the server will automatically decompress compressed request bodies.
|
||||
# Currently only gzip and br are supported. Note: max_memory_body_size and max_body_size applies twice for compressed requests.
|
||||
# Once when receiving and once when decompressing. i.e. if the decompressed body is larger than max_body_size, the request
|
||||
# will be rejected.
|
||||
enabled_compressed_request: false
|
||||
# enable_request_stream: Defaults to false. If true the server will enable stream mode for http requests.
|
||||
# See the wiki for more details.
|
||||
enable_request_stream: false
|
||||
# plugins: Define all plugins running in the application
|
||||
plugins:
|
||||
# name: The class name of the plugin
|
||||
- name: drogon::plugin::PromExporter
|
||||
# dependencies: Plugins that the plugin depends on. It can be commented out
|
||||
dependencies: []
|
||||
# config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
|
||||
# It can be commented out
|
||||
config:
|
||||
path: /metrics
|
||||
- name: drogon::plugin::AccessLogger
|
||||
dependencies: []
|
||||
config:
|
||||
use_spdlog: false
|
||||
log_path: ''
|
||||
log_format: ''
|
||||
log_file: access.log
|
||||
log_size_limit: 0
|
||||
use_local_time: true
|
||||
log_index: 0
|
||||
# show_microseconds: true
|
||||
# custom_time_format: ''
|
||||
# use_real_ip: false
|
||||
# custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method.
|
||||
custom_config: {}
|
@ -1,9 +1,10 @@
|
||||
#include <drogon/drogon.h>
|
||||
int main() {
|
||||
//Set HTTP listener address and port
|
||||
drogon::app().addListener("0.0.0.0",80);
|
||||
drogon::app().addListener("0.0.0.0", 5555);
|
||||
//Load config file
|
||||
//drogon::app().loadConfigFile("../config.json");
|
||||
//drogon::app().loadConfigFile("../config.yaml");
|
||||
//Run HTTP framework,the method will block in the internal event loop
|
||||
drogon::app().run();
|
||||
return 0;
|
||||
|
@ -22,9 +22,9 @@ class [[className]] : public HttpFilter<[[className]]>
|
||||
{
|
||||
public:
|
||||
[[className]]() {}
|
||||
virtual void doFilter(const HttpRequestPtr &req,
|
||||
FilterCallback &&fcb,
|
||||
FilterChainCallback &&fccb) override;
|
||||
void doFilter(const HttpRequestPtr &req,
|
||||
FilterCallback &&fcb,
|
||||
FilterChainCallback &&fccb) override;
|
||||
};
|
||||
|
||||
<%c++for(size_t i=0;i<namespaceVector.size();i++){%>
|
||||
|
@ -1,20 +1,73 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,visualstudio,visualstudiocode,cmake,c,c++
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,visualstudio,visualstudiocode,cmake,c,c++
|
||||
|
||||
### C ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
### C++ ###
|
||||
# Prerequisites
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
|
||||
# Precompiled Headers
|
||||
|
||||
# Linker files
|
||||
|
||||
# Debugger Files
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
@ -22,15 +75,487 @@
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
build
|
||||
cmake-build-debug
|
||||
.idea
|
||||
### CMake ###
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
CMakeUserPresets.json
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
*.code-workspace
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
### VisualStudio ###
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.meta
|
||||
*.iobj
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*[.json, .xml, .info]
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
### VisualStudio Patch ###
|
||||
# Additional files built by Visual Studio
|
||||
*.tlog
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,visualstudio,visualstudiocode,cmake,c,c++
|
File diff suppressed because it is too large
Load Diff
@ -14,17 +14,21 @@ using namespace drogon_ctl;
|
||||
#include <drogon/orm/Field.h>
|
||||
#include <drogon/orm/SqlBinder.h>
|
||||
#include <drogon/orm/Mapper.h>
|
||||
#include <drogon/orm/BaseBuilder.h>
|
||||
#ifdef __cpp_impl_coroutine
|
||||
#include <drogon/orm/CoroMapper.h>
|
||||
#endif
|
||||
#include <trantor/utils/Date.h>
|
||||
#include <trantor/utils/Logger.h>
|
||||
#include <json/json.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace drogon::orm;
|
||||
namespace drogon
|
||||
{
|
||||
namespace orm
|
||||
@ -39,27 +43,32 @@ namespace [[dbName]]
|
||||
{
|
||||
<%c++
|
||||
auto &schema=@@.get<std::string>("schema");
|
||||
if(!schema.empty())
|
||||
{
|
||||
$$<<"namespace "<<schema<<"\n";
|
||||
$$<<"{\n";
|
||||
}
|
||||
auto &relationships=@@.get<std::vector<Relationship>>("relationships");
|
||||
if(!schema.empty())
|
||||
{
|
||||
$$<<"namespace "<<schema<<"\n";
|
||||
$$<<"{\n";
|
||||
}
|
||||
std::vector<std::string> relationshipClassNames;
|
||||
auto &relationships=@@.get<std::vector<Relationship>>("relationships");
|
||||
for(auto &relationship : relationships)
|
||||
{
|
||||
auto &name=relationship.targetTableName();
|
||||
auto relationshipClassName=nameTransform(name, true);
|
||||
auto &name = relationship.targetTableName();
|
||||
auto relationshipClassName = nameTransform(name, true);
|
||||
relationshipClassNames.push_back(relationshipClassName);
|
||||
if(relationship.type() == Relationship::Type::ManyToMany)
|
||||
{
|
||||
auto &pivotTableName = relationship.pivotTable().tableName();
|
||||
auto pivotTableClassName = nameTransform(pivotTableName, true);
|
||||
relationshipClassNames.push_back(pivotTableClassName);
|
||||
}
|
||||
}
|
||||
std::sort(relationshipClassNames.begin(), relationshipClassNames.end());
|
||||
relationshipClassNames.erase(std::unique(relationshipClassNames.begin(), relationshipClassNames.end()), relationshipClassNames.end());
|
||||
for(std::string &relationshipClassName : relationshipClassNames)
|
||||
{
|
||||
%>
|
||||
class {%relationshipClassName%};
|
||||
<%c++
|
||||
if(relationship.type() == Relationship::Type::ManyToMany)
|
||||
{
|
||||
auto &pivotTableName=relationship.pivotTable().tableName();
|
||||
auto pivotTableClassName=nameTransform(pivotTableName, true);
|
||||
%>
|
||||
class {%pivotTableClassName%};
|
||||
<%c++
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
@ -77,11 +86,11 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
%>
|
||||
};
|
||||
|
||||
const static int primaryKeyNumber;
|
||||
const static std::string tableName;
|
||||
const static bool hasPrimaryKey;
|
||||
static const int primaryKeyNumber;
|
||||
static const std::string tableName;
|
||||
static const bool hasPrimaryKey;
|
||||
<%c++if(@@.get<int>("hasPrimaryKey")<=1){%>
|
||||
const static std::string primaryKeyName;
|
||||
static const std::string primaryKeyName;
|
||||
<%c++if(!@@.get<std::string>("primaryKeyType").empty()){%>
|
||||
using PrimaryKeyType = [[primaryKeyType]];
|
||||
const PrimaryKeyType &getPrimaryKey() const;
|
||||
@ -99,7 +108,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
typelist += ",";
|
||||
}
|
||||
%>
|
||||
const static std::vector<std::string> primaryKeyName;
|
||||
static const std::vector<std::string> primaryKeyName;
|
||||
using PrimaryKeyType = std::tuple<{%typelist%}>;//<%c++
|
||||
auto pkName=@@.get<std::vector<std::string>>("primaryKeyName");
|
||||
for(size_t i=0;i<pkName.size();i++)
|
||||
@ -121,7 +130,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
* @note If the SQL is not a style of 'select * from table_name ...' (select all
|
||||
* columns by an asterisk), please set the offset to -1.
|
||||
*/
|
||||
explicit [[className]](const Row &r, const ssize_t indexOffset = 0) noexcept;
|
||||
explicit [[className]](const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
|
||||
|
||||
/**
|
||||
* @brief constructor
|
||||
@ -219,18 +228,20 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
}
|
||||
std::string alind(alias.length(), ' ');
|
||||
%>
|
||||
void get{%alias%}(const DbClientPtr &clientPtr,
|
||||
{%relationshipClassName%} get{%alias%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%alias%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%alind%} const std::function<void({%relationshipClassName%})> &rcb,
|
||||
{%alind%} const ExceptionCallback &ecb) const;
|
||||
{%alind%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string relationshipClassInde(relationshipClassName.length(), ' ');
|
||||
%>
|
||||
void get{%relationshipClassName%}(const DbClientPtr &clientPtr,
|
||||
{%relationshipClassName%} get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%relationshipClassInde%} const std::function<void({%relationshipClassName%})> &rcb,
|
||||
{%relationshipClassInde%} const ExceptionCallback &ecb) const;
|
||||
{%relationshipClassInde%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
}
|
||||
@ -244,18 +255,20 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
}
|
||||
std::string alind(alias.length(), ' ');
|
||||
%>
|
||||
void get{%alias%}(const DbClientPtr &clientPtr,
|
||||
std::vector<{%relationshipClassName%}> get{%alias%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%alias%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%alind%} const std::function<void(std::vector<{%relationshipClassName%}>)> &rcb,
|
||||
{%alind%} const ExceptionCallback &ecb) const;
|
||||
{%alind%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string relationshipClassInde(relationshipClassName.length(), ' ');
|
||||
%>
|
||||
void get{%relationshipClassName%}(const DbClientPtr &clientPtr,
|
||||
std::vector<{%relationshipClassName%}> get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%relationshipClassInde%} const std::function<void(std::vector<{%relationshipClassName%}>)> &rcb,
|
||||
{%relationshipClassInde%} const ExceptionCallback &ecb) const;
|
||||
{%relationshipClassInde%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
}
|
||||
@ -271,25 +284,34 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
}
|
||||
std::string alind(alias.length(), ' ');
|
||||
%>
|
||||
void get{%alias%}(const DbClientPtr &clientPtr,
|
||||
std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>> get{%alias%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%alias%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%alind%} const std::function<void(std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>>)> &rcb,
|
||||
{%alind%} const ExceptionCallback &ecb) const;
|
||||
{%alind%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string relationshipClassInde(relationshipClassName.length(), ' ');
|
||||
%>
|
||||
void get{%relationshipClassName%}(const DbClientPtr &clientPtr,
|
||||
std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>> get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr) const;
|
||||
void get{%relationshipClassName%}(const drogon::orm::DbClientPtr &clientPtr,
|
||||
{%relationshipClassInde%} const std::function<void(std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>>)> &rcb,
|
||||
{%relationshipClassInde%} const ExceptionCallback &ecb) const;
|
||||
{%relationshipClassInde%} const drogon::orm::ExceptionCallback &ecb) const;
|
||||
<%c++
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
private:
|
||||
friend Mapper<[[className]]>;
|
||||
friend drogon::orm::Mapper<[[className]]>;
|
||||
friend drogon::orm::BaseBuilder<[[className]], true, true>;
|
||||
friend drogon::orm::BaseBuilder<[[className]], true, false>;
|
||||
friend drogon::orm::BaseBuilder<[[className]], false, true>;
|
||||
friend drogon::orm::BaseBuilder<[[className]], false, false>;
|
||||
#ifdef __cpp_impl_coroutine
|
||||
friend drogon::orm::CoroMapper<[[className]]>;
|
||||
#endif
|
||||
static const std::vector<std::string> &insertColumns() noexcept;
|
||||
void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
|
||||
const std::vector<std::string> updateColumns() const;
|
||||
@ -407,8 +429,21 @@ if(@@.get<int>("hasPrimaryKey")<=1){
|
||||
continue;
|
||||
if(cols[i].hasDefaultVal_)
|
||||
{
|
||||
$$<<" sql += \""<<cols[i].colName_<<",\";\n";
|
||||
$$<<" ++parametersCount;\n";
|
||||
if(@@.get<std::string>("rdbms")!="sqlite3")
|
||||
{
|
||||
$$<<" sql += \""<<cols[i].colName_<<",\";\n";
|
||||
$$<<" ++parametersCount;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
%>
|
||||
if(dirtyFlag_[{%i%}])
|
||||
{
|
||||
sql += "{%cols[i].colName_%},";
|
||||
++parametersCount;
|
||||
}
|
||||
<%c++
|
||||
}
|
||||
if(@@.get<int>("hasPrimaryKey")>0||@@.get<std::string>("rdbms")=="postgresql")
|
||||
{
|
||||
%>
|
||||
@ -473,7 +508,7 @@ if(@@.get<std::string>("rdbms")=="postgresql")
|
||||
if(@@.get<std::string>("rdbms")=="postgresql")
|
||||
{
|
||||
%>
|
||||
n = sprintf(placeholderStr,"$%d,",placeholder++);
|
||||
n = snprintf(placeholderStr,sizeof(placeholderStr),"$%d,",placeholder++);
|
||||
sql.append(placeholderStr, n);
|
||||
<%c++
|
||||
}else
|
||||
@ -486,7 +521,7 @@ if(@@.get<std::string>("rdbms")=="postgresql")
|
||||
%>
|
||||
}
|
||||
<%c++
|
||||
if(cols[i].hasDefaultVal_)
|
||||
if(cols[i].hasDefaultVal_&&@@.get<std::string>("rdbms")!="sqlite3")
|
||||
{
|
||||
%>
|
||||
else
|
||||
|
@ -20,6 +20,24 @@
|
||||
//"client_encoding": "",
|
||||
//table: An array of tables to be modelized. if the array is empty, all revealed tables are modelized.
|
||||
"tables": [],
|
||||
//convert: the value can be changed by a function call before it is stored into database or
|
||||
//after it is read from database
|
||||
"convert": {
|
||||
"enabled": false,
|
||||
"items":[{
|
||||
"table": "user",
|
||||
"column": "password",
|
||||
"method": {
|
||||
//after_db_read: name of the method which is called after reading from database, signature: void([const] std::shared_ptr [&])
|
||||
"after_db_read": "decrypt_password",
|
||||
//before_db_write: name of the method which is called before writing to database, signature: void([const] std::shared_ptr [&])
|
||||
"before_db_write": "encrypt_password"
|
||||
},
|
||||
"includes": [
|
||||
"\"file_local_search_path.h\"","<file_in_global_search_path.h>"
|
||||
]
|
||||
}]
|
||||
},
|
||||
"relationships": {
|
||||
"enabled": false,
|
||||
"items": [{
|
||||
|
@ -23,11 +23,11 @@ class [[className]] : public drogon::Plugin<[[className]]>
|
||||
[[className]]() {}
|
||||
/// This method must be called by drogon to initialize and start the plugin.
|
||||
/// It must be implemented by the user.
|
||||
virtual void initAndStart(const Json::Value &config) override;
|
||||
void initAndStart(const Json::Value &config) override;
|
||||
|
||||
/// This method must be called by drogon to shutdown the plugin.
|
||||
/// It must be implemented by the user.
|
||||
virtual void shutdown() override;
|
||||
void shutdown() override;
|
||||
};
|
||||
|
||||
<%c++for(size_t i=0;i<namespaceVector.size();i++){%>
|
||||
|
@ -19,6 +19,7 @@ auto modelName = tableInfo.get<std::string>("className");
|
||||
$$<<"#include \""<<modelName<<".h\"\n";
|
||||
bool hasPrimaryKey = (tableInfo.get<int>("hasPrimaryKey")==1);
|
||||
$$<<"using namespace drogon;\n";
|
||||
$$<<"using namespace drogon::orm;\n";
|
||||
|
||||
$$<<"using namespace drogon_model::"<<tableInfo.get<std::string>("dbName");
|
||||
auto &schema=tableInfo.get<std::string>("schema");
|
||||
|
14
drogon_ctl/templates/test_cmake.csp
Normal file
14
drogon_ctl/templates/test_cmake.csp
Normal file
@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project([[ProjectName]]_test CXX)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_main.cc)
|
||||
|
||||
# ##############################################################################
|
||||
# If you include the drogon source code locally in your project, use this method
|
||||
# to add drogon
|
||||
# target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||
#
|
||||
# and comment out the following lines
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
|
||||
|
||||
ParseAndAddDrogonTests(${PROJECT_NAME})
|
32
drogon_ctl/templates/test_main.csp
Normal file
32
drogon_ctl/templates/test_main.csp
Normal file
@ -0,0 +1,32 @@
|
||||
#define DROGON_TEST_MAIN
|
||||
#include <drogon/drogon_test.h>
|
||||
#include <drogon/drogon.h>
|
||||
|
||||
DROGON_TEST(BasicTest)
|
||||
{
|
||||
// Add your tests here
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace drogon;
|
||||
|
||||
std::promise<void> p1;
|
||||
std::future<void> f1 = p1.get_future();
|
||||
|
||||
// Start the main loop on another thread
|
||||
std::thread thr([&]() {
|
||||
// Queues the promise to be fulfilled after starting the loop
|
||||
app().getLoop()->queueInLoop([&p1]() { p1.set_value(); });
|
||||
app().run();
|
||||
});
|
||||
|
||||
// The future is only satisfied after the event loop started
|
||||
f1.get();
|
||||
int status = test::run(argc, argv);
|
||||
|
||||
// Ask the event loop to shutdown and wait
|
||||
app().getLoop()->queueInLoop([]() { app().quit(); });
|
||||
thr.join();
|
||||
return status;
|
||||
}
|
@ -15,20 +15,25 @@
|
||||
#include "version.h"
|
||||
#include <drogon/config.h>
|
||||
#include <drogon/version.h>
|
||||
#include <drogon/utils/Utilities.h>
|
||||
#include <trantor/net/Resolver.h>
|
||||
#include <trantor/utils/Utilities.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace drogon_ctl;
|
||||
static const char banner[] =
|
||||
" _ \n"
|
||||
" __| |_ __ ___ __ _ ___ _ __ \n"
|
||||
" / _` | '__/ _ \\ / _` |/ _ \\| '_ \\ \n"
|
||||
"| (_| | | | (_) | (_| | (_) | | | |\n"
|
||||
" \\__,_|_| \\___/ \\__, |\\___/|_| |_|\n"
|
||||
" |___/ \n";
|
||||
R"( _
|
||||
__| |_ __ ___ __ _ ___ _ __
|
||||
/ _` | '__/ _ \ / _` |/ _ \| '_ \
|
||||
| (_| | | | (_) | (_| | (_) | | | |
|
||||
\__,_|_| \___/ \__, |\___/|_| |_|
|
||||
|___/
|
||||
)";
|
||||
|
||||
void version::handleCommand(std::vector<std::string> ¶meters)
|
||||
{
|
||||
const auto tlsBackend = trantor::utils::tlsBackend();
|
||||
const bool tlsSupported = drogon::utils::supportsTls();
|
||||
std::cout << banner << std::endl;
|
||||
std::cout << "A utility for drogon" << std::endl;
|
||||
std::cout << "Version: " << DROGON_VERSION << std::endl;
|
||||
@ -38,25 +43,26 @@ void version::handleCommand(std::vector<std::string> ¶meters)
|
||||
<< "\n Compilation flags: " << COMPILATION_FLAGS
|
||||
<< INCLUDING_DIRS << std::endl;
|
||||
std::cout << "Libraries: \n postgresql: "
|
||||
<< (USE_POSTGRESQL ? "yes" : "no") << " (batch mode: "
|
||||
<< (USE_POSTGRESQL ? "yes" : "no") << " (pipeline mode: "
|
||||
<< (LIBPQ_SUPPORTS_BATCH_MODE ? "yes)\n" : "no)\n")
|
||||
<< " mariadb: " << (USE_MYSQL ? "yes\n" : "no\n")
|
||||
<< " sqlite3: " << (USE_SQLITE3 ? "yes\n" : "no\n");
|
||||
#ifdef OpenSSL_FOUND
|
||||
std::cout << " openssl: yes\n";
|
||||
#else
|
||||
std::cout << " openssl: no\n";
|
||||
#endif
|
||||
std::cout << " ssl/tls backend: " << tlsBackend << "\n";
|
||||
#ifdef USE_BROTLI
|
||||
std::cout << " brotli: yes\n";
|
||||
#else
|
||||
std::cout << " brotli: no\n";
|
||||
#endif
|
||||
#ifdef Boost_FOUND
|
||||
std::cout << " boost: yes\n";
|
||||
#ifdef USE_REDIS
|
||||
std::cout << " hiredis: yes\n";
|
||||
#else
|
||||
std::cout << " boost: no\n";
|
||||
std::cout << " hiredis: no\n";
|
||||
#endif
|
||||
std::cout << " c-ares: "
|
||||
<< (trantor::Resolver::isCAresUsed() ? "yes\n" : "no\n");
|
||||
#ifdef HAS_YAML_CPP
|
||||
std::cout << " yaml-cpp: yes\n";
|
||||
#else
|
||||
std::cout << " yaml-cpp: no\n";
|
||||
#endif
|
||||
}
|
||||
|
@ -17,20 +17,24 @@
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class version : public DrObject<version>, public CommandHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
virtual std::string script() override
|
||||
void handleCommand(std::vector<std::string> ¶meters) override;
|
||||
|
||||
std::string script() override
|
||||
{
|
||||
return "display version of this tool";
|
||||
}
|
||||
virtual bool isTopCommand() override
|
||||
|
||||
bool isTopCommand() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
version()
|
||||
{
|
||||
}
|
||||
|
@ -1,77 +1,64 @@
|
||||
link_libraries(${PROJECT_NAME})
|
||||
|
||||
file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/simple_example/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
message(STATUS "cspFile:" ${cspFile})
|
||||
get_filename_component(classname ${cspFile} NAME_WE)
|
||||
message(STATUS "view classname:" ${classname})
|
||||
add_custom_command(OUTPUT ${classname}.h ${classname}.cc
|
||||
COMMAND drogon_ctl
|
||||
ARGS
|
||||
create
|
||||
view
|
||||
${cspFile}
|
||||
DEPENDS ${cspFile}
|
||||
VERBATIM)
|
||||
set(VIEWSRC ${VIEWSRC} ${classname}.cc)
|
||||
endforeach()
|
||||
|
||||
set(simple_example_sources
|
||||
simple_example/CustomCtrl.cc
|
||||
simple_example/CustomHeaderFilter.cc
|
||||
simple_example/DoNothingPlugin.cc
|
||||
simple_example/ForwardCtrl.cc
|
||||
simple_example/JsonTestController.cc
|
||||
simple_example/ListParaCtl.cc
|
||||
simple_example/PipeliningTest.cc
|
||||
simple_example/TestController.cc
|
||||
simple_example/TestPlugin.cc
|
||||
simple_example/TestViewCtl.cc
|
||||
simple_example/WebSocketTest.cc
|
||||
simple_example/api_Attachment.cc
|
||||
simple_example/api_v1_ApiTest.cc
|
||||
simple_example/TimeFilter.cc
|
||||
simple_example/DigestAuthFilter.cc
|
||||
simple_example/main.cc)
|
||||
|
||||
add_executable(webapp ${simple_example_sources} ${VIEWSRC})
|
||||
add_dependencies(webapp drogon_ctl)
|
||||
|
||||
set(client_example_sources client_example/main.cc)
|
||||
set(benchmark_sources benchmark/BenchmarkCtrl.cc benchmark/JsonCtrl.cc
|
||||
benchmark/main.cc)
|
||||
# AUX_SOURCE_DIRECTORY(simple_example_test DIR_TEST)
|
||||
|
||||
add_executable(client ${client_example_sources})
|
||||
add_executable(client client_example/main.cc)
|
||||
add_executable(websocket_client websocket_client/WebSocketClient.cc)
|
||||
add_executable(websocket_server websocket_server/WebSocketServer.cc)
|
||||
add_executable(benchmark ${benchmark_sources})
|
||||
add_executable(webapp_test simple_example_test/main.cc)
|
||||
add_executable(pipelining_test simple_example_test/HttpPipeliningTest.cc)
|
||||
add_executable(websocket_test simple_example_test/WebSocketTest.cc)
|
||||
add_executable(multiple_ws_test simple_example_test/MultipleWsTest.cc)
|
||||
add_executable(helloworld helloworld/main.cc
|
||||
helloworld/HelloController.cc
|
||||
helloworld/HelloViewController.cc)
|
||||
drogon_create_views(helloworld
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/helloworld
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_executable(file_upload file_upload/file_upload.cc)
|
||||
drogon_create_views(file_upload
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_upload
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_executable(login_session login_session/main.cc)
|
||||
drogon_create_views(login_session
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/login_session
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_custom_command(
|
||||
TARGET webapp POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-E
|
||||
copy_if_different
|
||||
${PROJECT_SOURCE_DIR}/config.example.json
|
||||
${PROJECT_SOURCE_DIR}/drogon.jpg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simple_example/index.html
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simple_example/index.html.gz
|
||||
${PROJECT_SOURCE_DIR}/trantor/trantor/tests/server.pem
|
||||
$<TARGET_FILE_DIR:webapp>)
|
||||
add_executable(jsonstore jsonstore/main.cc)
|
||||
|
||||
add_executable(redis_simple redis/main.cc
|
||||
redis/controllers/Client.cc
|
||||
redis/controllers/WsClient.cc)
|
||||
|
||||
add_executable(redis_chat redis_chat/main.cc
|
||||
redis_chat/controllers/Chat.cc)
|
||||
|
||||
add_executable(async_stream async_stream/main.cc
|
||||
async_stream/RequestStreamExampleCtrl.cc)
|
||||
|
||||
add_executable(cors cors/main.cc)
|
||||
|
||||
set(example_targets
|
||||
webapp
|
||||
webapp_test
|
||||
client
|
||||
benchmark
|
||||
pipelining_test
|
||||
websocket_test
|
||||
multiple_ws_test)
|
||||
client
|
||||
websocket_client
|
||||
websocket_server
|
||||
helloworld
|
||||
file_upload
|
||||
login_session
|
||||
jsonstore
|
||||
redis_simple
|
||||
redis_chat
|
||||
async_stream
|
||||
cors)
|
||||
|
||||
# Add warnings for our example targets--some warnings (such as -Wunused-parameter) only appear
|
||||
# when the templated functions are instantiated at their point of use.
|
||||
if(NOT ${CMAKE_PLATFORM_NAME} STREQUAL "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
foreach(target ${example_targets})
|
||||
target_compile_options(${target} PRIVATE -Wall -Wextra -Werror)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${example_targets}
|
||||
PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD})
|
||||
set_property(TARGET ${example_targets} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
set_property(TARGET ${example_targets} PROPERTY CXX_EXTENSIONS OFF)
|
||||
set_property(TARGET webapp PROPERTY ENABLE_EXPORTS ON)
|
||||
|
@ -2,11 +2,21 @@
|
||||
|
||||
The following examples can help you understand how to use Drogon:
|
||||
|
||||
1. [benchmark](https://github.com/an-tao/drogon/tree/master/examples/benchmark) - Basic benchmark example. see [wiki benchmarks](https://github.com/an-tao/drogon/wiki/13-Benchmarks)
|
||||
2. [client_example](https://github.com/an-tao/drogon/tree/master/examples/client_example/main.cc) - A client example.
|
||||
3. [simple_example](https://github.com/an-tao/drogon/tree/master/examples/simple_example) - A simple example showing how to create a web application using Drogon.
|
||||
4. [simple_example_test](https://github.com/an-tao/drogon/tree/master/examples/simple_example_test) - Some tests for the `simple_example`.
|
||||
5. [simple_reverse_proxy](https://github.com/an-tao/drogon/tree/master/examples/simple_reverse_proxy) - A Example showing how to use drogon as a http reverse proxy with a simple round robin.
|
||||
1. [helloworld](https://github.com/drogonframework/drogon/tree/master/examples/helloworld) - The multiple ways of "Hello, World!"
|
||||
2. [client_example](https://github.com/drogonframework/drogon/tree/master/examples/client_example/main.cc) - A client example
|
||||
3. [websocket_client](https://github.com/drogonframework/drogon/tree/master/examples/websocket_client/WebSocketClient.cc) - An example on how to use the WebSocket client
|
||||
4. [login_session](https://github.com/drogonframework/drogon/tree/master/examples/login_session) - How to use the built-in session system to handle login and out
|
||||
5. [file_upload](https://github.com/drogonframework/drogon/tree/master/examples/file_upload) - How to handle file uploads in Drogon
|
||||
6. [simple_reverse_proxy](https://github.com/drogonframework/drogon/tree/master/examples/simple_reverse_proxy) - An example showing how to use Drogon as a HTTP reverse
|
||||
proxy with a simple round robin
|
||||
7. [benchmark](https://github.com/drogonframework/drogon/tree/master/examples/benchmark) - Basic benchmark(https://github.com/drogonframework/drogon/wiki/13-Benchmarks) example
|
||||
8. [jsonstore](https://github.com/drogonframework/drogon/tree/master/examples/jsonstore) - Implementation of a [jsonstore](https://github.com/bluzi/jsonstore)-like storage service that is concurrent and stores in memory. Serving as a showcase on how to build a minimally useful RESTful APIs in Drogon
|
||||
9. [redis](https://github.com/drogonframework/drogon/tree/master/examples/redis) - A simple example of Redis
|
||||
10. [websocket_server](https://github.com/drogonframework/drogon/tree/master/examples/websocket_server) - A example websocket chat room server
|
||||
11. [redis_cache](https://github.com/drogonframework/drogon/tree/master/examples/redis_cache) - An example for using coroutines of Redis clients
|
||||
12. [redis_chat](https://github.com/drogonframework/drogon/tree/master/examples/redis_chat) - A chatroom server built with websocket and Redis pub/sub service
|
||||
13. [prometheus_example](https://github.com/drogonframework/drogon/tree/master/examples/prometheus_example) - An example of how to use the Prometheus exporter in Drogon
|
||||
14. [cors](https://github.com/drogonframework/drogon/tree/master/examples/cors) - An example demonstrating how to implement CORS (Cross-Origin Resource Sharing) support in Drogon
|
||||
|
||||
### [TechEmpower Framework Benchmarks](https://github.com/TechEmpower/FrameworkBenchmarks) test suite
|
||||
|
||||
@ -14,4 +24,4 @@ I created a benchmark suite for the `tfb`, see [here](https://github.com/TechEmp
|
||||
|
||||
### Another test suite
|
||||
|
||||
I also created a test suite for another web frameworks benchmark repository, see [here](https://github.com/the-benchmarker/web-frameworks/tree/master/cpp/drogon), in this project, drogon is used as a sub-module (locally include in the project).
|
||||
I also created a test suite for another web frameworks benchmark repository, see [here](https://github.com/the-benchmarker/web-frameworks/tree/master/cpp/drogon). In this project, Drogon is used as a sub-module (locally include in the project).
|
||||
|
167
examples/async_stream/RequestStreamExampleCtrl.cc
Normal file
167
examples/async_stream/RequestStreamExampleCtrl.cc
Normal file
@ -0,0 +1,167 @@
|
||||
#include <drogon/drogon.h>
|
||||
#include <drogon/HttpController.h>
|
||||
#include <drogon/HttpRequest.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
class StreamEchoReader : public RequestStreamReader
|
||||
{
|
||||
public:
|
||||
StreamEchoReader(ResponseStreamPtr respStream)
|
||||
: respStream_(std::move(respStream))
|
||||
{
|
||||
}
|
||||
|
||||
void onStreamData(const char *data, size_t length) override
|
||||
{
|
||||
LOG_INFO << "onStreamData[" << length << "]";
|
||||
respStream_->send({data, length});
|
||||
}
|
||||
|
||||
void onStreamFinish(std::exception_ptr ptr) override
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(ptr);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR << "onStreamError: " << e.what();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO << "onStreamFinish";
|
||||
}
|
||||
respStream_->close();
|
||||
}
|
||||
|
||||
private:
|
||||
ResponseStreamPtr respStream_;
|
||||
};
|
||||
|
||||
class RequestStreamExampleCtrl : public HttpController<RequestStreamExampleCtrl>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
ADD_METHOD_TO(RequestStreamExampleCtrl::stream_echo, "/stream_echo", Post);
|
||||
ADD_METHOD_TO(RequestStreamExampleCtrl::stream_upload,
|
||||
"/stream_upload",
|
||||
Post);
|
||||
METHOD_LIST_END
|
||||
|
||||
void stream_echo(
|
||||
const HttpRequestPtr &,
|
||||
RequestStreamPtr &&stream,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) const
|
||||
{
|
||||
auto resp = drogon::HttpResponse::newAsyncStreamResponse(
|
||||
[stream](ResponseStreamPtr respStream) {
|
||||
stream->setStreamReader(
|
||||
std::make_shared<StreamEchoReader>(std::move(respStream)));
|
||||
});
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void stream_upload(
|
||||
const HttpRequestPtr &req,
|
||||
RequestStreamPtr &&stream,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) const
|
||||
{
|
||||
struct Entry
|
||||
{
|
||||
MultipartHeader header;
|
||||
std::string tmpName;
|
||||
std::ofstream file;
|
||||
};
|
||||
|
||||
auto files = std::make_shared<std::vector<Entry>>();
|
||||
auto reader = RequestStreamReader::newMultipartReader(
|
||||
req,
|
||||
[files](MultipartHeader &&header) {
|
||||
LOG_INFO << "Multipart name: " << header.name
|
||||
<< ", filename:" << header.filename
|
||||
<< ", contentType:" << header.contentType;
|
||||
|
||||
files->push_back({std::move(header)});
|
||||
auto tmpName = drogon::utils::genRandomString(40);
|
||||
if (!files->back().header.filename.empty())
|
||||
{
|
||||
files->back().tmpName = tmpName;
|
||||
files->back().file.open("uploads/" + tmpName,
|
||||
std::ios::trunc);
|
||||
}
|
||||
},
|
||||
[files](const char *data, size_t length) {
|
||||
if (files->back().tmpName.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto ¤tFile = files->back().file;
|
||||
if (length == 0)
|
||||
{
|
||||
LOG_INFO << "file finish";
|
||||
if (currentFile.is_open())
|
||||
{
|
||||
currentFile.flush();
|
||||
currentFile.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
LOG_INFO << "data[" << length << "]: ";
|
||||
if (currentFile.is_open())
|
||||
{
|
||||
LOG_INFO << "write file";
|
||||
currentFile.write(data, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR << "file not open";
|
||||
}
|
||||
},
|
||||
[files, callback = std::move(callback)](std::exception_ptr ex) {
|
||||
if (ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(std::move(ex));
|
||||
}
|
||||
catch (const StreamError &e)
|
||||
{
|
||||
LOG_ERROR << "stream error: " << e.what();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR << "multipart error: " << e.what();
|
||||
}
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
resp->setBody("error\n");
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO << "stream finish, received " << files->size()
|
||||
<< " files";
|
||||
Json::Value respJson;
|
||||
for (const auto &item : *files)
|
||||
{
|
||||
if (item.tmpName.empty())
|
||||
continue;
|
||||
Json::Value entry;
|
||||
entry["name"] = item.header.name;
|
||||
entry["filename"] = item.header.filename;
|
||||
entry["tmpName"] = item.tmpName;
|
||||
respJson.append(entry);
|
||||
}
|
||||
auto resp = HttpResponse::newHttpJsonResponse(respJson);
|
||||
callback(resp);
|
||||
}
|
||||
});
|
||||
|
||||
stream->setStreamReader(std::move(reader));
|
||||
}
|
||||
};
|
113
examples/async_stream/main.cc
Normal file
113
examples/async_stream/main.cc
Normal file
@ -0,0 +1,113 @@
|
||||
#include <drogon/drogon.h>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <trantor/utils/Logger.h>
|
||||
#include <trantor/net/callbacks.h>
|
||||
#include <trantor/net/TcpConnection.h>
|
||||
|
||||
using namespace drogon;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::mutex mutex;
|
||||
std::unordered_map<trantor::TcpConnectionPtr, std::function<void()>>
|
||||
connMapping;
|
||||
|
||||
int main()
|
||||
{
|
||||
app().registerHandler(
|
||||
"/stream",
|
||||
[](const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
const auto &weakConnPtr = req->getConnectionPtr();
|
||||
if (auto connPtr = weakConnPtr.lock())
|
||||
{
|
||||
std::lock_guard lk(mutex);
|
||||
connMapping.emplace(std::move(connPtr), [] {
|
||||
LOG_INFO << "call stop or other options!!!!";
|
||||
});
|
||||
}
|
||||
auto resp = drogon::HttpResponse::newAsyncStreamResponse(
|
||||
[](drogon::ResponseStreamPtr stream) {
|
||||
std::thread([stream =
|
||||
std::shared_ptr<drogon::ResponseStream>{
|
||||
std::move(stream)}]() mutable {
|
||||
std::cout << std::boolalpha << stream->send("hello ")
|
||||
<< std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
std::cout << std::boolalpha << stream->send("world");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
stream->close();
|
||||
}).detach();
|
||||
});
|
||||
resp->setContentTypeCodeAndCustomString(
|
||||
ContentType::CT_APPLICATION_JSON, "application/json");
|
||||
callback(resp);
|
||||
});
|
||||
|
||||
// Example: register a stream-mode function handler
|
||||
app().registerHandler(
|
||||
"/stream_req",
|
||||
[](const HttpRequestPtr &req,
|
||||
RequestStreamPtr &&stream,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
if (!stream)
|
||||
{
|
||||
LOG_INFO << "stream mode is not enabled";
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
resp->setBody("no stream");
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
auto reader = RequestStreamReader::newReader(
|
||||
[](const char *data, size_t length) {
|
||||
LOG_INFO << "piece[" << length
|
||||
<< "]: " << std::string_view{data, length};
|
||||
},
|
||||
[callback = std::move(callback)](std::exception_ptr ex) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
if (ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(std::move(ex));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR << "stream error: " << e.what();
|
||||
}
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
resp->setBody("error\n");
|
||||
callback(resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO << "stream finish";
|
||||
resp->setBody("success\n");
|
||||
callback(resp);
|
||||
}
|
||||
});
|
||||
|
||||
stream->setStreamReader(std::move(reader));
|
||||
},
|
||||
{Post});
|
||||
|
||||
LOG_INFO << "Server running on 127.0.0.1:8848";
|
||||
app().enableRequestStream(); // This is for request stream.
|
||||
app().setConnectionCallback([](const trantor::TcpConnectionPtr &conn) {
|
||||
if (conn->disconnected())
|
||||
{
|
||||
std::lock_guard lk(mutex);
|
||||
if (auto it = connMapping.find(conn); it != connMapping.end())
|
||||
{
|
||||
LOG_INFO << "disconnect";
|
||||
connMapping[conn]();
|
||||
connMapping.erase(conn);
|
||||
}
|
||||
}
|
||||
});
|
||||
app().addListener("127.0.0.1", 8848).run();
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#include "BenchmarkCtrl.h"
|
||||
|
||||
void BenchmarkCtrl::asyncHandleHttpRequest(
|
||||
const HttpRequestPtr &req,
|
||||
const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
// write your application logic here
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
using namespace drogon;
|
||||
|
||||
class BenchmarkCtrl : public drogon::HttpSimpleController<BenchmarkCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(
|
||||
void asyncHandleHttpRequest(
|
||||
const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "JsonCtrl.h"
|
||||
|
||||
void JsonCtrl::asyncHandleHttpRequest(
|
||||
const HttpRequestPtr &req,
|
||||
const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
Json::Value ret;
|
||||
ret["message"] = "Hello, World!";
|
||||
auto resp = HttpResponse::newHttpJsonResponse(ret);
|
||||
auto resp = HttpResponse::newHttpJsonResponse(std::move(ret));
|
||||
callback(resp);
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
using namespace drogon;
|
||||
|
||||
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
|
||||
{
|
||||
public:
|
||||
virtual void asyncHandleHttpRequest(
|
||||
void asyncHandleHttpRequest(
|
||||
const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||
PATH_LIST_BEGIN
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <drogon/drogon.h>
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
int main()
|
||||
{
|
||||
app()
|
||||
|
@ -1,15 +1,44 @@
|
||||
#include <drogon/drogon.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
int nth_resp = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
trantor::Logger::setLogLevel(trantor::Logger::kTrace);
|
||||
{
|
||||
int count = 0;
|
||||
auto client = HttpClient::newHttpClient("http://www.baidu.com");
|
||||
client->setSockOptCallback([](int fd) {
|
||||
std::cout << "setSockOptCallback:" << fd << std::endl;
|
||||
#ifdef __linux__
|
||||
int optval = 10;
|
||||
::setsockopt(fd,
|
||||
SOL_TCP,
|
||||
TCP_KEEPCNT,
|
||||
&optval,
|
||||
static_cast<socklen_t>(sizeof optval));
|
||||
::setsockopt(fd,
|
||||
SOL_TCP,
|
||||
TCP_KEEPIDLE,
|
||||
&optval,
|
||||
static_cast<socklen_t>(sizeof optval));
|
||||
::setsockopt(fd,
|
||||
SOL_TCP,
|
||||
TCP_KEEPINTVL,
|
||||
&optval,
|
||||
static_cast<socklen_t>(sizeof optval));
|
||||
#endif
|
||||
});
|
||||
|
||||
auto req = HttpRequest::newHttpRequest();
|
||||
req->setMethod(drogon::Get);
|
||||
req->setPath("/s");
|
||||
@ -19,11 +48,18 @@ int main()
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
client->sendRequest(
|
||||
req,
|
||||
[&count](ReqResult result, const HttpResponsePtr &response) {
|
||||
req, [](ReqResult result, const HttpResponsePtr &response) {
|
||||
if (result != ReqResult::Ok)
|
||||
{
|
||||
std::cout
|
||||
<< "error while sending request to server! result: "
|
||||
<< result << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "receive response!" << std::endl;
|
||||
// auto headers=response.
|
||||
++count;
|
||||
++nth_resp;
|
||||
std::cout << response->getBody() << std::endl;
|
||||
auto cookies = response->cookies();
|
||||
for (auto const &cookie : cookies)
|
||||
@ -33,9 +69,11 @@ int main()
|
||||
<< ":domain=" << cookie.second.domain()
|
||||
<< std::endl;
|
||||
}
|
||||
std::cout << "count=" << count << std::endl;
|
||||
std::cout << "count=" << nth_resp << std::endl;
|
||||
});
|
||||
}
|
||||
std::cout << "requestsBufferSize:" << client->requestsBufferSize()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
app().run();
|
||||
|
153
examples/cors/main.cc
Normal file
153
examples/cors/main.cc
Normal file
@ -0,0 +1,153 @@
|
||||
#include <drogon/HttpAppFramework.h>
|
||||
#include <drogon/HttpResponse.h>
|
||||
#include <drogon/drogon.h>
|
||||
#include "trantor/utils/Logger.h"
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
/// Configure Cross-Origin Resource Sharing (CORS) support.
|
||||
///
|
||||
/// This function registers both synchronous pre-processing advice for handling
|
||||
/// OPTIONS preflight requests and post-handling advice to inject CORS headers
|
||||
/// into all responses dynamically based on the incoming request headers.
|
||||
void setupCors()
|
||||
{
|
||||
// Register sync advice to handle CORS preflight (OPTIONS) requests
|
||||
drogon::app().registerSyncAdvice([](const drogon::HttpRequestPtr &req)
|
||||
-> drogon::HttpResponsePtr {
|
||||
if (req->method() == drogon::HttpMethod::Options)
|
||||
{
|
||||
auto resp = drogon::HttpResponse::newHttpResponse();
|
||||
|
||||
// Set Access-Control-Allow-Origin header based on the Origin
|
||||
// request header
|
||||
const auto &origin = req->getHeader("Origin");
|
||||
if (!origin.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Origin", origin);
|
||||
}
|
||||
|
||||
// Set Access-Control-Allow-Methods based on the requested method
|
||||
const auto &requestMethod =
|
||||
req->getHeader("Access-Control-Request-Method");
|
||||
if (!requestMethod.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Methods", requestMethod);
|
||||
}
|
||||
|
||||
// Allow credentials to be included in cross-origin requests
|
||||
resp->addHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
// Set allowed headers from the Access-Control-Request-Headers
|
||||
// header
|
||||
const auto &requestHeaders =
|
||||
req->getHeader("Access-Control-Request-Headers");
|
||||
if (!requestHeaders.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Headers", requestHeaders);
|
||||
}
|
||||
|
||||
return std::move(resp);
|
||||
}
|
||||
return {};
|
||||
});
|
||||
|
||||
// Register post-handling advice to add CORS headers to all responses
|
||||
drogon::app().registerPostHandlingAdvice(
|
||||
[](const drogon::HttpRequestPtr &req,
|
||||
const drogon::HttpResponsePtr &resp) -> void {
|
||||
// Set Access-Control-Allow-Origin based on the Origin request
|
||||
// header
|
||||
const auto &origin = req->getHeader("Origin");
|
||||
if (!origin.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Origin", origin);
|
||||
}
|
||||
|
||||
// Reflect the requested Access-Control-Request-Method back in the
|
||||
// response
|
||||
const auto &requestMethod =
|
||||
req->getHeader("Access-Control-Request-Method");
|
||||
if (!requestMethod.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Methods", requestMethod);
|
||||
}
|
||||
|
||||
// Allow credentials to be included in cross-origin requests
|
||||
resp->addHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
// Reflect the requested Access-Control-Request-Headers back
|
||||
const auto &requestHeaders =
|
||||
req->getHeader("Access-Control-Request-Headers");
|
||||
if (!requestHeaders.empty())
|
||||
{
|
||||
resp->addHeader("Access-Control-Allow-Headers", requestHeaders);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to start the Drogon application with CORS-enabled routes.
|
||||
* This example includes:
|
||||
* - A simple GET endpoint `/hello` that returns a greeting message.
|
||||
* - A POST endpoint `/echo` that echoes back the request body.
|
||||
* You can test with curl to test the CORS support:
|
||||
*
|
||||
```
|
||||
curl -i -X OPTIONS http://localhost:8000/echo \
|
||||
-H "Origin: http://localhost:3000" \
|
||||
-H "Access-Control-Request-Method: POST" \
|
||||
-H "Access-Control-Request-Headers: Content-Type"
|
||||
```
|
||||
or
|
||||
```
|
||||
curl -i -X POST http://localhost:8000/echo \
|
||||
-H "Origin: http://localhost:3000" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"key":"value"}'
|
||||
```
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
// Listen on port 8000 for all interfaces
|
||||
app().addListener("0.0.0.0", 8000);
|
||||
|
||||
// Setup CORS support
|
||||
setupCors();
|
||||
|
||||
// Register /hello route for GET and OPTIONS methods
|
||||
app().registerHandler(
|
||||
"/hello",
|
||||
[](const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Hello from Drogon!");
|
||||
|
||||
// Log client IP address
|
||||
LOG_INFO << "Request to /hello from " << req->getPeerAddr().toIp();
|
||||
|
||||
callback(resp);
|
||||
},
|
||||
{Get, Options});
|
||||
|
||||
// Register /echo route for POST and OPTIONS methods
|
||||
app().registerHandler(
|
||||
"/echo",
|
||||
[](const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody(std::string("Echo: ").append(req->getBody()));
|
||||
|
||||
// Log client IP and request body
|
||||
LOG_INFO << "Request to /echo from " << req->getPeerAddr().toIp();
|
||||
LOG_INFO << "Echo content: " << req->getBody();
|
||||
|
||||
callback(resp);
|
||||
},
|
||||
{Post, Options});
|
||||
|
||||
// Start the application main loop
|
||||
app().run();
|
||||
|
||||
return 0;
|
||||
}
|
83
examples/file_upload/FileUpload.csp
Normal file
83
examples/file_upload/FileUpload.csp
Normal file
@ -0,0 +1,83 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>File upload</title>
|
||||
<script type="text/javascript">
|
||||
var xhr;
|
||||
//File uploading method
|
||||
function UpladFile() {
|
||||
var fileObj = document.getElementById("file").files[0]; // js get file object
|
||||
var url = "/upload_endpoint";
|
||||
|
||||
var form = new FormData(); // FormData object
|
||||
form.append("file", fileObj); // File object
|
||||
|
||||
xhr = new XMLHttpRequest(); // XMLHttpRequest object
|
||||
xhr.open("post", url, true); //post
|
||||
xhr.onload = uploadComplete;
|
||||
xhr.onerror = uploadFailed;
|
||||
|
||||
xhr.upload.onprogress = progressFunction;
|
||||
xhr.upload.onloadstart = function(){
|
||||
ot = new Date().getTime();
|
||||
oloaded = 0;
|
||||
};
|
||||
|
||||
xhr.send(form);
|
||||
}
|
||||
|
||||
function uploadComplete(evt) {
|
||||
var data = evt.target.responseText;
|
||||
alert("File has been uploaded.\n" + data);
|
||||
}
|
||||
|
||||
function uploadFailed(evt) {
|
||||
alert("Upload failed!");
|
||||
}
|
||||
|
||||
function cancleUploadFile(){
|
||||
xhr.abort();
|
||||
}
|
||||
|
||||
function progressFunction(evt) {
|
||||
var progressBar = document.getElementById("progressBar");
|
||||
var percentageDiv = document.getElementById("percentage");
|
||||
if (evt.lengthComputable) {//
|
||||
progressBar.max = evt.total;
|
||||
progressBar.value = evt.loaded;
|
||||
percentageDiv.innerHTML = Math.round(evt.loaded / evt.total * 100) + "%";
|
||||
}
|
||||
var time = document.getElementById("time");
|
||||
var nt = new Date().getTime();
|
||||
var pertime = (nt-ot)/1000;
|
||||
ot = new Date().getTime();
|
||||
var perload = evt.loaded - oloaded;
|
||||
oloaded = evt.loaded;
|
||||
var speed = perload/pertime;
|
||||
var bspeed = speed;
|
||||
var units = 'b/s';
|
||||
if(speed/1024>1){
|
||||
speed = speed/1024;
|
||||
units = 'k/s';
|
||||
}
|
||||
if(speed/1024>1){
|
||||
speed = speed/1024;
|
||||
units = 'M/s';
|
||||
}
|
||||
speed = speed.toFixed(1);
|
||||
var resttime = ((evt.total-evt.loaded)/bspeed).toFixed(1);
|
||||
time.innerHTML = ',Speed: '+speed+units+', the remaining time: '+resttime+'s';
|
||||
if(bspeed==0) time.innerHTML = 'Upload cancelled';
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<progress id="progressBar" value="0" max="100" style="width: 300px;"></progress>
|
||||
<span id="percentage"></span><span id="time"></span>
|
||||
<br /><br />
|
||||
<input type="file" id="file" name="myfile" />
|
||||
<input type="button" onclick="UpladFile()" value="Upload" />
|
||||
<input type="button" onclick="cancleUploadFile()" value="Cancel" />
|
||||
</body>
|
||||
</html>
|
46
examples/file_upload/file_upload.cc
Normal file
46
examples/file_upload/file_upload.cc
Normal file
@ -0,0 +1,46 @@
|
||||
#include <drogon/drogon.h>
|
||||
using namespace drogon;
|
||||
|
||||
int main()
|
||||
{
|
||||
app().registerHandler(
|
||||
"/",
|
||||
[](const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
auto resp = HttpResponse::newHttpViewResponse("FileUpload");
|
||||
callback(resp);
|
||||
});
|
||||
|
||||
app().registerHandler(
|
||||
"/upload_endpoint",
|
||||
[](const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
MultiPartParser fileUpload;
|
||||
if (fileUpload.parse(req) != 0 || fileUpload.getFiles().size() != 1)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Must only be one file");
|
||||
resp->setStatusCode(k403Forbidden);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
auto &file = fileUpload.getFiles()[0];
|
||||
auto md5 = file.getMd5();
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody(
|
||||
"The server has calculated the file's MD5 hash to be " + md5);
|
||||
file.save();
|
||||
LOG_INFO << "The uploaded file has been saved to the ./uploads "
|
||||
"directory";
|
||||
callback(resp);
|
||||
},
|
||||
{Post});
|
||||
|
||||
LOG_INFO << "Server running on 127.0.0.1:8848";
|
||||
app()
|
||||
.setClientMaxBodySize(20 * 2000 * 2000)
|
||||
.setUploadPath("./uploads")
|
||||
.addListener("127.0.0.1", 8848)
|
||||
.run();
|
||||
}
|
40
examples/helloworld/HelloController.cc
Normal file
40
examples/helloworld/HelloController.cc
Normal file
@ -0,0 +1,40 @@
|
||||
#include <drogon/HttpController.h>
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
// HttpControllers are automatically added to Drogon upon Drogon initializing.
|
||||
class SayHello : public HttpController<SayHello>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
// Drogon automatically appends the namespace and name of the controller to
|
||||
// the handlers of the controller. In this example, although we are adding
|
||||
// a handler to /. But because it is a part of the SayHello controller. It
|
||||
// ends up in path /SayHello/ (IMPORTANT! It is /SayHello/ not /SayHello
|
||||
// as they are different paths).
|
||||
METHOD_ADD(SayHello::genericHello, "/", Get);
|
||||
// Same for /hello. It ends up at /SayHello/hello
|
||||
METHOD_ADD(SayHello::personalizedHello, "/hello", Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
protected:
|
||||
void genericHello(const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody(
|
||||
"Hello, this is a generic hello message from the SayHello "
|
||||
"controller");
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void personalizedHello(
|
||||
const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody(
|
||||
"Hi there, this is another hello from the SayHello Controller");
|
||||
callback(resp);
|
||||
}
|
||||
};
|
24
examples/helloworld/HelloView.csp
Normal file
24
examples/helloworld/HelloView.csp
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<%c++
|
||||
auto name=@@.get<std::string>("name");
|
||||
bool nameIsEmpty = name == "";
|
||||
if (nameIsEmpty)
|
||||
name = "anonymous";
|
||||
auto message = "Hello, " + name + " from a CSP template";
|
||||
%>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>[[ name ]]</title>
|
||||
</head>
|
||||
<body>
|
||||
<%c++ $$<<message; %>
|
||||
<%c++
|
||||
if (nameIsEmpty)
|
||||
{
|
||||
$$ << "<br>"
|
||||
<< "You can revisit the same page and append ?name=<i>your_name</i> to change the name";
|
||||
}
|
||||
%>
|
||||
</body>
|
||||
</html>
|
29
examples/helloworld/HelloViewController.cc
Normal file
29
examples/helloworld/HelloViewController.cc
Normal file
@ -0,0 +1,29 @@
|
||||
#include <drogon/HttpSimpleController.h>
|
||||
#include <drogon/HttpResponse.h>
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
// HttpSimpleController does not allow registration of multiple handlers.
|
||||
// Instead, it has one handler - asyncHandleHttpRequest. The
|
||||
// HttpSimpleController is a lightweight class designed to handle really simple
|
||||
// cases.
|
||||
class HelloViewController : public HttpSimpleController<HelloViewController>
|
||||
{
|
||||
public:
|
||||
PATH_LIST_BEGIN
|
||||
// Also unlike HttpContoller, HttpSimpleController does not automatically
|
||||
// prepend the namespace and class name to the path. Thus the path of this
|
||||
// controller is at "/view".
|
||||
PATH_ADD("/view");
|
||||
PATH_LIST_END
|
||||
|
||||
void asyncHandleHttpRequest(
|
||||
const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) override
|
||||
{
|
||||
HttpViewData data;
|
||||
data["name"] = req->getParameter("name");
|
||||
auto resp = HttpResponse::newHttpViewResponse("HelloView", data);
|
||||
callback(resp);
|
||||
}
|
||||
};
|
97
examples/helloworld/main.cc
Normal file
97
examples/helloworld/main.cc
Normal file
@ -0,0 +1,97 @@
|
||||
#include <trantor/utils/Logger.h>
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include <drogon/drogon.h>
|
||||
using namespace drogon;
|
||||
|
||||
int main()
|
||||
{
|
||||
// `registerHandler()` adds a handler to the desired path. The handler is
|
||||
// responsible for generating a HTTP response upon an HTTP request being
|
||||
// sent to Drogon
|
||||
app().registerHandler(
|
||||
"/",
|
||||
[](const HttpRequestPtr &request,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
LOG_INFO << "connected:"
|
||||
<< (request->connected() ? "true" : "false");
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Hello, World!");
|
||||
callback(resp);
|
||||
},
|
||||
{Get});
|
||||
|
||||
// `registerHandler()` also supports parsing and passing the path as
|
||||
// parameters to the handler. Parameters are specified using {}. The text
|
||||
// inside the {} does not correspond to the index of parameter passed to the
|
||||
// handler (nor it has any meaning). Instead, it is only to make it easier
|
||||
// for users to recognize the function of each parameter.
|
||||
app().registerHandler(
|
||||
"/user/{user-name}",
|
||||
[](const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &name) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Hello, " + name + "!");
|
||||
callback(resp);
|
||||
},
|
||||
{Get});
|
||||
|
||||
// You can also specify that the parameter is in the query section of the
|
||||
// URL!
|
||||
app().registerHandler(
|
||||
"/hello?user={user-name}",
|
||||
[](const HttpRequestPtr &,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &name) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setBody("Hello, " + name + "!");
|
||||
callback(resp);
|
||||
},
|
||||
{Get});
|
||||
|
||||
// Or, if you want to, instead of asking drogon to parse it for you. You can
|
||||
// parse the request yourselves.
|
||||
app().registerHandler(
|
||||
"/hello_user",
|
||||
[](const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
auto name = req->getOptionalParameter<std::string>("user");
|
||||
if (!name)
|
||||
resp->setBody("Please tell me your name");
|
||||
else
|
||||
resp->setBody("Hello, " + name.value() + "!");
|
||||
callback(resp);
|
||||
},
|
||||
{Get});
|
||||
|
||||
app()
|
||||
.setBeforeListenSockOptCallback([](int fd) {
|
||||
LOG_INFO << "setBeforeListenSockOptCallback:" << fd;
|
||||
#ifdef _WIN32
|
||||
#elif __linux__
|
||||
int enable = 1;
|
||||
if (setsockopt(
|
||||
fd, IPPROTO_TCP, TCP_FASTOPEN, &enable, sizeof(enable)) ==
|
||||
-1)
|
||||
{
|
||||
LOG_INFO << "setsockopt TCP_FASTOPEN failed";
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
})
|
||||
.setAfterAcceptSockOptCallback([](int) {});
|
||||
|
||||
// Ask Drogon to listen on 127.0.0.1 port 8848. Drogon supports listening
|
||||
// on multiple IP addresses by adding multiple listeners. For example, if
|
||||
// you want the server also listen on 127.0.0.1 port 5555. Just add another
|
||||
// line of addListener("127.0.0.1", 5555)
|
||||
LOG_INFO << "Server running on 127.0.0.1:8848";
|
||||
app().addListener("127.0.0.1", 8848).run();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user