|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "os" |
| 7 | +) |
| 8 | + |
| 9 | +type configurationListHandler struct { |
| 10 | + version string |
| 11 | + environment string |
| 12 | + environment_type string |
| 13 | + region string |
| 14 | + paypal_url string |
| 15 | + db_user string |
| 16 | + db_password string |
| 17 | + gpu_enabled string |
| 18 | + ui_theme string |
| 19 | + cache_size string |
| 20 | + page_limit string |
| 21 | + sorting string |
| 22 | + number_of_buckets string |
| 23 | +} |
| 24 | + |
| 25 | +func (h *configurationListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 26 | + w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 27 | + fmt.Fprintf(w, "<h2>I am a GO application running inside Kubernetes.<h2> <h3>My properties are:</h3><ul>") |
| 28 | + fmt.Fprintf(w, "<li>version: "+h.version+"</li>") |
| 29 | + fmt.Fprintf(w, "<li>environment: "+h.environment+"</li>") |
| 30 | + fmt.Fprintf(w, "<li>environment_type: "+h.environment_type+"</li>") |
| 31 | + fmt.Fprintf(w, "<li>region: "+h.region+"</li>") |
| 32 | + fmt.Fprintf(w, "<li>paypal_url: "+h.paypal_url+"</li>") |
| 33 | + fmt.Fprintf(w, "<li>db_user: "+h.db_user+"</li>") |
| 34 | + fmt.Fprintf(w, "<li>db_password: "+h.db_password+"</li>") |
| 35 | + fmt.Fprintf(w, "<li>gpu_enabled: "+h.gpu_enabled+"</li>") |
| 36 | + fmt.Fprintf(w, "<li>ui_theme: "+h.ui_theme+"</li>") |
| 37 | + fmt.Fprintf(w, "<li>cache_size: "+h.cache_size+"</li>") |
| 38 | + fmt.Fprintf(w, "<li>page_limit: "+h.page_limit+"</li>") |
| 39 | + fmt.Fprintf(w, "<li>sorting: "+h.sorting+"</li>") |
| 40 | + fmt.Fprintf(w, "<li>number_of_buckets: "+h.number_of_buckets+"</li>") |
| 41 | + fmt.Fprintf(w, "</ol>") |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +func healthHandler(w http.ResponseWriter, r *http.Request) { |
| 46 | + fmt.Fprintf(w, "OK\n") |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +func main() { |
| 51 | + |
| 52 | + clh := configurationListHandler{} |
| 53 | + clh.version = "3.0" |
| 54 | + clh.environment = os.Getenv("ENV") |
| 55 | + clh.environment_type = os.Getenv("ENV_TYPE") |
| 56 | + clh.region = os.Getenv("REGION") |
| 57 | + clh.paypal_url = os.Getenv("PAYPAL_URL") |
| 58 | + clh.db_user = os.Getenv("DB_USER") |
| 59 | + clh.db_password = os.Getenv("DB_PASSWORD") |
| 60 | + clh.gpu_enabled = os.Getenv("GPU_ENABLED") |
| 61 | + clh.ui_theme = os.Getenv("UI_THEME") |
| 62 | + clh.cache_size = os.Getenv("CACHE_SIZE") |
| 63 | + clh.page_limit = os.Getenv("PAGE_LIMIT") |
| 64 | + clh.sorting = os.Getenv("SORTING") |
| 65 | + clh.number_of_buckets = os.Getenv("N_BUCKETS") |
| 66 | + |
| 67 | + fmt.Println("Simple web server is starting on port 8080...") |
| 68 | + http.Handle("/", &clh) |
| 69 | + http.HandleFunc("/health", healthHandler) |
| 70 | + err := http.ListenAndServe(":8080", nil) |
| 71 | + if err != nil { |
| 72 | + fmt.Printf("Failed to start server at port 8080: %v", err) |
| 73 | + } |
| 74 | +} |
0 commit comments