mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
8745d7ef1b
* extract kindsys * reinstate kindsys report This may end up living somewhere else (or not! who knows!), but the important part is that I don't get rid of it right now :) I hate the package layout (kindsysreport/codegen) for the main function and will take pretty much any alternative suggestion, but we can change also change it later. Note that the generated report.json is in a different location - anything using this (ops something) needs to be updated. * kindsysreport in codeowners
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package codegen
|
|
|
|
import (
|
|
"bytes"
|
|
"embed"
|
|
"text/template"
|
|
"time"
|
|
|
|
"github.com/grafana/codejen"
|
|
"github.com/grafana/kindsys"
|
|
)
|
|
|
|
// All the parsed templates in the tmpl subdirectory
|
|
var tmpls *template.Template
|
|
|
|
func init() {
|
|
base := template.New("codegen").Funcs(template.FuncMap{
|
|
"now": time.Now,
|
|
})
|
|
tmpls = template.Must(base.ParseFS(tmplFS, "tmpl/*.tmpl"))
|
|
}
|
|
|
|
//go:embed tmpl/*.tmpl
|
|
var tmplFS embed.FS
|
|
|
|
// The following group of types, beginning with tvars_*, all contain the set
|
|
// of variables expected by the corresponding named template file under tmpl/
|
|
type (
|
|
tvars_autogen_header struct {
|
|
GeneratorPath string
|
|
LineagePath string
|
|
LineageCUEPath string
|
|
GenLicense bool
|
|
}
|
|
tvars_gen_header struct {
|
|
MainGenerator string
|
|
Using []codejen.NamedJenny
|
|
From string
|
|
Leader string
|
|
}
|
|
tvars_kind_registry struct {
|
|
PackageName string
|
|
KindPackagePrefix string
|
|
Kinds []kindsys.Core
|
|
}
|
|
tvars_coremodel_imports struct {
|
|
PackageName string
|
|
}
|
|
)
|
|
|
|
type HeaderVars = tvars_autogen_header
|
|
|
|
// GenGrafanaHeader creates standard header elements for generated Grafana files.
|
|
func GenGrafanaHeader(vars HeaderVars) string {
|
|
buf := new(bytes.Buffer)
|
|
if err := tmpls.Lookup("autogen_header.tmpl").Execute(buf, vars); err != nil {
|
|
panic(err)
|
|
}
|
|
return buf.String()
|
|
}
|