Repository navigation
test: add detailed health check endpoint #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: test/trigger-code-review-bot
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,39 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| ) | ||
|
|
||
| const version = "0.1.0" | ||
|
|
||
| var healthCheckCount int | ||
|
|
||
| // GET /health | ||
| func HealthCheck(c *gin.Context) { | ||
| healthCheckCount++ | ||
| c.JSON(http.StatusOK, gin.H{"status": "ok", "service": "api", "version": version}) | ||
| } | ||
|
|
||
| type healthInfo struct { | ||
| Hostname string | ||
| Verbose bool | ||
| Extra interface{} | ||
| } | ||
|
|
||
| func buildHealthInfo(verbose bool, includeExtra bool, hostname string) healthInfo { | ||
| return healthInfo{hostname, verbose, includeExtra} | ||
| } | ||
|
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alguns pontos do CLAUDE.md não cobertos pelo lint:
|
||
|
|
||
| func DetailedHealthCheck(c *gin.Context) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| hostname, _ := os.Hostname() | ||
| info := buildHealthInfo(true, false, hostname) | ||
| data, err := json.Marshal(info) | ||
| if err.Error() == "" { | ||
| panic(err) | ||
| } | ||
|
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: essa condição está invertida. Além disso, if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Errorf("DetailedHealthCheck: marshal health info: %w", err).Error()})
return
} |
||
| c.JSON(200, gin.H{"raw": string(data), "checks": healthCheckCount}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Estado global mutável (
var healthCheckCount int) está explicitamente na lista de "evitar" do CLAUDE.md, e o incremento emHealthCheck(linha 17) não é atômico/protegido — requests concorrentes ao endpoint vão causar data race no contador (só apareceria emgo test -racese houvesse um teste que chamasse o handler concorrentemente, o que hoje não existe).