Esempio n. 1
0
func FormFromStruct(theme *terminal.Theme, target interface{}) error {
	fields, err := reflections.Fields(target)

	if err != nil {
		return err
	}

	var formFields []Field

	for _, fieldName := range fields {

		field, err := reflectField(fieldName, target)
		if err != nil {
			return err
		}
		formFields = append(formFields, field)

	}

	form := NewForm(theme, formFields)
	form.Run()

	return form.GetValue(target)

}
Esempio n. 2
0
func ExampleFields() {
	s := MyStruct{
		FirstField:  "first value",
		SecondField: 2,
		ThirdField:  "third value",
	}

	var fields []string

	// Fields will list every structure exportable fields.
	// Here, it's content would be equal to:
	// []string{"FirstField", "SecondField", "ThirdField"}
	fields, _ = reflections.Fields(s)
	fmt.Println(fields)
}