s3-tests-parser/internal/templates/templates.go

87 lines
1.5 KiB
Go
Raw Normal View History

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
}
}