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

vweb fixes

This commit is contained in:
Alexander Medvednikov 2019-08-03 01:35:36 +02:00
parent 9e380e2886
commit 34a98e3df0
2 changed files with 19 additions and 13 deletions

View File

@ -106,6 +106,12 @@ pub fn (db DB) exec_param2(query string, param, param2 string) []pg.Row {
param_vals[0] = param.str
param_vals[1] = param2.str
res := C.PQexecParams(db.conn, query.str, 2, 0, param_vals, 0, 0, 0)
e := string(C.PQerrorMessage(db.conn))
if e != '' {
println('pg exec2 error:')
println(e)
return res_to_rows(res)
}
return res_to_rows(res)
}

View File

@ -86,8 +86,8 @@ $html
pub fn run<T>(port int) {
println('Running vweb app on http://localhost:$port ...')
l := net.listen(port) or { panic('failed to listen') return }
mut app_init := T{}
app_init.init()
mut app := T{}
app.init()
for {
conn := l.accept() or {
panic('accept() failed')
@ -133,15 +133,15 @@ pub fn run<T>(port int) {
url: vals[1]
}
println('vweb action = "$action"')
mut app := T{
vweb: Context{
//mut app := T{
app.vweb = Context{
req: req
conn: conn
post_form: map[string]string{}
static_files: map[string]string{}
static_mime_types: map[string]string{}
}
}
//}
if req.method == 'POST' {
app.vweb.parse_form(s)
}
@ -181,12 +181,12 @@ fn (ctx mut Context) parse_form(s string) {
words := str_form.split('&')
for word in words {
println('parse form keyval="$word"')
keyval := word.split('=')
keyval := word.trim_space().split('=')
if keyval.len != 2 { continue }
key := keyval[0]
val := keyval[1]
//println('http form $key => $val')
ctx.post_form[key] = http.unescape_url(val)
val := http.unescape_url(keyval[1])
println('http form "$key" => "$val"')
ctx.post_form[key] = val
}
}
}