package html_components type SelectInputOption struct { Label string Value string Selected bool } type SelectInput struct { Label string Name string Options []SelectInputOption HideLabel bool } func (s SelectInput) SetSelectedOption(selectedFunc func(option SelectInputOption) bool) SelectInput { newOptions := make([]SelectInputOption, len(s.Options)) for index, option := range s.Options { if selectedFunc(option) { option.Selected = true } newOptions[index] = option } s.Options = newOptions return s }