all: update remaining deprecated attr syntax (#19908)

This commit is contained in:
Turiiya 2023-11-17 11:03:51 +01:00 committed by GitHub
parent 709976f42e
commit b347f546f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 64 additions and 64 deletions

View file

@ -67,7 +67,7 @@ fn new_app() &App {
return app
}
['/']
@['/']
pub fn (mut app App) page_home() vweb.Result {
// all this constants can be accessed by src/templates/page/home.html file.
page_title := 'V is the new V'
@ -182,7 +182,7 @@ fn (mut app App) hello() vweb.Result {
}
// This endpoint can be accessed via http://localhost:port/foo
["/foo"]
@["/foo"]
fn (mut app App) world() vweb.Result {
return app.text('World')
}
@ -197,12 +197,12 @@ you can simply add the attribute before the function definition.
**Example:**
```v ignore
[post]
@[post]
fn (mut app App) world() vweb.Result {
return app.text('World')
}
['/product/create'; post]
@['/product/create'; post]
fn (mut app App) create_product() vweb.Result {
return app.text('product')
}
@ -220,7 +220,7 @@ After it is defined in the attribute, you have to add it as a function parameter
```v ignore
vvvv
['/hello/:user'] vvvv
@['/hello/:user'] vvvv
fn (mut app App) hello_user(user string) vweb.Result {
return app.text('Hello $user')
}
@ -245,7 +245,7 @@ This will match all routes after `'/'`. For example the url `/path/to/test` woul
```v ignore
vvv
['/:path...'] vvvv
@['/:path...'] vvvv
fn (mut app App) wildcard(path string) vweb.Result {
return app.text('URL path = "${path}"')
}
@ -269,7 +269,7 @@ fn main() {
vweb.run(&App{}, 8081)
}
['/user'; get]
@['/user'; get]
pub fn (mut app App) controller_get_user_by_id() vweb.Result {
// http://localhost:3000/user?q=vpm&order_by=desc => { 'q': 'vpm', 'order_by': 'desc' }
return app.text(app.query.str())
@ -283,18 +283,18 @@ by adding a host to the "hosts" file of your device.
**Example:**
```v ignore
['/'; host: 'example.com']
@['/'; host: 'example.com']
pub fn (mut app App) hello_web() vweb.Result {
return app.text('Hello World')
}
['/'; host: 'api.example.org']
@['/'; host: 'api.example.org']
pub fn (mut app App) hello_api() vweb.Result {
return app.text('Hello API')
}
// define the handler without a host attribute last if you have conflicting paths.
['/']
@['/']
pub fn (mut app App) hello_others() vweb.Result {
return app.text('Hello Others')
}
@ -376,8 +376,8 @@ Middleware can also be added to route specific functions via attributes.
**Example:**
```v ignore
[middleware: check_auth]
['/admin/data']
@[middleware: check_auth]
@['/admin/data']
pub fn (mut app App) admin() vweb.Result {
// ...
}
@ -489,7 +489,7 @@ pub fn (mut app App) before_request() {
```
```v ignore
['/articles'; get]
@['/articles'; get]
pub fn (mut app App) articles() vweb.Result {
if !app.token {
app.redirect('/login')
@ -503,14 +503,14 @@ You can also combine middleware and redirect.
**Example:**
```v ignore
[middleware: with_auth]
['/admin/secret']
@[middleware: with_auth]
@['/admin/secret']
pub fn (mut app App) admin_secret() vweb.Result {
// this code should never be reached
return app.text('secret')
}
['/redirect']
@['/redirect']
pub fn (mut app App) with_auth() bool {
app.redirect('/auth/login')
return false
@ -767,7 +767,7 @@ will simply be ignored.
Any route inside a controller struct is treated as a relative route to its controller namespace.
```v ignore
['/path']
@['/path']
pub fn (mut app Admin) path vweb.Result {
return app.text('Admin')
}
@ -780,7 +780,7 @@ Vweb doesn't support fallback routes or duplicate routes, so if we add the follo
route to the example the code will produce an error.
```v ignore
['/admin/path']
@['/admin/path']
pub fn (mut app App) admin_path vweb.Result {
return app.text('Admin overwrite')
}
@ -916,7 +916,7 @@ Sets the response status
**Example:**
```v ignore
['/user/get_all'; get]
@['/user/get_all'; get]
pub fn (mut app App) controller_get_all_user() vweb.Result {
token := app.get_header('token')
@ -961,7 +961,7 @@ Response HTTP_OK with payload with content-type `application/json`
**Examples:**
```v ignore
['/articles'; get]
@['/articles'; get]
pub fn (mut app App) articles() vweb.Result {
articles := app.find_all_articles()
json_result := json.encode(articles)
@ -970,7 +970,7 @@ pub fn (mut app App) articles() vweb.Result {
```
```v ignore
['/user/create'; post]
@['/user/create'; post]
pub fn (mut app App) controller_create_user() vweb.Result {
body := json.decode(User, app.req.data) or {
app.set_status(400, '')
@ -1009,7 +1009,7 @@ Response HTTP_OK with payload
**Example:**
```v ignore
['/form_echo'; post]
@['/form_echo'; post]
pub fn (mut app App) form_echo() vweb.Result {
app.set_content_type(app.req.header.get(.content_type) or { '' })
return app.ok(app.form['foo'])
@ -1033,7 +1033,7 @@ Response HTTP_NOT_FOUND with payload
**Example:**
```v ignore
['/:user/:repo/settings']
@['/:user/:repo/settings']
pub fn (mut app App) user_repo_settings(username string, repository string) vweb.Result {
if username !in known_users {
return app.not_found()
@ -1050,7 +1050,7 @@ Returns the header data from the key
**Example:**
```v ignore
['/user/get_all'; get]
@['/user/get_all'; get]
pub fn (mut app App) controller_get_all_user() vweb.Result {
token := app.get_header('token')
return app.text(token)
@ -1074,7 +1074,7 @@ Adds an header to the response with key and val
**Example:**
```v ignore
['/upload'; post]
@['/upload'; post]
pub fn (mut app App) upload() vweb.Result {
fdata := app.files['upfile']
@ -1132,7 +1132,7 @@ Sets the response content type
**Example:**
```v ignore
['/form_echo'; post]
@['/form_echo'; post]
pub fn (mut app App) form_echo() vweb.Result {
app.set_content_type(app.req.header.get(.content_type) or { '' })
return app.ok(app.form['foo'])