| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | import databases |
| 5 | |
| 6 | const http_port = 8081 |
| 7 | |
| 8 | pub struct Context { |
| 9 | veb.Context |
| 10 | } |
| 11 | |
| 12 | struct App { |
| 13 | veb.StaticHandler |
| 14 | } |
| 15 | |
| 16 | pub fn (app &App) before_request(mut ctx Context) { |
| 17 | println('[veb] ${ctx.req.method} ${ctx.req.url}') |
| 18 | } |
| 19 | |
| 20 | fn main() { |
| 21 | mut db := databases.create_db_connection() or { panic(err) } |
| 22 | |
| 23 | sql db { |
| 24 | create table User |
| 25 | } or { panic('error on create table: ${err}') } |
| 26 | |
| 27 | db.close() or { panic(err) } |
| 28 | |
| 29 | mut app := &App{} |
| 30 | veb.run[App, Context](mut app, http_port) |
| 31 | } |
| 32 | |
| 33 | @['/'; get] |
| 34 | pub fn (mut app App) ping(mut ctx Context) veb.Result { |
| 35 | return ctx.text('ping') |
| 36 | } |
| 37 | |