-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (51 loc) · 1.47 KB
/
main.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
package main
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
)
func main() {
printvar := os.Getenv("HWC_PRINTVAR")
if printvar == "true" {
for _, v := range os.Environ() {
fmt.Printf("%s \n", v)
}
}
timedKill := os.Getenv("HWC_TIMEDKILL")
sleepTimer, _ := strconv.Atoi(os.Getenv("HWC_SLEEPTIMER"))
exitcode, _ := strconv.Atoi(os.Getenv("HWC_EXITCODE"))
if timedKill == "true" {
fmt.Printf("This service will be killed in %d seconds \n", sleepTimer)
time.Sleep(time.Duration(sleepTimer) * time.Second)
os.Exit(exitcode)
}
counter := 0
// increments sleeptimer, starting from HWC_SLEEPTIMEr
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello for the %d time \n", counter)
fmt.Printf("Hello for the %d time \n", counter)
counter++
})
// Prints environment variables
http.HandleFunc("/env", func(w http.ResponseWriter, r *http.Request) {
for _, v := range os.Environ() {
fmt.Fprintf(w, "%s \n", v)
fmt.Printf("%s \n", v)
}
})
// Kills the service
http.HandleFunc("/kill", func(w http.ResponseWriter, r *http.Request) {
os.Exit(exitcode)
})
// Kills the service after 60 sec
http.HandleFunc("/timedkill", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "This service will be killed in 60 seconds \n")
fmt.Printf("This service will be killed in 60 seconds \n")
time.Sleep(time.Duration(sleepTimer) * time.Second)
os.Exit(exitcode)
})
log.Fatal(http.ListenAndServe(":80", nil))
}