Go CLI that turns the markdown currency of this stack (Redmine notes, Discourse posts, briefing output) into typeset PDFs: two embedded typst templates (report with title page/TOC/headers, dense brief), front-matter (title/subtitle/author/date/classification/template), GFM tables, and bar charts rendered in pure Go (go-chart) from fenced chart data blocks. Engine is a prebuilt typst 0.15.1 container pinned by digest and run --network none; PDF bytes to stdout or -o. Exit codes 0/1/2. All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures plus a host-side smoke against the real engine container. Generated with Crush Assisted-by: Crush:glm-5.2
41 lines
908 B
Go
41 lines
908 B
Go
package chart
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// ParseFloats parses a list of floats.
|
|
func ParseFloats(values ...string) ([]float64, error) {
|
|
var output []float64
|
|
var parsedValue float64
|
|
var err error
|
|
var cleaned string
|
|
for _, value := range values {
|
|
cleaned = strings.TrimSpace(strings.Replace(value, ",", "", -1))
|
|
if cleaned == "" {
|
|
continue
|
|
}
|
|
if parsedValue, err = strconv.ParseFloat(cleaned, 64); err != nil {
|
|
return nil, err
|
|
}
|
|
output = append(output, parsedValue)
|
|
}
|
|
return output, nil
|
|
}
|
|
|
|
// ParseTimes parses a list of times with a given format.
|
|
func ParseTimes(layout string, values ...string) ([]time.Time, error) {
|
|
var output []time.Time
|
|
var parsedValue time.Time
|
|
var err error
|
|
for _, value := range values {
|
|
if parsedValue, err = time.Parse(layout, value); err != nil {
|
|
return nil, err
|
|
}
|
|
output = append(output, parsedValue)
|
|
}
|
|
return output, nil
|
|
}
|