-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package courier | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Determines if the server is healthy or not. | ||
func (s *Server) IsHealthy() bool { | ||
s.RLock() | ||
defer s.RUnlock() | ||
return s.healthy | ||
} | ||
|
||
// Determines if the server is ready or not. | ||
func (s *Server) IsReady() bool { | ||
s.RLock() | ||
defer s.RUnlock() | ||
return s.ready | ||
} | ||
|
||
// Set the server health state to the status bool. | ||
func (s *Server) SetHealthy(status bool) { | ||
s.Lock() | ||
defer s.Unlock() | ||
s.healthy = status | ||
} | ||
|
||
// Set the server ready state to the status bool. | ||
func (s *Server) SetReady(status bool) { | ||
s.Lock() | ||
defer s.Unlock() | ||
s.ready = status | ||
} | ||
|
||
func (s *Server) Healthz(c *gin.Context) { | ||
status := http.StatusOK | ||
if !s.IsHealthy() { | ||
status = http.StatusServiceUnavailable | ||
} | ||
c.Data(status, "text/plain", []byte(http.StatusText(status))) | ||
} | ||
|
||
func (s *Server) Readyz(c *gin.Context) { | ||
status := http.StatusOK | ||
if !s.IsReady() { | ||
status = http.StatusServiceUnavailable | ||
} | ||
c.Data(status, "text/plain", []byte(http.StatusText(status))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters