func()

in pkg/generator/gotext/config.go [82:123]


func (f *Field) randomize(object map[string]any) any {
	var buf bytes.Buffer

	// if there is a template, process that
	if f.template != nil {
		err := f.template.Tpl.Execute(&buf, object)
		if err != nil {
			log.Fatal("Failed to execute template", f.template.Format, "with error", err)
			return f.Type
		}

		// need to convert this to the type
		return f.convert(buf)
	}

	// if there are choices, select one at random
	if f.Choices != nil {
		count := len(f.Choices)
		if count > 0 {
			return f.Choices[rand.Intn(count)]
		}
	}

	// if there is a random definition, use that
	switch f.Type {
	case "int":
		return RandomInt(65535)
	case "IPv4", "IP", "ipv4":
		return RandomIPv4()
	case "Port", "port":
		return strconv.Itoa(random.Port())
	case "interface", "Intf", "intf":
		return fmt.Sprintf("%s%02d", f.Name, rand.Intn(16))
	case "Duration", "duration":
		return RandomDuration()
	default:
	}

	// otherwise, return the type as a string
	return f.Type

}