@@ -2,57 +2,20 @@ package main
22
33import (
44 "fmt"
5- "net"
65 "net/http"
76)
87
9- var (
10- version = "1.0"
11- bannedIp = "0.0.0.0"
12- )
13-
14- func getServerIP () string {
15- conn , err := net .Dial ("udp" , "8.8.8.8:80" )
16- if err != nil {
17- panic (err )
18- }
19- defer conn .Close ()
20- return conn .LocalAddr ().(* net.UDPAddr ).IP .String ()
21- }
22-
238func playHome (w http.ResponseWriter , r * http.Request ) {
249 html := `<!DOCTYPE html><html><body><center>
25- <img src="https://raw.githubusercontent.com/twogg-git/k8s-intro /master/kubernetes_katacoda .png">
10+ <img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop /master/src/1.0 .png">
2611 <h1 style="color:green">Playing with Kubernetes</h1>
27- <h2 style="color:blue">Your server IP:` + getServerIP () + `</h2>
28- <h3 style="color:blue">Version: twogghub/k8s-workshop:` + version + `</h3>
29- <h3 style="color:red">Banned IP: ` + bannedIp + `</h3>
12+ <h3 style="color:blue">Version: twogghub/k8s-workshop:1.0-baby</h3>
3013 </center></body></html>`
3114 fmt .Fprintf (w , html )
3215}
3316
34- func playHealth (w http.ResponseWriter , r * http.Request ) {
35- ip := getServerIP ()
36- if ip == bannedIp {
37- w .WriteHeader (http .StatusInternalServerError )
38- } else {
39- fmt .Fprintf (w , "I'm alive!.. but also dead for IP: " + bannedIp )
40- }
41- }
42-
43- func playDead (w http.ResponseWriter , r * http.Request ) {
44- bannedIp = r .URL .Query ().Get ("ip" )
45- fmt .Fprintf (w , "Now playing dead for IP: " + bannedIp )
46- }
47-
48- /*func getBannedIP() string {
49- return bannedIp
50- }*/
51-
5217func main () {
5318 http .HandleFunc ("/" , playHome )
54- http .HandleFunc ("/health" , playHealth )
55- http .HandleFunc ("/kill" , playDead )
5619 if err := http .ListenAndServe (":8080" , nil ); err != nil {
5720 panic (err )
5821 }
0 commit comments