Skip to content

Commit

Permalink
(fix) timestamp and color fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Aug 8, 2024
1 parent 92bffe1 commit 0eb6f0b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
5 changes: 4 additions & 1 deletion app/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ require (
)

// github.com/kevincobain2000/go-progress-svg => /Users/pulkit.kathuria/git/go-progress-svg
replace github.com/narqo/go-badge => github.com/kevincobain2000/go-badge v0.0.0-20240527052429-de9eb158774b
// replace github.com/narqo/go-badge => github.com/kevincobain2000/go-badge master
replace github.com/narqo/go-badge => github.com/kevincobain2000/go-badge v0.0.0-20240808031701-59995e0da671

// replace github.com/narqo/go-badge => /Users/pulkit.kathuria/git/go-badge

require (
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions app/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kevincobain2000/go-badge v0.0.0-20240527052429-de9eb158774b h1:rszueD1SXo5shNhpRxP9s1JQz4urhf7E8kmjTgF4RJE=
github.com/kevincobain2000/go-badge v0.0.0-20240527052429-de9eb158774b/go.mod h1:m9BzkaxwU4IfPQi9ko23cmuFltayFe8iS0dlRlnEWiM=
github.com/kevincobain2000/go-badge v0.0.0-20240808031701-59995e0da671 h1:GZFO+lyVmb9Cp1vA6UrwX8cSFvST1HxOU1F/5TFdrrI=
github.com/kevincobain2000/go-badge v0.0.0-20240808031701-59995e0da671/go.mod h1:m9BzkaxwU4IfPQi9ko23cmuFltayFe8iS0dlRlnEWiM=
github.com/kevincobain2000/go-progress-svg v1.0.5 h1:wTIG191GJWkqNNtQmtmaUgb0d9fWXnGUa6g/1/sA1Dg=
github.com/kevincobain2000/go-progress-svg v1.0.5/go.mod h1:d6tIZwxFM0QdM16xoVRFKCnrFZTDBR0deQhe5dy2QXg=
github.com/kevincobain2000/instachart v1.0.20 h1:pGhgXYE5rlhBHXqwIc1UBLhdOM/EkAnKPA9rzq3J7Ik=
Expand Down
35 changes: 26 additions & 9 deletions app/pkg/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ func (b *Badge) Get(req *BadgeRequest, t *models.Type) ([]byte, error) {
label := t.Name + " | " + req.Branch

if t.Metric == "" {
badge.SetSocialTemplate()
return badge.RenderBytes(label, scoreStr, "#00000", "#00000", "#fff")
return badge.RenderBytesSocial(label, scoreStr, "#00000", "#00000", "#fff")
}
badge.SetFlatTemplate()

scoreStr += ret.Metric
badgeColor, labelColor, color := b.getBadgeColors(t.Metric)
return badge.RenderBytes(label, scoreStr, badgeColor, labelColor, color)
badgeColor, labelColor, color := b.getBadgeColors(t.Metric, ret.Score)
return badge.RenderBytesFlat(label, scoreStr, badgeColor, labelColor, color)
}

func (b *Badge) Get404(req *BadgeRequest) ([]byte, error) {
return badge.RenderBytes(req.Branch+"|"+req.Type, "404", "#fff", "white", "red")
return badge.RenderBytesFlat(req.Branch+"|"+req.Type, "404", "#fff", "white", "red")
}

func (b *Badge) GetType(name string) (*models.Type, error) {
Expand All @@ -49,13 +47,32 @@ func (b *Badge) GetType(name string) (*models.Type, error) {
return b.typeModel.Get(name)
}

func (e *Badge) getBadgeColors(metric string) (badge.Color, badge.Color, badge.Color) {
func (e *Badge) getBadgeColors(metric string, score float64) (badge.Color, badge.Color, badge.Color) {
metric = strings.ToLower(metric)
if metric == "%" {
return "#fff", "#fff", "blue"
var color badge.Color
var textColor badge.Color
switch {
case score >= 90:
color = "green"
textColor = "black"
case score >= 75:
color = "blue"
textColor = "white"
case score >= 50:
color = "orange"
textColor = "black"
case score < 50:
color = "red"
textColor = "white"
default:
color = "white"
textColor = "black"
}
return "#fff", textColor, color
}
if metric == "kb" || metric == "mb" || metric == "gb" {
return "#fff", "gray", "#F8C8DC"
return "#fff", "gray", "yellow"
}
if metric == "ms" ||
metric == "s" ||
Expand Down
8 changes: 4 additions & 4 deletions app/pkg/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"os"
"time"

"github.com/go-echarts/statsview"
"github.com/go-echarts/statsview/viewer"
Expand Down Expand Up @@ -79,12 +80,11 @@ func HTTPErrorHandler(err error, c echo.Context) {
}

func ltsv() string {
time_custom := "2006-01-02 15:04:05"
_ = time_custom
timeCustom := time.Now().Format("2006-01-02 15:04:05")
var format string
format += "time:${time_custom}\t"
format += fmt.Sprintf("time:%s\t", timeCustom)
format += "host:${remote_ip}\t"
format += "forwardedfor:${header:x-forwarded-for}\t"
format += "xff:${header:x-forwarded-for}\t"
format += "req:-\t"
format += "status:${status}\t"
format += "method:${method}\t"
Expand Down

0 comments on commit 0eb6f0b

Please sign in to comment.