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

@ -2344,7 +2344,7 @@ V doesn't have default function arguments or named arguments, for that trailing
literal syntax can be used instead: literal syntax can be used instead:
```v ```v
[params] @[params]
struct ButtonConfig { struct ButtonConfig {
text string text string
is_disabled bool is_disabled bool
@ -2470,7 +2470,7 @@ For an example, consider the following source in a directory `sample`:
```v oksyntax ```v oksyntax
module sample module sample
[noinit] @[noinit]
pub struct Information { pub struct Information {
pub: pub:
data string data string
@ -4488,7 +4488,7 @@ be achieved by tagging your assert containing functions with an `[assert_continu
tag, for example running this program: tag, for example running this program:
```v ```v
[assert_continues] @[assert_continues]
fn abc(ii int) { fn abc(ii int) {
assert ii == 2 assert ii == 2
} }
@ -4640,7 +4640,7 @@ data types:
```v ```v
struct MyType {} struct MyType {}
[unsafe] @[unsafe]
fn (data &MyType) free() { fn (data &MyType) free() {
// ... // ...
} }
@ -4813,7 +4813,7 @@ mut:
} }
// see discussion below // see discussion below
[heap] @[heap]
struct MyStruct { struct MyStruct {
n int n int
} }
@ -4974,7 +4974,7 @@ V's ORM provides a number of benefits:
import db.sqlite import db.sqlite
// sets a custom table name. Default is struct name (case-sensitive) // sets a custom table name. Default is struct name (case-sensitive)
[table: 'customers'] @[table: 'customers']
struct Customer { struct Customer {
id int [primary; sql: serial] // a field named `id` of integer type must be the first field id int [primary; sql: serial] // a field named `id` of integer type must be the first field
name string [nonull] name string [nonull]
@ -5353,7 +5353,7 @@ function/struct/enum declaration and applies only to the following declaration.
```v ```v
// [flag] enables Enum types to be used as bitfields // [flag] enables Enum types to be used as bitfields
[flag] @[flag]
enum BitField { enum BitField {
read read
write write
@ -5395,13 +5395,13 @@ Function/method deprecations:
```v ```v
// Calling this function will result in a deprecation warning // Calling this function will result in a deprecation warning
[deprecated] @[deprecated]
fn old_function() { fn old_function() {
} }
// It can also display a custom deprecation message // It can also display a custom deprecation message
[deprecated: 'use new_function() instead'] @[deprecated: 'use new_function() instead']
fn legacy_function() {} fn legacy_function() {}
// You can also specify a date, after which the function will be // You can also specify a date, after which the function will be
@ -5413,19 +5413,19 @@ fn legacy_function() {}
// 6 months after the deprecation date, calls will be hard // 6 months after the deprecation date, calls will be hard
// compiler errors. // compiler errors.
[deprecated: 'use new_function2() instead'] @[deprecated: 'use new_function2() instead']
[deprecated_after: '2021-05-27'] @[deprecated_after: '2021-05-27']
fn legacy_function2() {} fn legacy_function2() {}
``` ```
```v nofmt ```v nofmt
// This function's calls will be inlined. // This function's calls will be inlined.
[inline] @[inline]
fn inlined_function() { fn inlined_function() {
} }
// This function's calls will NOT be inlined. // This function's calls will NOT be inlined.
[noinline] @[noinline]
fn function() { fn function() {
} }
@ -5434,7 +5434,7 @@ fn function() {
// just like exit/1 or panic/1. Such functions can not // just like exit/1 or panic/1. Such functions can not
// have return types, and should end either in for{}, or // have return types, and should end either in for{}, or
// by calling other `[noreturn]` functions. // by calling other `[noreturn]` functions.
[noreturn] @[noreturn]
fn forever() { fn forever() {
for {} for {}
} }
@ -5442,13 +5442,13 @@ fn forever() {
// The following struct must be allocated on the heap. Therefore, it can only be used as a // The following struct must be allocated on the heap. Therefore, it can only be used as a
// reference (`&Window`) or inside another reference (`&OuterStruct{ Window{...} }`). // reference (`&Window`) or inside another reference (`&OuterStruct{ Window{...} }`).
// See section "Stack and Heap" // See section "Stack and Heap"
[heap] @[heap]
struct Window { struct Window {
} }
// V will not generate this function and all its calls if the provided flag is false. // V will not generate this function and all its calls if the provided flag is false.
// To use a flag, use `v -d flag` // To use a flag, use `v -d flag`
[if debug] @[if debug]
fn foo() { fn foo() {
} }
@ -5458,7 +5458,7 @@ fn bar() {
// The memory pointed to by the pointer arguments of this function will not be // The memory pointed to by the pointer arguments of this function will not be
// freed by the garbage collector (if in use) before the function returns // freed by the garbage collector (if in use) before the function returns
[keep_args_alive] @[keep_args_alive]
fn C.my_external_function(voidptr, int, voidptr) int fn C.my_external_function(voidptr, int, voidptr) int
// Calls to following function must be in unsafe{} blocks. // Calls to following function must be in unsafe{} blocks.
@ -5467,7 +5467,7 @@ fn C.my_external_function(voidptr, int, voidptr) int
// This is useful, when you want to have an `[unsafe]` function that // This is useful, when you want to have an `[unsafe]` function that
// has checks before/after a certain unsafe operation, that will still // has checks before/after a certain unsafe operation, that will still
// benefit from V's safety features. // benefit from V's safety features.
[unsafe] @[unsafe]
fn risky_business() { fn risky_business() {
// code that will be checked, perhaps checking pre conditions // code that will be checked, perhaps checking pre conditions
unsafe { unsafe {
@ -5483,22 +5483,22 @@ fn risky_business() {
// V's autofree engine will not take care of memory management in this function. // V's autofree engine will not take care of memory management in this function.
// You will have the responsibility to free memory manually yourself in it. // You will have the responsibility to free memory manually yourself in it.
[manualfree] @[manualfree]
fn custom_allocations() { fn custom_allocations() {
} }
// For C interop only, tells V that the following struct is defined with `typedef struct` in C // For C interop only, tells V that the following struct is defined with `typedef struct` in C
[typedef] @[typedef]
pub struct C.Foo { pub struct C.Foo {
} }
// Used to add a custom calling convention to a function, available calling convention: stdcall, fastcall and cdecl. // Used to add a custom calling convention to a function, available calling convention: stdcall, fastcall and cdecl.
// This list also applies for type aliases (see below). // This list also applies for type aliases (see below).
[callconv: "stdcall"] @[callconv: "stdcall"]
fn C.DefWindowProc(hwnd int, msg int, lparam int, wparam int) fn C.DefWindowProc(hwnd int, msg int, lparam int, wparam int)
// Used to add a custom calling convention to a function type aliases. // Used to add a custom calling convention to a function type aliases.
[callconv: "fastcall"] @[callconv: "fastcall"]
type FastFn = fn (int) bool type FastFn = fn (int) bool
// Windows only: // Windows only:
@ -5508,7 +5508,7 @@ type FastFn = fn (int) bool
// (e)println output can be seen. // (e)println output can be seen.
// Use it to force-open a terminal to view output in, even if the app is started from Explorer. // Use it to force-open a terminal to view output in, even if the app is started from Explorer.
// Valid before main() only. // Valid before main() only.
[console] @[console]
fn main() { fn main() {
} }
``` ```
@ -6776,7 +6776,7 @@ For example, `fn foo() {}` in module `bar` will result in `bar__foo()`.
To use a custom export name, use the `[export]` attribute: To use a custom export name, use the `[export]` attribute:
``` ```
[export: 'my_custom_c_name'] @[export: 'my_custom_c_name']
fn foo() { fn foo() {
} }
``` ```
@ -6902,7 +6902,7 @@ module main
import time import time
[live] @[live]
fn print_message() { fn print_message() {
println('Hello! Modify this message while the program is running.') println('Hello! Modify this message while the program is running.')
} }

View File

@ -140,7 +140,7 @@ fn new_app() &App {
return app return app
} }
['/'; get] @['/'; get]
pub fn (mut app App) controller_get_all_task() vweb.Result { pub fn (mut app App) controller_get_all_task() vweb.Result {
file := os.read_file('./index.html') or { panic(err) } file := os.read_file('./index.html') or { panic(err) }
return app.html(file) return app.html(file)

View File

@ -142,7 +142,7 @@ fn new_app() &App {
return app return app
} }
['/'; get] @['/'; get]
pub fn (mut app App) controller_get_all_task() vweb.Result { pub fn (mut app App) controller_get_all_task() vweb.Result {
file := os.read_file('./index.html') or { panic(err) } file := os.read_file('./index.html') or { panic(err) }
return app.html(file) return app.html(file)

View File

@ -54,7 +54,7 @@ exit
In `v_vweb_orm/src/main.v`, create a route that returns a `Response` struct. In `v_vweb_orm/src/main.v`, create a route that returns a `Response` struct.
```v ignore ```v ignore
['/sqlite-memory/:count'] @['/sqlite-memory/:count']
pub fn (mut app App) sqlite_memory(count int) vweb.Result { pub fn (mut app App) sqlite_memory(count int) vweb.Result {
mut insert_stopwatchs := []int{} mut insert_stopwatchs := []int{}
mut select_stopwatchs := []int{} mut select_stopwatchs := []int{}

View File

@ -19,7 +19,7 @@ In `examples/js_dom_draw_bechmark_chart/v_vweb_orm/src/main.v` path
Create a route returning a `Response` struct like: Create a route returning a `Response` struct like:
```v ignore ```v ignore
['/sqlite-memory/:count'] @['/sqlite-memory/:count']
pub fn (mut app App) sqlite_memory(count int) vweb.Result { pub fn (mut app App) sqlite_memory(count int) vweb.Result {
mut insert_stopwatchs := []int{} mut insert_stopwatchs := []int{}
mut select_stopwatchs := []int{} mut select_stopwatchs := []int{}

View File

@ -49,7 +49,7 @@ It will create `primes.v` with the following contents:
```v ```v
[translated] @[translated]
module main module main
fn is_prime(x int) bool { fn is_prime(x int) bool {

View File

@ -69,7 +69,7 @@ fn main() {
vweb.run(app, 8081) vweb.run(app, 8081)
} }
['/index'] @['/index']
pub fn (mut app App) index() vweb.Result { pub fn (mut app App) index() vweb.Result {
return app.text('Hello world from vweb!') return app.text('Hello world from vweb!')
} }
@ -336,7 +336,7 @@ Create `new.html`:
// article.v // article.v
import vweb import vweb
[post] @[post]
pub fn (mut app App) new_article(title string, text string) vweb.Result { pub fn (mut app App) new_article(title string, text string) vweb.Result {
if title == '' || text == '' { if title == '' || text == '' {
return app.text('Empty text/title') return app.text('Empty text/title')
@ -368,7 +368,7 @@ We need to update `index.html` to add a link to the "new article" page:
Next we need to add the HTML endpoint to our code like we did with `index.html`: Next we need to add the HTML endpoint to our code like we did with `index.html`:
```v ignore ```v ignore
['/new'] @['/new']
pub fn (mut app App) new() vweb.Result { pub fn (mut app App) new() vweb.Result {
return $vweb.html() return $vweb.html()
} }
@ -386,7 +386,7 @@ in V is very simple:
// article.v // article.v
import vweb import vweb
['/articles'; get] @['/articles'; get]
pub fn (mut app App) articles() vweb.Result { pub fn (mut app App) articles() vweb.Result {
articles := app.find_all_articles() articles := app.find_all_articles()
return app.json(articles) return app.json(articles)

View File

@ -30,7 +30,7 @@ non-option fields are defied as NOT NULL when creating tables.
```v ignore ```v ignore
import time import time
[table: 'foos'] @[table: 'foos']
struct Foo { struct Foo {
id int [primary; sql: serial] id int [primary; sql: serial]
name string name string

View File

@ -21,7 +21,7 @@ const (
sw_start_ms = sw.elapsed().milliseconds() sw_start_ms = sw.elapsed().milliseconds()
) )
[inline] @[inline]
fn sintone(periods int, frame int, num_frames int) f32 { fn sintone(periods int, frame int, num_frames int) f32 {
return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames)) return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames))
} }

View File

@ -1,4 +1,4 @@
[params] @[params]
struct Bar { struct Bar {
bar bool bar bool
} }

View File

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