77)
88
99var (
10- version = "1.3-liveness"
1110 bannedIp = "0.0.0.0"
1211)
1312
@@ -20,42 +19,52 @@ func getServerIP() string {
2019 return conn .LocalAddr ().(* net.UDPAddr ).IP .String ()
2120}
2221
22+ func getHTML (image string ) string {
23+ message := "Customer Support, Mr. Cat speaking, how can I help you?"
24+ color := "orange"
25+ if image == "1.3.1" {
26+ message = "High five budy, I'm healthy as ever!"
27+ color = "green"
28+ }
29+ if image == "1.3.2" {
30+ message = "I don't want to die Mr. Stark ( x_x ) ..."
31+ color = "red"
32+ }
33+ return `<!DOCTYPE html><html><body><center>
34+ <img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/master/src` + image + `.png">
35+ <h1 style="color:` + color + `">` + message + `</h3>
36+ <h2 style="color:green">Playing with Kubernetes</h1>
37+ <h2 style="color:blue">Server IP ` + getServerIP () + `</h2>
38+ <h3 style="color:blue">Version twogghub/k8s-workshop:1.3-liveness</h3>
39+ </center></body></html>`
40+ }
41+
2342func playHome (w http.ResponseWriter , r * http.Request ) {
24- status := "Customer Support, Mr. Cat speaking, how can I help you?"
25- img := "1.3.0"
26- if bannedIp == getServerIP () {
27- status = "I don't want to die Mr. Stark ( x_x ) ..."
28- img = "1.3.1"
43+ if getServerIP () == bannedIp {
44+ fmt .Fprintf (w , getHTML ("1.3.2" ))
45+ } else {
46+ fmt .Fprintf (w , getHTML ("1.3.0" ))
2947 }
30- html := `<!DOCTYPE html><html><body><center>
31- <img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/master/src/` + img + `.png">
32- <h1 style="color:green">Playing with Kubernetes</h1>
33- <h2 style="color:blue">Server IP ` + getServerIP () + `</h2>
34- <h3 style="color:blue">Version twogghub/k8s-workshop:` + version + `</h3>
35- <h3 style="color:red">` + status + `</h3>
36- </center></body></html>`
37- fmt .Fprintf (w , html )
3848}
3949
4050func playHealth (w http.ResponseWriter , r * http.Request ) {
41- ip := getServerIP ()
42- if ip == bannedIp {
51+ if getServerIP () == bannedIp {
4352 w .WriteHeader (http .StatusServiceUnavailable )
4453 } else {
45- fmt .Fprintf (w , "I'm alive!.. but also dead for IP: " + bannedIp )
54+ fmt .Fprintf (w , getHTML ( "1.3.1" ) )
4655 }
4756}
4857
49- func playDead (w http.ResponseWriter , r * http.Request ) {
50- bannedIp = r . URL . Query (). Get ( "ip" )
51- fmt .Fprintf (w , "Now playing dead for IP: " + bannedIp )
58+ func playKillMe (w http.ResponseWriter , r * http.Request ) {
59+ bannedIp = getServerIP ( )
60+ fmt .Fprintf (w , getHTML ( "1.3.2" ) )
5261}
5362
5463func main () {
5564 http .HandleFunc ("/" , playHome )
5665 http .HandleFunc ("/health" , playHealth )
57- http .HandleFunc ("/kill " , playDead )
58- if err := http .ListenAndServe (":9090 " , nil ); err != nil {
66+ http .HandleFunc ("/killme " , playKillMe )
67+ if err := http .ListenAndServe (":8080 " , nil ); err != nil {
5968 panic (err )
6069 }
6170}
0 commit comments