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

vweb: check function and route parameter count (#6761)

This commit is contained in:
pancake
2020-11-08 09:14:24 +01:00
committed by GitHub
parent 6da8454b3b
commit 2994e7150f
9 changed files with 138 additions and 15 deletions

View File

@@ -203,7 +203,7 @@ pub fn run_app<T>(mut app T, port int) {
$if method.return_type is Result {
// check routes for validity
}
}
}
//app.reset()
for {
conn := l.accept() or { panic('accept() failed') }
@@ -380,7 +380,7 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
mut vars := []string{cap: route_words_a.len}
mut action := ''
$for method in T.methods {
$if method.return_type is Result {
$if method.return_type is Result {
attrs := method.attrs
route_words_a = [][]string{}
if attrs.len == 0 {
@@ -485,7 +485,11 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
// search again for method
if action == method.name && method.attrs.len > 0 {
// call action method
app.$method(vars)
if method.args.len == vars.len {
app.$method(vars)
} else {
eprintln('warning: uneven parameters count (${method.args.len}) in `$method.name`, compared to the vweb route `$method.attrs` (${vars.len})')
}
}
}
}