38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// Read from the environment, not baked in at build time — the Helm
|
|
// chart's deployment.env sets APP_VERSION from the same image tag
|
|
// updateHelmTag.groovy just bumped, so curling /version proves the
|
|
// whole CI/CD loop (build -> push -> tag-bump -> deploy) actually
|
|
// worked end to end, not just that "some" image is running.
|
|
version := os.Getenv("APP_VERSION")
|
|
if version == "" {
|
|
version = "dev"
|
|
}
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "hello from demo-go-app, version %s\n", version)
|
|
})
|
|
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
fmt.Fprintln(w, "ok")
|
|
})
|
|
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintln(w, version)
|
|
})
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
log.Printf("listening on :%s (version %s)", port, version)
|
|
log.Fatal(http.ListenAndServe(":"+port, nil))
|
|
}
|