From 352cf91ba222c603f0fc8c85f0127c353dbd937b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 8 Jan 2021 04:57:02 +0100 Subject: [PATCH] vweb: remove `return vweb.Result{}` everywhere --- CHANGELOG.md | 3 ++- tutorials/building-a-simple-web-blog-with-vweb.md | 15 +++++---------- vlib/v/checker/tests/vweb_routing_checks.vv | 11 ++++------- vlib/vweb/tests/vweb_test_server.v | 9 +++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e193adcc45..98a24e2b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ - Overloading of `>`, `<`, `!=`, and `==` operators. - New struct updating syntax: `User{ ...u, name: 'new' }` to replace `{ u | name: 'new' }`. - `byte.str()` has been fixed and works like with all other numbers. `byte.ascii_str()` has been added. -- Smart cast in for-loops: `for mut x is string {}` +- Smart cast in for loops: `for mut x is string {}`. +- `[noinit]` struct attribute to disallow direct struct initialization with `Foo{}`. ## V 0.2.1 *30 Dec 2020* diff --git a/tutorials/building-a-simple-web-blog-with-vweb.md b/tutorials/building-a-simple-web-blog-with-vweb.md index 194560931e..5ca6b099ad 100644 --- a/tutorials/building-a-simple-web-blog-with-vweb.md +++ b/tutorials/building-a-simple-web-blog-with-vweb.md @@ -70,8 +70,7 @@ fn main() { } pub fn (mut app App) index() vweb.Result { - app.text('Hello, world from vweb!') - return vweb.Result{} + return app.text('Hello world from vweb!') } pub fn (app &App) init() { @@ -110,8 +109,7 @@ import vweb import time fn (mut app App) time() vweb.Result { - app.text(time.now().format()) - return vweb.Result{} + return app.text(time.now().format()) } ``` @@ -352,8 +350,7 @@ pub fn (mut app App) new_article() vweb.Result { title := app.form['title'] text := app.form['text'] if title == '' || text == '' { - app.text('Empty text/title') - return vweb.Result{} + return app.text('Empty text/title') } article := Article{ title: title @@ -363,8 +360,7 @@ pub fn (mut app App) new_article() vweb.Result { sql app.db { insert article into Article } - app.redirect('/') - return vweb.Result{} + return app.redirect('/') } ``` @@ -391,8 +387,7 @@ import json pub fn (mut app App) articles() vweb.Result { articles := app.find_all_articles() - app.json(json.encode(articles)) - return vweb.Result{} + return app.json(json.encode(articles)) } ``` diff --git a/vlib/v/checker/tests/vweb_routing_checks.vv b/vlib/v/checker/tests/vweb_routing_checks.vv index b2a26cf715..e016623388 100644 --- a/vlib/v/checker/tests/vweb_routing_checks.vv +++ b/vlib/v/checker/tests/vweb_routing_checks.vv @@ -5,29 +5,26 @@ struct App { } pub fn (mut app App) no_attributes(a string) vweb.Result { - return vweb.Result{} + return app.text('ok') } // works fine, as long as fcn gets 1 arg and route takes 1 var ['/foo/:bar'] pub fn (mut app App) foo(a string) vweb.Result { eprintln('foo') - app.html('works') - return vweb.Result{} + return app.html('works') } // segfault because path taks 0 vars and fcn takes 1 arg ['/bar'] pub fn (mut app App) bar(a string) vweb.Result { - app.html('works') - return vweb.Result{} + return app.html('works') } // no segfault, but it shouldnt compile ['/cow/:low'] pub fn (mut app App) cow() vweb.Result { - app.html('works') - return vweb.Result{} + return app.html('works') } pub fn (app App) init_once() { diff --git a/vlib/vweb/tests/vweb_test_server.v b/vlib/vweb/tests/vweb_test_server.v index b41d37c999..c587b153cf 100644 --- a/vlib/vweb/tests/vweb_test_server.v +++ b/vlib/vweb/tests/vweb_test_server.v @@ -53,8 +53,7 @@ pub fn (mut app App) simple() vweb.Result { } pub fn (mut app App) html_page() vweb.Result { - app.html('

ok

') - return vweb.Result{} + return app.html('

ok

') } // the following serve custom routes @@ -63,8 +62,7 @@ pub fn (mut app App) settings(username string) vweb.Result { if username !in known_users { return app.not_found() } - app.html('username: $username') - return vweb.Result{} + return app.html('username: $username') } ['/:user/:repo/settings'] @@ -72,8 +70,7 @@ pub fn (mut app App) user_repo_settings(username string, repository string) vweb if username !in known_users { return app.not_found() } - app.html('username: $username | repository: $repository') - return vweb.Result{} + return app.html('username: $username | repository: $repository') } [post]