s3-tests-parser/internal/templates/templates.go
Denis Kirillov ca943e1dc8 Support result formatting
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-09-01 12:08:49 +03:00

86 lines
1.5 KiB
Go

package templates
import (
_ "embed"
"fmt"
"text/template"
)
const (
GreenColor = "green"
YellowColor = "yellow"
RedColor = "red"
BlueColor = "blue"
BlackColor = "black"
)
const (
blackTerminal = "\033[0m"
redTerminal = "\033[31m"
greenTerminal = "\033[32m"
yellowTerminal = "\033[33m"
blueTerminal = "\033[34m"
)
const (
greenCircle = "🟢"
yellowCircle = "🟡"
redCircle = "🔴"
blueCircle = "🔵"
blackCircle = "⚫"
)
var (
//go:embed resources/txt-template.gotmpl
txtTemplate []byte
//go:embed resources/md-template.gotmpl
mdTemplate []byte
)
func GetTemplate(outFormat string) (*template.Template, error) {
var templateData []byte
switch outFormat {
case "txt":
templateData = txtTemplate
case "md":
templateData = mdTemplate
default:
return nil, fmt.Errorf("unkonwn output format: %s", outFormat)
}
return template.New("out-format").Funcs(template.FuncMap{
"colorToCircle": ColorToCircle,
"colorToTerminal": ColorToTerminal,
}).Parse(string(templateData))
}
func ColorToCircle(color string) string {
switch color {
case GreenColor:
return greenCircle
case YellowColor:
return yellowCircle
case RedColor:
return redCircle
case BlueColor:
return blueCircle
default:
return blackCircle
}
}
func ColorToTerminal(color string) string {
switch color {
case GreenColor:
return greenTerminal
case YellowColor:
return yellowTerminal
case RedColor:
return redTerminal
case BlueColor:
return blueTerminal
default:
return blackTerminal
}
}