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

vweb: form error

This commit is contained in:
Alexander Medvednikov 2020-07-07 21:35:56 +02:00
parent cdfb578565
commit 246e7e8464

View File

@ -53,6 +53,8 @@ pub mut:
headers string // response headers headers string // response headers
done bool done bool
page_gen_start i64 page_gen_start i64
form_error string
} }
pub struct Cookie { pub struct Cookie {
@ -353,19 +355,19 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
} }
} }
mut vars := []string{cap: route_words.len} mut vars := []string{cap: route_words.len}
//println('http method = $req.method')
$for method in T { $for method in T {
ok = true ok = true
println('\n\n method = $method urlwords=') //println('\n\n method = $method urlwords=')
println(url_words) //println(url_words)
println('attrs=$attrs') //println('attrs=$attrs')
if attrs == '' { if attrs == '' {
// No routing for this method. If it matches, call it and finish matching // No routing for this method. If it matches, call it and finish matching
// since such methods have a priority. // since such methods have a priority.
// For example URL `/register` matches route `/:user`, but `fn register()` // For example URL `/register` matches route `/:user`, but `fn register()`
// should be called first. // should be called first.
println('no attrs for ${url_words[0]}') //println('no attrs for ${url_words[0]}')
if url_words[0] == method { if (req.method == 'GET' && url_words[0] == method) || (req.method == 'POST' && url_words[0] + '_post' == method) {
println('easy match $method') println('easy match $method')
vars = [] vars = []
app.$method(vars) app.$method(vars)
@ -522,6 +524,10 @@ pub fn (mut ctx Context) serve_static(url, file_path, mime_type string) {
ctx.static_mime_types[url] = mime_type ctx.static_mime_types[url] = mime_type
} }
pub fn (mut ctx Context) error(s string) {
ctx.form_error = s
}
/* /*
fn readall(conn net.Socket) string { fn readall(conn net.Socket) string {