hskiba

GetStructModifiableFields

Oct 7th, 2021
1,632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.37 KB | None | 0 0
  1. // GetStructModifiableFields returns an array of field names that do not have a
  2. // readonly:"true" struct tag
  3. func GetStructModifiableFields(s interface{}) (fields []reflect.StructField) {
  4.     structFields := reflect.VisibleFields(reflect.TypeOf(s))
  5.     for _, f := range structFields {
  6.         if f.Tag.Get("readonly") != "true" {
  7.             fields = append(fields, f)
  8.         }
  9.     }
  10.     return
  11. }
  12.  
Advertisement