examples: fix type in veb_example.v

This commit is contained in:
Alexander Medvednikov 2024-09-17 22:57:13 +03:00
parent 1187e1367c
commit c11b1f8bd1
2 changed files with 11 additions and 4 deletions

View File

@ -64,8 +64,8 @@ pub fn (mut app App) cookie(mut ctx Context) veb.Result {
} }
@[post] @[post]
pub fn (mut app Context) post(mut ctx Context) veb.Result { pub fn (mut app App) post(mut ctx Context) veb.Result {
return ctx.text('Post body: ${app.req.data}') return ctx.text('Post body: ${ctx.req.data}')
} }
fn main() { fn main() {

View File

@ -223,7 +223,6 @@ fn ev_callback[A, X](mut pv picoev.Picoev, fd int, events int) {
$if trace_picoev_callback ? { $if trace_picoev_callback ? {
eprintln('> read event on file descriptor ${fd}') eprintln('> read event on file descriptor ${fd}')
} }
// TODO figure out the POST repeat in ev_callback
// println('ev_callback fd=${fd} params.routes=${params.routes.len}') // println('ev_callback fd=${fd} params.routes=${params.routes.len}')
handle_read[A, X](mut pv, mut params, fd) handle_read[A, X](mut pv, mut params, fd)
} else { } else {
@ -329,6 +328,7 @@ fn handle_write_string(mut pv picoev.Picoev, mut params RequestParams, fd int) {
// and the connection stays open until it is ready to read again // and the connection stays open until it is ready to read again
@[direct_array_access; manualfree] @[direct_array_access; manualfree]
fn handle_read[A, X](mut pv picoev.Picoev, mut params RequestParams, fd int) { fn handle_read[A, X](mut pv picoev.Picoev, mut params RequestParams, fd int) {
// println('handle_read() fd=${fd} params.routes=${params.routes}')
mut conn := &net.TcpConn{ mut conn := &net.TcpConn{
sock: net.tcp_socket_from_handle_raw(fd) sock: net.tcp_socket_from_handle_raw(fd)
handle: fd handle: fd
@ -523,6 +523,7 @@ fn handle_complete_request(should_close bool, mut pv picoev.Picoev, fd int) {
} }
fn handle_request[A, X](mut conn net.TcpConn, req http.Request, params &RequestParams) ?&Context { fn handle_request[A, X](mut conn net.TcpConn, req http.Request, params &RequestParams) ?&Context {
// println('handle_request() params.routes=${params.routes}')
mut global_app := unsafe { &A(params.global_app) } mut global_app := unsafe { &A(params.global_app) }
// TODO: change this variable to include the total wait time over each network cycle // TODO: change this variable to include the total wait time over each network cycle
@ -594,7 +595,7 @@ fn handle_request[A, X](mut conn net.TcpConn, req http.Request, params &RequestP
} }
fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string, routes &map[string]Route) { fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string, routes &map[string]Route) {
// println('\n\nHANDLE ROUTE') // println('\n\nhandle_route() url=${url} routes=${routes}')
mut route := Route{} mut route := Route{}
mut middleware_has_sent_response := false mut middleware_has_sent_response := false
mut not_found := false mut not_found := false
@ -712,13 +713,16 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
args << data[param.name] args << data[param.name]
} }
// println('m1')
app.$method(mut user_context, args) app.$method(mut user_context, args)
} else { } else {
// println('m2')
app.$method(mut user_context) app.$method(mut user_context)
} }
return return
} }
// println('route_words=${route_words} method=${method}')
if url_words.len == 0 && route_words == ['index'] && method.name == 'index' { if url_words.len == 0 && route_words == ['index'] && method.name == 'index' {
$if A is MiddlewareApp { $if A is MiddlewareApp {
if validate_middleware[X](mut user_context, route.middlewares) == false { if validate_middleware[X](mut user_context, route.middlewares) == false {
@ -741,8 +745,10 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
args << data[param.name] args << data[param.name]
} }
// println('m3')
app.$method(mut user_context, args) app.$method(mut user_context, args)
} else { } else {
// println('m4')
app.$method(mut user_context) app.$method(mut user_context)
} }
return return
@ -760,6 +766,7 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
if method_args.len + 1 != method.args.len { if method_args.len + 1 != method.args.len {
eprintln('[veb] warning: uneven parameters count (${method.args.len}) in `${method.name}`, compared to the veb route `${method.attrs}` (${method_args.len})') eprintln('[veb] warning: uneven parameters count (${method.args.len}) in `${method.name}`, compared to the veb route `${method.attrs}` (${method_args.len})')
} }
// println('m5')
app.$method(mut user_context, method_args) app.$method(mut user_context, method_args)
return return
} }