safe_struct.go 781 B

1234567891011121314151617181920212223242526272829
  1. package reflect2
  2. type safeStructType struct {
  3. safeType
  4. }
  5. func (type2 *safeStructType) FieldByName(name string) StructField {
  6. field, found := type2.Type.FieldByName(name)
  7. if !found {
  8. panic("field " + name + " not found")
  9. }
  10. return &safeField{StructField: field}
  11. }
  12. func (type2 *safeStructType) Field(i int) StructField {
  13. return &safeField{StructField: type2.Type.Field(i)}
  14. }
  15. func (type2 *safeStructType) FieldByIndex(index []int) StructField {
  16. return &safeField{StructField: type2.Type.FieldByIndex(index)}
  17. }
  18. func (type2 *safeStructType) FieldByNameFunc(match func(string) bool) StructField {
  19. field, found := type2.Type.FieldByNameFunc(match)
  20. if !found {
  21. panic("field match condition not found in " + type2.Type.String())
  22. }
  23. return &safeField{StructField: field}
  24. }