stupid-kv/stupid-kv - Copy.v
2022-03-07 17:57:52 +01:00

42 lines
600 B
V

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')
}