refactoring

This commit is contained in:
2020-07-10 22:29:02 +10:00
parent 94fa315dcf
commit 2cc3b341de
3 changed files with 9 additions and 1 deletions
+1
View File
@@ -1 +1,2 @@
.vscode
.idea
+2
View File
@@ -1,5 +1,7 @@
# Badger
Create badge from your prometheus metrics
![Hello](http://localhost:8080/mel)
![Hello](http://localhost:8080/dockerhub)
+6 -1
View File
@@ -24,6 +24,8 @@ const (
fontSize = 12
textMarginX = 5.0
textMarginY = -2.0
badgeWidth = 180
badgeHeight = 20
)
var (
@@ -73,7 +75,7 @@ func generateBadge(client api.Client, c *gin.Context) error {
}
metric := queryMetric(client, query)
dc := gg.NewContext(180, 22)
dc := gg.NewContext(badgeWidth, badgeHeight)
fontPath := filepath.Join("fonts", "SourceCodePro-Regular.ttf")
if err := dc.LoadFontFace(fontPath, fontSize); err != nil {
return fmt.Errorf("load font %w", err)
@@ -90,6 +92,9 @@ func generateBadge(client api.Client, c *gin.Context) error {
dc.SetColor(query.Color)
labelContainerWidth := labelWidth + textMarginX*2
if labelContainerWidth < badgeWidth*0.5 {
labelContainerWidth = badgeWidth * 0.5
}
dc.DrawRectangle(0, 0, labelContainerWidth, float64(dc.Height()))
dc.Fill()