🎉 First commit
This commit is contained in:
commit
23a0c77d56
24
load-test.js
Normal file
24
load-test.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import http from "k6/http";
|
||||||
|
import { sleep } from 'k6';
|
||||||
|
|
||||||
|
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:8080/get/${random_string(1)}`);
|
||||||
|
} else {
|
||||||
|
http.post(`http://127.0.0.1:8080/set/${random_string(1)}`, random_string(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function random_string(length) {
|
||||||
|
var result = '';
|
||||||
|
var characters = 'abcdefghijklmnopqrstuvwxyz';
|
||||||
|
var charactersLength = characters.length;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
5
load-test2.js
Normal file
5
load-test2.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import http from "k6/http";
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
http.get(`http://localhost:8082/`);
|
||||||
|
};
|
41
stupid-kv - Copy.v
Normal file
41
stupid-kv - Copy.v
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = 8082
|
||||||
|
)
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
vweb.Context
|
||||||
|
mut:
|
||||||
|
state shared State
|
||||||
|
}
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
mut:
|
||||||
|
kv_store map[string]string = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut app := &App{}
|
||||||
|
println('stupid kvstore')
|
||||||
|
vweb.run(app, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
['/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() }
|
||||||
|
return app.ok(res)
|
||||||
|
}
|
||||||
|
return app.not_found()
|
||||||
|
}
|
||||||
|
|
||||||
|
['/set/:key'; post]
|
||||||
|
fn (mut app App) kv_set(key string) vweb.Result {
|
||||||
|
lock app.state {
|
||||||
|
app.state.kv_store[key] = app.req.data
|
||||||
|
}
|
||||||
|
return app.text('OK')
|
||||||
|
}
|
59
stupid-kv.v
Normal file
59
stupid-kv.v
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
import json
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = 8080
|
||||||
|
)
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
vweb.Context
|
||||||
|
mut:
|
||||||
|
state shared State
|
||||||
|
}
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
mut:
|
||||||
|
kv_store string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut app := &App{}
|
||||||
|
println('stupid kvstore')
|
||||||
|
lock app.state {
|
||||||
|
app.state.kv_store = '{}'
|
||||||
|
}
|
||||||
|
//vweb.run(app, port)
|
||||||
|
vweb.run_at(app, family: .ip, host: 'localhost', port: port) ?
|
||||||
|
}
|
||||||
|
|
||||||
|
['/get/:key']
|
||||||
|
pub fn (mut app App) kv_get(key string) vweb.Result {
|
||||||
|
lock app.state {
|
||||||
|
// data := json.decode(map[string]string, app.state.kv_store) or {
|
||||||
|
// return app.server_error(500)
|
||||||
|
// }
|
||||||
|
// if key in data {
|
||||||
|
// r := data[key]
|
||||||
|
// return app.ok(r)
|
||||||
|
// } else {
|
||||||
|
// return app.not_found()
|
||||||
|
// }
|
||||||
|
|
||||||
|
return app.ok(app.state.kv_store)
|
||||||
|
}
|
||||||
|
return app.server_error(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
['/set/:key'; post]
|
||||||
|
fn (mut app App) kv_set(key string) vweb.Result {
|
||||||
|
lock app.state {
|
||||||
|
// mut data := json.decode(map[string]string, app.state.kv_store) or {
|
||||||
|
// return app.server_error(500)
|
||||||
|
// }
|
||||||
|
// data[key] = app.req.data
|
||||||
|
app.state.kv_store = app.req.data//json.encode(data)
|
||||||
|
}
|
||||||
|
return app.text('OK')
|
||||||
|
}
|
17
vweb_example.v
Normal file
17
vweb_example.v
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
vweb.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut app := &App{}
|
||||||
|
vweb.run_at(app, family: .ip, host: 'localhost', port: 8082) ?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut app App) index() vweb.Result {
|
||||||
|
return app.text('World')
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user