├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── doc └── tujiao.sql ├── src ├── database.rs ├── lib.rs ├── main.rs ├── model │ ├── mod.rs │ └── user.rs └── service │ ├── mod.rs │ └── user_service.rs └── ssl ├── certificate.pem ├── certrequest.csr ├── makessl.txt └── privatekey.pem /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files 2 | *.o 3 | *.so 4 | *.rlib 5 | *.dll 6 | 7 | # Executables 8 | *.exe 9 | 10 | # Generated by Cargo 11 | target 12 | tmp 13 | Cargo.lock 14 | .DS_Store 15 | 16 | # Autogenerated 17 | src/release.rs 18 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "tujiao-api" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "chrono 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 6 | "jsonway 0.3.4 (git+https://github.com/rustless/jsonway)", 7 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 8 | "mysql 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", 9 | "nickel 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 10 | "nickel_mysql 0.1.0 (git+https://github.com/zither/nickel-mysql.git)", 11 | "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 12 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 13 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 14 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 15 | "uuid 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", 16 | ] 17 | 18 | [[package]] 19 | name = "advapi32-sys" 20 | version = "0.1.2" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | dependencies = [ 23 | "winapi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 24 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 25 | ] 26 | 27 | [[package]] 28 | name = "aho-corasick" 29 | version = "0.3.0" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | dependencies = [ 32 | "memchr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 33 | ] 34 | 35 | [[package]] 36 | name = "bitflags" 37 | version = "0.3.2" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | 40 | [[package]] 41 | name = "byteorder" 42 | version = "0.3.11" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | 45 | [[package]] 46 | name = "chrono" 47 | version = "0.2.15" 48 | source = "registry+https://github.com/rust-lang/crates.io-index" 49 | dependencies = [ 50 | "num 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", 51 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 52 | ] 53 | 54 | [[package]] 55 | name = "cookie" 56 | version = "0.1.21" 57 | source = "registry+https://github.com/rust-lang/crates.io-index" 58 | dependencies = [ 59 | "openssl 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 60 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 61 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 62 | "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", 63 | ] 64 | 65 | [[package]] 66 | name = "gcc" 67 | version = "0.3.13" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | dependencies = [ 70 | "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 71 | "winapi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 72 | ] 73 | 74 | [[package]] 75 | name = "groupable" 76 | version = "0.2.0" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | 79 | [[package]] 80 | name = "hpack" 81 | version = "0.2.0" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | dependencies = [ 84 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 85 | ] 86 | 87 | [[package]] 88 | name = "httparse" 89 | version = "0.1.5" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | 92 | [[package]] 93 | name = "hyper" 94 | version = "0.6.9" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | dependencies = [ 97 | "cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", 98 | "httparse 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "language-tags 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", 100 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "mime 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "num_cpus 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 103 | "openssl 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 104 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 105 | "solicit 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 106 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 107 | "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 108 | "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 109 | "unicase 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 110 | "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", 111 | ] 112 | 113 | [[package]] 114 | name = "jsonway" 115 | version = "0.3.4" 116 | source = "git+https://github.com/rustless/jsonway#72436ea7e506949fac3027912ed12e2e5fe76949" 117 | dependencies = [ 118 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 119 | ] 120 | 121 | [[package]] 122 | name = "kernel32-sys" 123 | version = "0.1.4" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | dependencies = [ 126 | "winapi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 128 | ] 129 | 130 | [[package]] 131 | name = "language-tags" 132 | version = "0.0.7" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | 135 | [[package]] 136 | name = "lazy_static" 137 | version = "0.1.14" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | 140 | [[package]] 141 | name = "libc" 142 | version = "0.1.8" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | 145 | [[package]] 146 | name = "libressl-pnacl-sys" 147 | version = "2.1.6" 148 | source = "registry+https://github.com/rust-lang/crates.io-index" 149 | dependencies = [ 150 | "pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)", 151 | ] 152 | 153 | [[package]] 154 | name = "log" 155 | version = "0.3.1" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | dependencies = [ 158 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 159 | ] 160 | 161 | [[package]] 162 | name = "matches" 163 | version = "0.1.2" 164 | source = "registry+https://github.com/rust-lang/crates.io-index" 165 | 166 | [[package]] 167 | name = "memchr" 168 | version = "0.1.3" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | dependencies = [ 171 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 172 | ] 173 | 174 | [[package]] 175 | name = "mime" 176 | version = "0.1.0" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | dependencies = [ 179 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 180 | ] 181 | 182 | [[package]] 183 | name = "modifier" 184 | version = "0.1.0" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | 187 | [[package]] 188 | name = "mustache" 189 | version = "0.6.1" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | dependencies = [ 192 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 193 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 194 | ] 195 | 196 | [[package]] 197 | name = "mysql" 198 | version = "0.18.0" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | dependencies = [ 201 | "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 202 | "byteorder 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", 203 | "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", 204 | "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 205 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 206 | ] 207 | 208 | [[package]] 209 | name = "nickel" 210 | version = "0.6.0" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | dependencies = [ 213 | "groupable 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "hyper 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", 215 | "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", 216 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 217 | "modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 218 | "mustache 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 219 | "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 220 | "regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", 221 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 222 | "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 223 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 224 | "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", 225 | ] 226 | 227 | [[package]] 228 | name = "nickel_mysql" 229 | version = "0.1.0" 230 | source = "git+https://github.com/zither/nickel-mysql.git#6022f116d6597a9932c58688633ca6406c57e542" 231 | dependencies = [ 232 | "mysql 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", 233 | "nickel 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 234 | "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 235 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 236 | ] 237 | 238 | [[package]] 239 | name = "num" 240 | version = "0.1.26" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | dependencies = [ 243 | "rand 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 244 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 245 | ] 246 | 247 | [[package]] 248 | name = "num_cpus" 249 | version = "0.2.6" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | dependencies = [ 252 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 253 | ] 254 | 255 | [[package]] 256 | name = "openssl" 257 | version = "0.6.4" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | dependencies = [ 260 | "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 261 | "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", 262 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 263 | "openssl-sys 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 264 | ] 265 | 266 | [[package]] 267 | name = "openssl-sys" 268 | version = "0.6.4" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | dependencies = [ 271 | "gcc 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", 272 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 273 | "libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 274 | "pkg-config 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 275 | ] 276 | 277 | [[package]] 278 | name = "pkg-config" 279 | version = "0.3.5" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | 282 | [[package]] 283 | name = "plugin" 284 | version = "0.2.6" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | dependencies = [ 287 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 288 | ] 289 | 290 | [[package]] 291 | name = "pnacl-build-helper" 292 | version = "1.4.10" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | dependencies = [ 295 | "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 296 | ] 297 | 298 | [[package]] 299 | name = "rand" 300 | version = "0.3.9" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | dependencies = [ 303 | "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 304 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 305 | "winapi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 306 | ] 307 | 308 | [[package]] 309 | name = "regex" 310 | version = "0.1.41" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | dependencies = [ 313 | "aho-corasick 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 314 | "memchr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 315 | "regex-syntax 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 316 | ] 317 | 318 | [[package]] 319 | name = "regex-syntax" 320 | version = "0.2.1" 321 | source = "registry+https://github.com/rust-lang/crates.io-index" 322 | 323 | [[package]] 324 | name = "rustc-serialize" 325 | version = "0.3.15" 326 | source = "registry+https://github.com/rust-lang/crates.io-index" 327 | 328 | [[package]] 329 | name = "solicit" 330 | version = "0.4.1" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | dependencies = [ 333 | "hpack 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 334 | "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 335 | ] 336 | 337 | [[package]] 338 | name = "tempdir" 339 | version = "0.3.4" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | dependencies = [ 342 | "rand 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 343 | ] 344 | 345 | [[package]] 346 | name = "time" 347 | version = "0.1.32" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | dependencies = [ 350 | "kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 351 | "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 352 | "winapi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 353 | ] 354 | 355 | [[package]] 356 | name = "traitobject" 357 | version = "0.0.1" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | 360 | [[package]] 361 | name = "traitobject" 362 | version = "0.0.3" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | 365 | [[package]] 366 | name = "typeable" 367 | version = "0.1.2" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | 370 | [[package]] 371 | name = "typemap" 372 | version = "0.3.3" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | dependencies = [ 375 | "unsafe-any 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 376 | ] 377 | 378 | [[package]] 379 | name = "unicase" 380 | version = "1.0.0" 381 | source = "registry+https://github.com/rust-lang/crates.io-index" 382 | 383 | [[package]] 384 | name = "unsafe-any" 385 | version = "0.4.1" 386 | source = "registry+https://github.com/rust-lang/crates.io-index" 387 | dependencies = [ 388 | "traitobject 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 389 | ] 390 | 391 | [[package]] 392 | name = "url" 393 | version = "0.2.37" 394 | source = "registry+https://github.com/rust-lang/crates.io-index" 395 | dependencies = [ 396 | "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 398 | ] 399 | 400 | [[package]] 401 | name = "uuid" 402 | version = "0.1.17" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | dependencies = [ 405 | "rand 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 406 | "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 407 | ] 408 | 409 | [[package]] 410 | name = "winapi" 411 | version = "0.2.2" 412 | source = "registry+https://github.com/rust-lang/crates.io-index" 413 | 414 | [[package]] 415 | name = "winapi-build" 416 | version = "0.1.1" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | 419 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tujiao-api" 3 | version = "0.1.0" 4 | authors = ["arden "] 5 | description = "the tujiao api" 6 | repository = "" 7 | readme = "README.md" 8 | keywords = ["tujiao"] 9 | 10 | [lib] 11 | name = "tujiaoapi" 12 | path = "src/lib.rs" 13 | 14 | [[bin]] 15 | name = "tujiao-api" 16 | test = false 17 | bench = false 18 | doctest = false 19 | path = "src/main.rs" 20 | 21 | [dependencies] 22 | time = "*" 23 | uuid = "*" 24 | log = "*" 25 | chrono = "*" 26 | plugin = "*" 27 | typemap = "*" 28 | rustc-serialize = "*" 29 | 30 | [dependencies.mysql] 31 | mysql = "*" 32 | default-features = false 33 | 34 | [dependencies.nickel] 35 | git = "https://github.com/arden/nickel.rs" 36 | 37 | [dependencies.jsonway] 38 | git = "https://github.com/rustless/jsonway" 39 | 40 | [dependencies.nickel_mysql] 41 | git = "https://github.com/arden/nickel-mysql.git" 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tujiao api 2 | -------------------------------------------------------------------------------- /doc/tujiao.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat Premium Data Transfer 3 | 4 | Source Server : localhost 5 | Source Server Type : MySQL 6 | Source Server Version : 50624 7 | Source Host : localhost 8 | Source Database : tujiao 9 | 10 | Target Server Type : MySQL 11 | Target Server Version : 50624 12 | File Encoding : utf-8 13 | 14 | Date: 07/06/2015 11:47:01 AM 15 | */ 16 | 17 | SET NAMES utf8; 18 | SET FOREIGN_KEY_CHECKS = 0; 19 | 20 | -- ---------------------------- 21 | -- 用户 22 | -- ---------------------------- 23 | DROP TABLE IF EXISTS `t_users`; 24 | CREATE TABLE `t_users` ( 25 | `id` int(11) NOT NULL AUTO_INCREMENT, 26 | `name` varchar(50) NOT NULL COMMENT '用户名', 27 | `username` varchar(50) NOT NULL COMMENT '用户昵称', 28 | `mobile` varchar(50) NOT NULL COMMENT '手机号', 29 | `email` varchar(20) DEFAULT NULL COMMENT '邮箱', 30 | `password` varchar(50) NOT NULL COMMENT '手机号', 31 | `uuid` varchar(128) NOT NULL COMMENT '客户端唯一标识号', 32 | `token` varchar(128) DEFAULT NULL COMMENT '推送的令牌', 33 | `sex` int(2) DEFAULT NULL COMMENT '性别', 34 | `source` int(2) DEFAULT null COMMENT '用户注册来源(0->iPhone, 1->iPad, 2->Android)', 35 | `from_source` int(11) DEFAULT 0 COMMENT '通过什么方式注册的', 36 | `avatar` varchar(128) DEFAULT NULL COMMENT '头像', 37 | `lng` float DEFAULT '0.0' COMMENT '经度', 38 | `lat` float DEFAULT '0.0' COMMENT '纬度', 39 | `created_at` timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 40 | `updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', 41 | `status` int(2) DEFAULT 1 COMMENT '状态', 42 | PRIMARY KEY (`id`), 43 | UNIQUE KEY `uuid` (`uuid`) 44 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 45 | -------------------------------------------------------------------------------- /src/database.rs: -------------------------------------------------------------------------------- 1 | use mysql::conn::MyOpts; 2 | use mysql::conn::pool::MyPool; 3 | 4 | //static DB_POOL: Option = None; 5 | 6 | static DB_USER: &'static str = "root"; 7 | static DB_PASSWORD: &'static str = "123456"; 8 | static DB_NAME: &'static str = "tujiao"; 9 | 10 | pub fn get_db_pool() -> MyPool { 11 | let db_config = MyOpts { 12 | user: Some(DB_USER.to_string()), 13 | pass: Some(DB_PASSWORD.to_string()), 14 | db_name: Some(DB_NAME.to_string()), 15 | ..Default::default() 16 | }; 17 | let db_pool = MyPool::new(db_config).unwrap(); 18 | return db_pool; 19 | } 20 | 21 | /* 22 | pub fn getDbPoolSingleton() -> Option { 23 | let dbConfig = MyOpts { 24 | user: Some(DB_USER.to_string()), 25 | pass: Some(DB_PASSWORD.to_string()), 26 | db_name: Some(DB_NAME.to_string()), 27 | ..Default::default() 28 | }; 29 | 30 | //if DB_POOL.is_none() { 31 | if let None = DB_POOL {} { 32 | //DB_POOL = Some(MyPool::new(dbConfig).unwrap()); 33 | } 34 | 35 | return Some(DB_POOL); 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate mysql; 2 | extern crate chrono; 3 | 4 | pub mod model; 5 | pub mod service; 6 | pub mod database; 7 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate tujiaoapi; 2 | #[macro_use] extern crate nickel; 3 | extern crate rustc_serialize as serialize; 4 | extern crate jsonway; 5 | extern crate mysql; 6 | extern crate nickel_mysql; 7 | 8 | use std::path::Path; 9 | use nickel::{Nickel, HttpRouter, MediaType}; 10 | use nickel_mysql::{MysqlMiddleware, MysqlRequestExtensions}; 11 | 12 | use tujiaoapi::service::user_service::UserService; 13 | use tujiaoapi::database::get_db_pool; 14 | use tujiaoapi::model::user::*; 15 | use serialize::json::{Json, ToJson}; 16 | use std::collections::BTreeMap; 17 | 18 | fn main() { 19 | let mut app = Nickel::new(); 20 | app.utilize(MysqlMiddleware::new("tujiao", "root", "123456")); 21 | 22 | app.get("/user/:userid", middleware! { |request| 23 | format!("This is user: {:?}", request.param("userid")) 24 | }); 25 | 26 | app.get("/v1/user/list", middleware! { |request, mut response| 27 | //response.set(MediaType::Json); 28 | 29 | let connection = request.db_connection(); 30 | let mut user_service = UserService::new(connection); 31 | let users: Vec = user_service.get_users(); 32 | 33 | let json = jsonway::array(|json| { 34 | json.objects(users.iter(), |user, json| { 35 | json.set("id".to_string(), user.id.to_string()); 36 | json.set("email".to_string(), user.email.as_ref().unwrap().to_string()); 37 | }) 38 | }).unwrap(); 39 | let mut json_extras = BTreeMap::new(); 40 | json_extras.insert("totalCount".to_string(), "100".to_json()); 41 | json_extras.insert("users".to_string(), json); 42 | Json::Object(json_extras) 43 | 44 | }); 45 | 46 | //app.listen("0.0.0.0:6767"); 47 | 48 | let cert_path = Path::new("/Users/arden/data/repository/trunk/tj/server/tujiao-api/ssl/certificate.pem"); 49 | let key_path = Path::new("/Users/arden/data/repository/trunk/tj/server/tujiao-api/ssl/privatekey.pem"); 50 | app.listen_https("0.0.0.0:6767", cert_path, key_path); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/model/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod user; 2 | -------------------------------------------------------------------------------- /src/model/user.rs: -------------------------------------------------------------------------------- 1 | use chrono::datetime::DateTime; 2 | use chrono::offset::utc::UTC; 3 | 4 | pub struct User { 5 | pub id: u32, 6 | pub name: Option, 7 | pub username: Option, 8 | pub mobile: Option, 9 | pub email: Option, 10 | pub password: Option, 11 | pub uuid: Option, 12 | pub token: Option, 13 | pub sex: Option, 14 | pub source: Option, 15 | pub from_source: Option, 16 | pub avatar: Option, 17 | pub lng: Option, 18 | pub lat: Option, 19 | pub created_at: Option>, 20 | pub updated_at: Option>, 21 | pub status: Option 22 | } 23 | 24 | impl Default for User { 25 | fn default() -> User { 26 | User{ 27 | id: 0, 28 | name: None, 29 | username: None, 30 | mobile: None, 31 | email: None, 32 | password: None, 33 | uuid: None, 34 | token: None, 35 | sex: None, 36 | source: None, 37 | from_source: None, 38 | avatar: None, 39 | lng: None, 40 | lat: None, 41 | created_at: None, 42 | updated_at: None, 43 | status: None 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/service/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod user_service; 2 | -------------------------------------------------------------------------------- /src/service/user_service.rs: -------------------------------------------------------------------------------- 1 | use mysql::conn::pool::MyPool; 2 | use mysql::value::from_row; 3 | use std::sync::Arc; 4 | 5 | use ::model::user::*; 6 | 7 | pub struct UserService { 8 | db_pool: Arc 9 | } 10 | 11 | impl UserService { 12 | pub fn default(db_pool: Arc) -> UserService { 13 | UserService { 14 | db_pool: db_pool, 15 | } 16 | } 17 | 18 | pub fn new(db_pool: Arc) -> UserService { 19 | Self::default(db_pool) 20 | } 21 | 22 | pub fn get_users(&mut self) -> Vec { 23 | let users: Vec = self.db_pool.prep_exec("SELECT id, email from t_users", ()) 24 | .map(|result| { 25 | result.map(|x| x.unwrap()).map(|row| { 26 | let (id, email) = from_row(row); 27 | User { 28 | id: id, 29 | email: email, 30 | ..Default::default() 31 | } 32 | }).collect() 33 | }).unwrap(); 34 | return users; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ssl/certificate.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIChzCCAfACCQCQpzw9po01sjANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC 3 | Q0ExEjAQBgNVBAgTCUd1YW5nRG9uZzERMA8GA1UEBxMIc2hlbnpoZW4xDzANBgNV 4 | BAoTBnR1amlhbzEPMA0GA1UECxMGdHVqaWFvMQ4wDAYDVQQDEwVhcmRlbjEfMB0G 5 | CSqGSIb3DQEJARYQYXJkZW5AdHVqaWFvLmNvbTAeFw0xNTA3MTYwODA1MzZaFw0x 6 | NTA4MTUwODA1MzZaMIGHMQswCQYDVQQGEwJDQTESMBAGA1UECBMJR3VhbmdEb25n 7 | MREwDwYDVQQHEwhzaGVuemhlbjEPMA0GA1UEChMGdHVqaWFvMQ8wDQYDVQQLEwZ0 8 | dWppYW8xDjAMBgNVBAMTBWFyZGVuMR8wHQYJKoZIhvcNAQkBFhBhcmRlbkB0dWpp 9 | YW8uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCamV35nscpP/wOR6Uq 10 | xaRkISYnE8FCLwBnvh9OY/Fp7jDdE9zdXiuHPPFiRp9Kv7Nyx/UM6v7ki3WSDqBp 11 | HqQUHsPb0yxWWWOio/zKfsPGFnR5oIDTeFPP4FyuNh3Untcgiu5/hOI7gmOh9lz2 12 | BF71RQ9NCCVdmamvgw+VnPvHMQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBADgUfdxb 13 | eXXuEbrdxUid9dP1f6yZkQZj6jzKjYee7vo+oH/za78UBfHALxymrAkF5nZxSo8x 14 | 2O+QAlkFWAQv/c6JhR+WBVTCmA+mwrtMNiwAKBz4cGOaNK2FR1bgiCYvFQTkx35M 15 | /fbG7vJaQkziiXovCjqxdlVloHTzBFtdazJc 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /ssl/certrequest.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIB9jCCAV8CAQAwgYcxCzAJBgNVBAYTAkNBMRIwEAYDVQQIEwlHdWFuZ0Rvbmcx 3 | ETAPBgNVBAcTCHNoZW56aGVuMQ8wDQYDVQQKEwZ0dWppYW8xDzANBgNVBAsTBnR1 4 | amlhbzEOMAwGA1UEAxMFYXJkZW4xHzAdBgkqhkiG9w0BCQEWEGFyZGVuQHR1amlh 5 | by5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJqZXfmexyk//A5HpSrF 6 | pGQhJicTwUIvAGe+H05j8WnuMN0T3N1eK4c88WJGn0q/s3LH9Qzq/uSLdZIOoGke 7 | pBQew9vTLFZZY6Kj/Mp+w8YWdHmggNN4U8/gXK42HdSe1yCK7n+E4juCY6H2XPYE 8 | XvVFD00IJV2Zqa+DD5Wc+8cxAgMBAAGgLjAVBgkqhkiG9w0BCQIxCBMGdHVqaWFv 9 | MBUGCSqGSIb3DQEJBzEIEwYxMjM0NTYwDQYJKoZIhvcNAQEFBQADgYEAKYs/AS3Z 10 | a28SkynVh8d1wIkwB8PAeR1hnLGfjxsBoaa/WeJoAOzm2DRw3TUDfDD3te4s7Cbr 11 | ZbGzX9Dj7BZ41ZKghms0WFnp0gilWq12IZ5hmEGjLdefmLBjwvClpruGMyUnayGp 12 | 5LuZ1qAWnyYYKe2Cgosr6AWZqgjUstUFIJ8= 13 | -----END CERTIFICATE REQUEST----- 14 | -------------------------------------------------------------------------------- /ssl/makessl.txt: -------------------------------------------------------------------------------- 1 | openssl genrsa -out privatekey.pem 1024 2 | openssl req -new -key privatekey.pem -out certrequest.csr 3 | openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem 4 | -------------------------------------------------------------------------------- /ssl/privatekey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICWwIBAAKBgQCamV35nscpP/wOR6UqxaRkISYnE8FCLwBnvh9OY/Fp7jDdE9zd 3 | XiuHPPFiRp9Kv7Nyx/UM6v7ki3WSDqBpHqQUHsPb0yxWWWOio/zKfsPGFnR5oIDT 4 | eFPP4FyuNh3Untcgiu5/hOI7gmOh9lz2BF71RQ9NCCVdmamvgw+VnPvHMQIDAQAB 5 | AoGAe0zoi4bcFwUmFYmErJlXJFjf4fi6gPuVmigjNdU2HKNRK3GFDLTniIPNjPEA 6 | aJB+IYRi5/ugcUzc5zFtNImwl/IeaKVDND5zZeya7HZluzGYHYyHUdmgHhjbUQw4 7 | sYJsnRoPvOQqw0NT+fvaj5UgWDXx8hfL6QZDp/PIOiCqG2UCQQDIHqdqGRDJ8H60 8 | I2qQyEjprvjKbNcC0RutXIGwPs7GmrXeTuVGVwTLl57sGJX79cHxO0/FKiwzLg+l 9 | Z+Mm3RaDAkEAxcS3y0BQUodNczyVQTBrvMI3V62GCW1o7k2NxRPqM4T9JJCj4O4a 10 | FhiSY1RwBUbYmayK71juhBOdcHbGJp5dOwJASXMm00Q760J/3rIZDObWDB8SZYmp 11 | KPmDBRAs8Xk7/50NH3kpobWSpv8Rb2peskmzU00HrEAcVPSU/YqxzrPa7QJAJBRD 12 | Q300Khos8vz2bbIbtY/o8MHjVgzzu6XCW1XKwCNe2zDX9Mz7TVSmQCDDXvMRyNdF 13 | cWzT9pxteHryo1D4yQJAV0NDk09IUZ/nEvwY4jHxOv+YYg78q7yMF3wEvQLVCO0r 14 | 0/3FGrcwMw8vahx6QQBulovcZ4+iu+5AWAeWEn+awQ== 15 | -----END RSA PRIVATE KEY----- 16 | --------------------------------------------------------------------------------