photoprism/pkg/report/render.go
Michael Mayer 3c4cc40882 Security: Refactor log levels and events #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-10 16:34:07 +02:00

43 lines
1.2 KiB
Go

package report
import (
"fmt"
"github.com/photoprism/photoprism/pkg/clean"
)
// RenderFormat returns a text-formatted table, optionally as valid Markdown,
// so the output can be pasted into the docs.
func RenderFormat(rows [][]string, cols []string, format Format) (string, error) {
switch format {
case CSV:
return Render(rows, cols, Options{Format: CSV})
case TSV:
return Render(rows, cols, Options{Format: TSV})
case Markdown:
return Render(rows, cols, Options{Format: Markdown, Valid: true})
case Default:
return Render(rows, cols, Options{Format: Default, Valid: false})
default:
return "", fmt.Errorf("invalid format %s", clean.Log(string(format)))
}
}
// Render returns a text-formatted table, optionally as valid Markdown,
// so the output can be pasted into the docs.
func Render(rows [][]string, cols []string, opt Options) (string, error) {
switch opt.Format {
case CSV:
return CsvExport(rows, cols, ';')
case TSV:
return CsvExport(rows, cols, '\t')
case Markdown:
opt.Valid = true
return MarkdownTable(rows, cols, opt), nil
case Default:
opt.Valid = false
return MarkdownTable(rows, cols, opt), nil
default:
return "", fmt.Errorf("invalid format %s", clean.Log(string(opt.Format)))
}
}