🔧 Update to latest version of V
This commit is contained in:
parent
81786f6b27
commit
c8ff20a80c
@ -5,9 +5,9 @@ export default function () {
|
|||||||
for (let i = 0; i < 250; i++) {
|
for (let i = 0; i < 250; i++) {
|
||||||
var rand = Math.random()
|
var rand = Math.random()
|
||||||
if (rand > 0.5) {
|
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 {
|
} 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
10
stupid-kv.v
10
stupid-kv.v
@ -2,9 +2,7 @@ module main
|
|||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
|
||||||
const (
|
const port = 8082
|
||||||
port = 8082
|
|
||||||
)
|
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
vweb.Context
|
vweb.Context
|
||||||
@ -23,10 +21,10 @@ fn main() {
|
|||||||
lock app.state {
|
lock app.state {
|
||||||
app.state.kv_store = {}
|
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 {
|
pub fn (mut app App) kv_get(key string) vweb.Result {
|
||||||
lock app.state {
|
lock app.state {
|
||||||
res := app.state.kv_store[key] or { return app.not_found() }
|
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()
|
return app.not_found()
|
||||||
}
|
}
|
||||||
|
|
||||||
['/set/:key'; put]
|
@['/set/:key'; put]
|
||||||
fn (mut app App) kv_set(key string) vweb.Result {
|
fn (mut app App) kv_set(key string) vweb.Result {
|
||||||
lock app.state {
|
lock app.state {
|
||||||
app.state.kv_store[key] = app.req.data
|
app.state.kv_store[key] = app.req.data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user