if !reflect.ValueOf(strct).Field(i).CanInterface() { continue }
在 2016年4月27日星期三 UTC+8上午3:10:34,Tad Vizbaras写道: > > While reviewing number of popular packages online I noticed different > approaches to the same problem: > how to find if struct field is exported or not? > > Some use PkgPath and check if it is empty: > > // skip unexported fields > if len(f.PkgPath) != 0 { > continue > } > > Some check if field is settable something like: > > // Don't even bother for unexported fields. > if !v.CanSet() { > return nil > } > > Stdlib does not seem to have IsExported() so question is: which way is > idiomatic? > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/91d7980c-f4ec-4a6c-ab74-2bbd898a714c%40googlegroups.com.