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

View File

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

View File

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

View File

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