forked from dbenque/labkube
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
38 lines (34 loc) · 1.07 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
log.Printf("request on URI /ready")
if _, err := os.Stat("/ready"); os.IsNotExist(err) {
w.WriteHeader(500)
log.Printf("--> readiness probe failed")
return
}
w.WriteHeader(200)
})
r.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
log.Printf("request on URI /hello")
fmt.Fprintf(w, "Hello I am pod %s\nWelcome to kubernetes lab.\n", os.Getenv("HOSTNAME"))
})
r.HandleFunc("/env", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%v", os.Environ())
})
r.HandleFunc("/mydeployment", func(w http.ResponseWriter, r *http.Request) {
log.Printf("request on URI /hello")
fmt.Fprintf(w, "Hello I am pod %s\nWelcome to kubernetes lab.\n", os.Getenv("HOSTNAME"))
fmt.Fprintf(w, "MY_DEPLOYMENT environment variable is set to: %s\n", os.Getenv("MY_DEPLOYMENT"))
})
log.Printf("Server listening on port 8080...")
http.ListenAndServe(":8080", r)
}