-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.v
More file actions
41 lines (36 loc) · 722 Bytes
/
main.v
File metadata and controls
41 lines (36 loc) · 722 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
35
36
37
38
39
40
41
module main
import x.json2
import net.http { Request, Response, Server }
struct Version {
version string
}
struct Handler {}
fn (h Handler) handle(req Request) Response {
mut res := Response{
header: http.new_header_from_map({
.content_type: 'application/json'
})
status_code: 200
}
res.body = match req.url {
'/version' {
json2.encode(Version{ version: '0.0.1' })
}
else {
res.status_code = 404
'Not found\n'
}
}
return res
}
fn main() {
mut server := Server{
handler: Handler{}
addr: ':8000'
on_running: fn (mut s Server) {
println('listening on port ${s.addr}')
}
show_startup_message: false
}
server.listen_and_serve()
}