🔧 Update to latest version of V

This commit is contained in:
Edgar 2025-01-21 10:21:18 +01:00
parent 81786f6b27
commit c8ff20a80c
No known key found for this signature in database
GPG Key ID: 3C2E1F2C1C353131
2 changed files with 6 additions and 8 deletions

View File

@ -5,9 +5,9 @@ export default function () {
for (let i = 0; i < 250; i++) {
var rand = Math.random()
if (rand > 0.5) {
http.get(`http://127.0.0.1:8082/get/${random_string(1)}`);
http.get(`http://127.0.0.1:8082/get/${random_string(5)}`);
} else {
http.post(`http://127.0.0.1:8082/set/${random_string(1)}`, random_string(5));
http.put(`http://127.0.0.1:8082/set/${random_string(5)}`, random_string(5));
}
}
};

View File

@ -2,9 +2,7 @@ module main
import vweb
const (
port = 8082
)
const port = 8082
struct App {
vweb.Context
@ -23,10 +21,10 @@ fn main() {
lock app.state {
app.state.kv_store = {}
}
vweb.run_at(app, family: .ip, host: 'localhost', port: port)?
vweb.run_at(app, family: .ip, host: 'localhost', port: port)!
}
['/get/:key']
@['/get/:key']
pub fn (mut app App) kv_get(key string) vweb.Result {
lock app.state {
res := app.state.kv_store[key] or { return app.not_found() }
@ -35,7 +33,7 @@ pub fn (mut app App) kv_get(key string) vweb.Result {
return app.not_found()
}
['/set/:key'; put]
@['/set/:key'; put]
fn (mut app App) kv_set(key string) vweb.Result {
lock app.state {
app.state.kv_store[key] = app.req.data