Completely refactor project structure
parent: tbd commit: ae8ff44
1 | use Error; |
2 | use ; |
3 | use |
4 | , | AuthenticationTokenGranter
5 | , |
6 | , |
7 | ; |
8 | use Instance; |
9 | use ; |
10 | use ; |
11 | use |
12 | , | File
13 | , |
14 | , |
15 | , | Mutex
16 | ; |
17 | use ; |
18 | use Table; |
19 | |
20 | |
21 | extern crate tracing; |
22 | |
23 | |
24 | async |
25 | ; | init
26 | let mut listener = bind .await?; |
27 | let connections: = default; |
28 | let config: Table = |
29 | let mut file = open .await?; |
30 | let mut text = String new; |
31 | file.read_to_string .await?; |
32 | text.parse? |
33 | ; |
34 | let db_conn_options = new |
35 | .host |
36 | .port |
37 | .database |
38 | .username |
39 | .password |
40 | .log_statements; |
41 | let db_pool = connect_with .await?; |
42 | |
43 | debug!; |
44 | ! .run .await?; | migrate
45 | info!; |
46 | |
47 | let repository_backend: = |
48 | new |
49 | pg_pool: db_pool.clone, |
50 | repository_folder: String from |
51 | config |
52 | .as_str |
53 | .unwrap, |
54 | , |
55 | instance: from_str .unwrap, |
56 | ; |
57 | |
58 | let token_granter = new |
59 | config: config.clone, |
60 | instance: from_str .unwrap, |
61 | ; |
62 | |
63 | let user_backend: = new |
64 | db_pool.clone, |
65 | & from_str .unwrap, |
66 | token_granter.clone, |
67 | ; |
68 | |
69 | info!; |
70 | |
71 | loop |
72 | let stream = accept_stream .await; |
73 | info!; |
74 | |
75 | let = match stream |
76 | Ok => stream, |
77 | Err => |
78 | error!; |
79 | continue; |
80 | |
81 | ; |
82 | |
83 | info!; |
84 | |
85 | let connection = accept_websocket_connection .await; |
86 | |
87 | let connection = match connection |
88 | Ok => connection, |
89 | Err => |
90 | error! |
91 | "Failed to initiate Websocket connection from {}. {:?}", |
92 | address, err |
93 | ; |
94 | continue; |
95 | |
96 | ; |
97 | |
98 | info!; |
99 | |
100 | let connection = RawConnection |
101 | task: spawn |
102 | connection, |
103 | connections.clone, |
104 | repository_backend.clone, |
105 | user_backend.clone, |
106 | token_granter.clone, |
107 | address, |
108 | unwrap, | from_str .
109 | , |
110 | ; |
111 | |
112 | connections.lock .await.connections.push; |
113 | |
114 | |
115 | |
116 | async |
117 | let stream = listener.accept .await?; |
118 | |
119 | Ok |
120 | |
121 | |
122 | async |
123 | stream: S, |
124 | |
125 | let connection = accept_async .await?; |
126 | |
127 | Ok |
128 | |
129 |