github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/server/health.go (about) 1 package server 2 3 import ( 4 "fmt" 5 "net/http" 6 "os" 7 "time" 8 9 "github.com/isyscore/isc-gobase/config" 10 11 "github.com/gin-gonic/gin" 12 h2 "github.com/isyscore/isc-gobase/http" 13 t2 "github.com/isyscore/isc-gobase/time" 14 ) 15 16 var procId = os.Getpid() 17 var startTime = time.Now().Format(t2.FmtYMdHms) 18 19 const defaultVersion = "unknown" 20 21 func healthSystemStatus(c *gin.Context) { 22 c.Data(http.StatusOK, h2.ContentTypeJson, []byte(fmt.Sprintf(`{"status":"ok","running":true,"pid":%d,"startupAt":"%s","version":"%s"}`, procId, startTime, getVersion()))) 23 } 24 25 func healthSystemInit(c *gin.Context) { 26 c.Data(http.StatusOK, h2.ContentTypeText, []byte(`{"status":"ok"}`)) 27 } 28 29 func healthSystemDestroy(c *gin.Context) { 30 c.Data(http.StatusOK, h2.ContentTypeText, []byte(`{"status":"ok"}`)) 31 } 32 33 func getVersion() string { 34 return config.GetValueStringDefault("base.server.version", defaultVersion) 35 }