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

vweb: minor fixes

This commit is contained in:
Alexander Medvednikov 2019-12-20 03:02:16 +03:00
parent fbd9fedbfb
commit 61bfecfa09
4 changed files with 131 additions and 115 deletions

View File

@ -13,10 +13,8 @@ pub mut:
} }
fn main() { fn main() {
mut app := App{} println('noice')
app.vweb = vweb.Context{} vweb.run<App>(port)
vweb.run(mut app, port)
//vweb.run<App>(Port)
} }
pub fn (app mut App) init() { pub fn (app mut App) init() {
@ -32,6 +30,9 @@ pub fn (app mut App) index() {
$vweb.html() $vweb.html()
} }
pub fn (app mut App) reset() {
}
pub fn (app mut App) text() { pub fn (app mut App) text() {
app.vweb.text('Hello world') app.vweb.text('Hello world')
} }

View File

@ -1146,9 +1146,8 @@ pub fn vfmt(args []string) {
exit(1) exit(1)
} }
println('WIP') println('WIP')
/*
vexe := vexe_path() vexe := vexe_path()
//launch_tool('vfmt', '-d vfmt') // launch_tool('vfmt', '-d vfmt')
vroot := os.dir(vexe) vroot := os.dir(vexe)
os.chdir(vroot) os.chdir(vroot)
ret := os.system('$vexe -o $vroot/tools/vfmt -d vfmt v.v') ret := os.system('$vexe -o $vroot/tools/vfmt -d vfmt v.v')
@ -1156,10 +1155,10 @@ pub fn vfmt(args []string) {
println('err') println('err')
return return
} }
os.exec('$vroot/tools/vfmt $file') or { panic(err) } os.exec('$vroot/tools/vfmt $file')or{
//if !os.exists(' panic(err)
*/ }
// if !os.exists('
} }
pub fn create_symlink() { pub fn create_symlink() {

View File

@ -1584,6 +1584,7 @@ fn (p mut Parser) var_decl() {
p.check(.comma) p.check(.comma)
if p.tok == .key_mut { if p.tok == .key_mut {
p.check(.key_mut) p.check(.key_mut)
p.fspace()
var_mut << true var_mut << true
} }
else { else {

View File

@ -122,14 +122,26 @@ fn (ctx &Context) get_header(key string) string {
return ctx.req.headers[key] return ctx.req.headers[key]
} }
//pub fn run<T>(port int) { //fn handle_conn(conn net.Socket) {
pub fn run<T>(app mut T, port int) { //println('handle')
//}
pub fn foo<T>() {
}
pub fn run<T>(port int) {
//pub fn run<T>(app mut T, port int) {
println('Running a Vweb app on http://localhost:$port ...') println('Running a Vweb app on http://localhost:$port ...')
l := net.listen(port) or { panic('failed to listen') } l := net.listen(port) or { panic('failed to listen') }
//mut app := T{} mut app := T{}
app.vweb = Context{}
app.init() app.init()
//app.reset()
for { for {
conn := l.accept() or { panic('accept() failed') } conn := l.accept() or { panic('accept() failed') }
handle_conn(conn, mut app)
//foobar<T>() //foobar<T>()
// TODO move this to handle_conn<T>(conn, app) // TODO move this to handle_conn<T>(conn, app)
//message := readall(conn) //message := readall(conn)
@ -153,7 +165,10 @@ pub fn run<T>(app mut T, port int) {
continue continue
} }
*/ */
}
}
fn handle_conn<T>(conn net.Socket, app mut T) {
//first_line := strip(lines[0]) //first_line := strip(lines[0])
first_line := conn.read_line() first_line := conn.read_line()
println('firstline="$first_line"') println('firstline="$first_line"')
@ -166,7 +181,8 @@ pub fn run<T>(app mut T, port int) {
println('no vals for http') println('no vals for http')
conn.send_string(HTTP_500) or {} conn.send_string(HTTP_500) or {}
conn.close() or {} conn.close() or {}
continue return
//continue
} }
mut headers := []string mut headers := []string
mut body := '' mut body := ''
@ -246,7 +262,8 @@ pub fn run<T>(app mut T, port int) {
println('no vals for http') println('no vals for http')
} }
conn.close() or {} conn.close() or {}
continue return
//continue
} }
// Serve a static file if it's one // Serve a static file if it's one
@ -263,9 +280,7 @@ pub fn run<T>(app mut T, port int) {
conn.send_string(HTTP_404) or {} conn.send_string(HTTP_404) or {}
} }
conn.close() or {} conn.close() or {}
reset := 'reset' app.reset()
app.$reset()
}
} }
fn (ctx mut Context) parse_form(s string) { fn (ctx mut Context) parse_form(s string) {