-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathmain.v
More file actions
34 lines (27 loc) · 764 Bytes
/
main.v
File metadata and controls
34 lines (27 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module main
import fasthttp
fn handle_request(req fasthttp.HttpRequest) ![]u8 {
method := req.buffer[req.method.start..req.method.start + req.method.len].bytestr()
path := req.buffer[req.path.start..req.path.start + req.path.len].bytestr()
if method == 'GET' {
if path == '/' {
return home_controller()!
} else if path.starts_with('/user/') {
id := path[6..]
return get_user_controller(id)!
}
} else if method == 'POST' {
if path == '/user' {
return create_user_controller()!
}
}
return not_found_response()!
}
fn main() {
mut server := fasthttp.new_server(3000, handle_request) or {
eprintln('Failed to create server: ${err}')
return
}
println('Starting fasthttp server on port http://localhost:3000...')
server.run()
}