-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (45 loc) · 1.41 KB
/
main.go
File metadata and controls
54 lines (45 loc) · 1.41 KB
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
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/__version__", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Read version.json file
versionFile, err := os.Open("/app/version.json")
if err != nil {
http.Error(w, "Failed to read version.json", http.StatusInternalServerError)
log.Println("Error reading version.json:", err)
return
}
defer versionFile.Close()
// Read the content of the file
data, err := io.ReadAll(versionFile)
if err != nil {
http.Error(w, "Failed to read version.json content", http.StatusInternalServerError)
log.Println("Error reading version.json content:", err)
return
}
// Write the content to the response
w.Write(data)
})
http.HandleFunc("/__lbheartbeat__", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
})
http.HandleFunc("/__heartbeat__", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Welcome to the cicd demo go web app! Visit /__version__ for version information. Adding test string here"))
})
port := "8000"
println("Server running on port:", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Println("Error starting server:", err)
}
}