no more omit
This commit is contained in:
0
src/client/css.css
Normal file
0
src/client/css.css
Normal file
10
src/client/index.html
Normal file
10
src/client/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
|
||||
<link rel="stylesheet" href="css.css">
|
||||
<script src="js.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, world</h1>
|
||||
</body>
|
||||
</html>
|
||||
107
src/client/js.js
Normal file
107
src/client/js.js
Normal file
@@ -0,0 +1,107 @@
|
||||
class DB {
|
||||
constructor() {
|
||||
if (typeof(localStorage) === "undefined") {
|
||||
throw new Error('Hmmm... no "localStorage" support');
|
||||
}
|
||||
}
|
||||
|
||||
get(key) {
|
||||
b = localStorage.getItem(key);
|
||||
if (b) {
|
||||
b = JSON.parse(b);
|
||||
} else {
|
||||
b = null;
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
b = JSON.stringify(value);
|
||||
localStorage.setItem(key, b);
|
||||
}
|
||||
|
||||
del(key) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
class Requests {
|
||||
put(remote, body, callback) {
|
||||
this.http("put", remote, callback, body);
|
||||
}
|
||||
|
||||
post(remote, body, callback) {
|
||||
this.http("post", remote, callback, body);
|
||||
}
|
||||
|
||||
get(remote, callback) {
|
||||
this.http("get", remote, callback, null);
|
||||
}
|
||||
|
||||
http(method, remote, callback, body) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
callback(xmlhttp.responseText, xmlhttp.status);
|
||||
}
|
||||
};
|
||||
xmlhttp.open(method, remote, true);
|
||||
if (typeof body == "undefined") {
|
||||
body = null;
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
}
|
||||
|
||||
class Games {
|
||||
constructor() {
|
||||
this.db = new DB();
|
||||
this.requests = new Requests();
|
||||
}
|
||||
|
||||
list(cb) {
|
||||
this.requests.get("/api/games", (text) => {
|
||||
var list = JSON.parse(text);
|
||||
cb(list);
|
||||
});
|
||||
}
|
||||
|
||||
get(id, cb) {
|
||||
this.requests.get("/api/games/"+id, (text, status) => {
|
||||
if (status != 200) {
|
||||
throw new Error("bad status getting game: "+status+": "+text);
|
||||
}
|
||||
var game = JSON.parse(text);
|
||||
cb(game);
|
||||
});
|
||||
}
|
||||
|
||||
create(id, cb) {
|
||||
this.requests.post("/api/games/"+id, null, (text, status) => {
|
||||
if (status != 200) {
|
||||
throw new Error("bad status creating game: "+status+": "+text);
|
||||
}
|
||||
var game = JSON.parse(text);
|
||||
cb(game);
|
||||
});
|
||||
}
|
||||
|
||||
update(id, game, cb) {
|
||||
this.requests.put("/api/games/"+id, JSON.stringify(game), (text, status) => {
|
||||
if (status != 200) {
|
||||
throw new Error("bad status updating game: "+status+": "+text);
|
||||
}
|
||||
var game2 = JSON.parse(text);
|
||||
cb(game2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
games = new Games()
|
||||
games.create("id", console.log);
|
||||
games.list((ids) => {
|
||||
console.log(ids);
|
||||
ids.forEach((id) => {
|
||||
games.get(id, console.log);
|
||||
});
|
||||
});
|
||||
@@ -16,10 +16,10 @@ type Game struct {
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
ID string `json:",omitempty"`
|
||||
Name string `json:",omitempty"`
|
||||
Card string `json:",omitempty"`
|
||||
Balance Currency `json:",omitempty"`
|
||||
ID string
|
||||
Name string
|
||||
Card string
|
||||
Balance Currency
|
||||
}
|
||||
|
||||
type Currency int
|
||||
|
||||
Reference in New Issue
Block a user