func()

in pkg/generator/gotext/gotext.go [179:206]


func (g *GoText) Next() ([]byte, error) {
	var buf bytes.Buffer

	object := make(map[string]any)

	object["Timestamp"] = time.Now()

	// loop over each field
	for _, f := range g.Fields {
		object[f.Name] = f.randomize(object)
	}

	// are there formats?
	if len(g.templates) < 1 {
		fmt.Printf("i am %v; %v\n", g.Name, g.templates)
		return nil, fmt.Errorf("This has no templates to process; bailing")
	}
	index := rand.Intn(len(g.templates))

	// attempt to generate each one
	err := g.templates[index].Tpl.Execute(&buf, object)
	if err != nil {
		log.Fatal("Failed to execute template", g.templates[index].Format, "with error", err)
		return nil, err
	}

	return buf.Bytes(), err
}