-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (41 loc) · 838 Bytes
/
main.go
File metadata and controls
47 lines (41 loc) · 838 Bytes
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
package main
import (
"log"
"net/http"
"runtime"
"time"
)
func load(response http.ResponseWriter, _ *http.Request) {
done := make(chan int)
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
for {
select {
case <-done:
return
default:
}
}
}()
}
time.Sleep(time.Second * 10)
close(done)
_, err := response.Write([]byte("Load generation done."))
if err != nil {
log.Printf("failed to write response (%v)", err)
}
}
func health(response http.ResponseWriter, _ *http.Request) {
_, err := response.Write([]byte("OK"))
if err != nil {
log.Printf("failed to write response (%v)", err)
}
}
func main() {
http.HandleFunc("/health", health)
http.HandleFunc("/load", load)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("failed to launch webserver (%v)", err)
}
}