in pkg/generator/gotext/gotext.go [209:259]
func New(cfg *ucfg.Config) (generator.Generator, error) {
c := defaultConfig()
if err := cfg.Unpack(&c); err != nil {
return nil, err
}
gotextConfig := c.Config
// check variables
// return
g := &GoText{
Name: gotextConfig.Name,
Fields: nil,
templates: nil,
}
for i, v := range gotextConfig.Fields {
f := Field{
Name: v.Name,
Type: v.Type,
Choices: v.Choices,
}
// if there is a Template field
if v.Template != nil {
t, err := template.New(strconv.Itoa(i)).Funcs(FunctionMap).Parse(*v.Template)
if err != nil {
return nil, err
}
f.template = &Template{
Format: *v.Template,
Tpl: t,
}
}
g.Fields = append(g.Fields, f)
}
for i, v := range gotextConfig.Formats {
t, err := template.New(strconv.Itoa(i)).Funcs(FunctionMap).Parse(*v)
if err != nil {
return nil, err
}
g.templates = append(g.templates, Template{
Format: *v,
Tpl: t,
})
}
return g, nil
}