-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
70 lines (67 loc) · 2.07 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!-- public/index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gin API Example</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
button {
margin-left: .5rem;
right: .5rem;
display: inline-block;
outline: 0;
cursor: pointer;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
vertical-align: middle;
border: 1px solid;
border-radius: 6px;
color: #ffffff;
background-color: #2ea44f;
border-color: #1b1f2326;
box-shadow: rgba(27, 31, 35, 0.04) 0px 1px 0px 0px, rgba(255, 255, 255, 0.25) 0px 1px 0px 0px inset;
transition: 0.2s cubic-bezier(0.3, 0, 0.5, 1);
transition-property: color, background-color, border-color;
}
button:hover {
background-color: #2c974b;
border-color: #1b1f2326;
transition-duration: 0.1s;
}
</style>
</head>
<body>
<button onclick="getProducts('normal')">Get Products</button>
<button onclick="getProducts('new')">Get Products | New</button>
<button onclick="getProducts('pooled')">Get Products | Connection Pool</button>
<script>
function getProducts(mode) {
let lastResult = null;
const promises = [];
for (let i = 0; i < 200; i++) {
promises.push(
fetch(`/products/${mode}`)
.then(response => response.json())
.then(({elapsed, average, products}) => {
lastResult = {elapsed, average};
console.log({elapsed, average});
})
);
}
Promise.all(promises)
.then(() => {
console.log(`Last result for ${mode}:`, lastResult);
})
.catch(error => console.error(error));
}
</script>
</body>
</html>