1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: refactor routing logic (#9025)

This commit is contained in:
Miccah
2021-03-01 04:50:52 -06:00
committed by GitHub
parent 8045395cbd
commit d0fab60981
6 changed files with 434 additions and 178 deletions

View File

@ -1,6 +1,7 @@
module main
import vweb
import rand
const (
port = 8082
@ -21,8 +22,10 @@ pub fn (mut app App) init_once() {
app.handle_static('.', false)
}
pub fn (mut app App) json_endpoint() vweb.Result {
return app.json('{"a": 3}')
['/users/:user']
pub fn (mut app App) user_endpoint(user string) vweb.Result {
id := rand.intn(100)
return app.json('{"$user": $id}')
}
pub fn (mut app App) index() vweb.Result {