gitee.com/h79/goutils@v1.22.10/common/server/health.go (about) 1 package server 2 3 import ( 4 "gitee.com/h79/goutils/common/config" 5 "gitee.com/h79/goutils/common/json" 6 "time" 7 ) 8 9 const ( 10 GHealthTtl = 10 11 KGRpcProtocol = "grpc" 12 KHttpProtocol = "http" 13 KTCPProtocol = "tcp" 14 ) 15 16 type Health struct { 17 URL Address `json:"url"` 18 Method string `json:"method"` 19 Protocol string `json:"protocol"` 20 Ttl bool `json:"ttl"` 21 Interval time.Duration `json:"interval"` //(second) 22 SuccessStatus int `json:"successStatus"` 23 } 24 25 func ReadHealth(filename string) (Health, error) { 26 if len(filename) == 0 { 27 filename = config.FileNameInEnvPath("healthcheck.json") 28 } 29 health := Health{ 30 Ttl: true, 31 Interval: GHealthTtl} 32 err := json.Read(filename, &health) 33 return health, err 34 }