-
Notifications
You must be signed in to change notification settings - Fork 22
/
simple-web-server.go
74 lines (65 loc) · 2.31 KB
/
simple-web-server.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"net/http"
"os"
)
type configurationListHandler struct {
version string
environment string
environment_type string
region string
paypal_url string
db_user string
db_password string
gpu_enabled string
ui_theme string
cache_size string
page_limit string
sorting string
number_of_buckets string
}
func (h *configurationListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, "<h2>I am a GO application running inside Kubernetes.<h2> <h3>My properties are:</h3><ul>")
fmt.Fprintf(w, "<li>version: "+h.version+"</li>")
fmt.Fprintf(w, "<li>environment: "+h.environment+"</li>")
fmt.Fprintf(w, "<li>environment_type: "+h.environment_type+"</li>")
fmt.Fprintf(w, "<li>region: "+h.region+"</li>")
fmt.Fprintf(w, "<li>paypal_url: "+h.paypal_url+"</li>")
fmt.Fprintf(w, "<li>db_user: "+h.db_user+"</li>")
fmt.Fprintf(w, "<li>db_password: "+h.db_password+"</li>")
fmt.Fprintf(w, "<li>gpu_enabled: "+h.gpu_enabled+"</li>")
fmt.Fprintf(w, "<li>ui_theme: "+h.ui_theme+"</li>")
fmt.Fprintf(w, "<li>cache_size: "+h.cache_size+"</li>")
fmt.Fprintf(w, "<li>page_limit: "+h.page_limit+"</li>")
fmt.Fprintf(w, "<li>sorting: "+h.sorting+"</li>")
fmt.Fprintf(w, "<li>number_of_buckets: "+h.number_of_buckets+"</li>")
fmt.Fprintf(w, "</ol>")
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK\n")
}
func main() {
clh := configurationListHandler{}
clh.version = "3.0"
clh.environment = os.Getenv("ENV")
clh.environment_type = os.Getenv("ENV_TYPE")
clh.region = os.Getenv("REGION")
clh.paypal_url = os.Getenv("PAYPAL_URL")
clh.db_user = os.Getenv("DB_USER")
clh.db_password = os.Getenv("DB_PASSWORD")
clh.gpu_enabled = os.Getenv("GPU_ENABLED")
clh.ui_theme = os.Getenv("UI_THEME")
clh.cache_size = os.Getenv("CACHE_SIZE")
clh.page_limit = os.Getenv("PAGE_LIMIT")
clh.sorting = os.Getenv("SORTING")
clh.number_of_buckets = os.Getenv("N_BUCKETS")
fmt.Println("Simple web server is starting on port 8080...")
http.Handle("/", &clh)
http.HandleFunc("/health", healthHandler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
fmt.Printf("Failed to start server at port 8080: %v", err)
}
}