2022-07-24 13:02:57 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import vweb
|
|
|
|
import databases
|
|
|
|
|
|
|
|
const (
|
|
|
|
http_port = 8081
|
|
|
|
)
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
vweb.Context
|
|
|
|
}
|
|
|
|
|
2022-11-01 20:02:07 +03:00
|
|
|
pub fn (app App) before_request() {
|
2022-11-15 16:53:13 +03:00
|
|
|
println('[Vweb] ${app.Context.req.method} ${app.Context.req.url}')
|
2022-11-01 20:02:07 +03:00
|
|
|
}
|
|
|
|
|
2022-07-24 13:02:57 +03:00
|
|
|
fn main() {
|
|
|
|
mut db := databases.create_db_connection() or { panic(err) }
|
|
|
|
|
|
|
|
sql db {
|
|
|
|
create table User
|
2022-11-15 16:53:13 +03:00
|
|
|
} or { panic('error on create table: ${err}') }
|
2022-07-24 13:02:57 +03:00
|
|
|
|
2022-08-12 17:24:57 +03:00
|
|
|
db.close() or { panic(err) }
|
2022-07-24 13:02:57 +03:00
|
|
|
|
|
|
|
vweb.run(new_app(), http_port)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_app() &App {
|
|
|
|
mut app := &App{}
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
2022-10-22 19:12:54 +03:00
|
|
|
|
|
|
|
['/'; get]
|
|
|
|
pub fn (mut app App) ping() ?vweb.Result {
|
|
|
|
return app.text('ping')
|
|
|
|
}
|