All checks were successful
ci/woodpecker/push/build Pipeline was successful
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package render
|
|
|
|
import (
|
|
"github.com/jedib0t/go-pretty/v6/table"
|
|
"github.com/jedib0t/go-pretty/v6/text"
|
|
"gitnet.fr/deblan/expiration-check/checker"
|
|
"os"
|
|
"sort"
|
|
)
|
|
|
|
func Render(values []checker.Domain, warning, danger float64) {
|
|
sort.SliceStable(values, func(i, j int) bool {
|
|
if values[i].Failed && values[j].Failed {
|
|
return values[i].Name < values[j].Name
|
|
}
|
|
|
|
if values[i].Failed {
|
|
return false
|
|
}
|
|
|
|
if values[j].Failed {
|
|
return true
|
|
}
|
|
|
|
return values[i].DaysLeft < values[j].DaysLeft
|
|
})
|
|
|
|
t := table.NewWriter()
|
|
t.SetOutputMirror(os.Stdout)
|
|
t.AppendHeader(table.Row{
|
|
text.Colors{0, text.FgCyan}.Sprint("Domain"),
|
|
text.Colors{0, text.FgCyan}.Sprint("Days"),
|
|
text.Colors{0, text.FgCyan}.Sprint("Date"),
|
|
})
|
|
t.SetColumnConfigs([]table.ColumnConfig{
|
|
{Number: 2, Align: text.AlignRight},
|
|
{Number: 3, Align: text.AlignRight},
|
|
})
|
|
|
|
for _, value := range values {
|
|
if value.Failed {
|
|
t.AppendRow(table.Row{
|
|
value.Name,
|
|
text.Colors{0, text.FgRed}.Sprint("FAIL"),
|
|
text.Colors{0, text.FgRed}.Sprint("FAIL"),
|
|
}, table.RowConfig{})
|
|
} else {
|
|
var days string
|
|
var date string
|
|
|
|
if value.DaysLeft <= danger {
|
|
days = text.Colors{0, text.FgRed}.Sprint("FAIL")
|
|
date = text.Colors{0, text.FgRed}.Sprint("FAIL")
|
|
} else if value.DaysLeft <= warning {
|
|
days = text.Colors{0, text.FgYellow}.Sprint(value.DaysLeft)
|
|
date = text.Colors{0, text.FgYellow}.Sprint(value.Date)
|
|
} else {
|
|
days = text.Colors{0, text.FgGreen}.Sprint(value.DaysLeft)
|
|
date = text.Colors{0, text.FgGreen}.Sprint(value.Date)
|
|
}
|
|
|
|
t.AppendRow(table.Row{
|
|
value.Name,
|
|
days,
|
|
date,
|
|
}, table.RowConfig{})
|
|
}
|
|
}
|
|
|
|
t.Render()
|
|
}
|