This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
pages.go
67 lines (57 loc) · 1.86 KB
/
pages.go
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
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
"github.com/gorilla/mux"
)
func homeHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("Hello World from the Home page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func loginHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("Login page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func logoutHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("Login page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func productsHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("Products page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func productHandler(w http.ResponseWriter, r *http.Request) {
rVars := mux.Vars(r)
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = fmt.Fprintf(w, "Product %s page", rVars["productID"])
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func basketHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("Basket page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}
func aboutHandler(w http.ResponseWriter, r *http.Request) {
_ = r
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("About page"))
time.Sleep(time.Duration(50+rand.Intn(100)) * time.Millisecond)
}