Files
streamsql/utils/reflectutil/reflectutil.go
T
rulego-team a47748d4c7 refactor: translate Chinese comments to English in functions directory
- Convert all Chinese function comments to English in functions package
- Update interface documentation for better international readability
- Maintain original logic and functionality unchanged
- Improve code documentation standards for global development
2025-08-04 12:35:33 +08:00

28 lines
604 B
Go

package reflectutil
import (
"fmt"
"reflect"
)
// SafeFieldByName safely gets struct field
func SafeFieldByName(v reflect.Value, fieldName string) (reflect.Value, error) {
// Check if Value is valid
if !v.IsValid() {
return reflect.Value{}, fmt.Errorf("invalid value")
}
// Check if it's a struct type
if v.Kind() != reflect.Struct {
return reflect.Value{}, fmt.Errorf("value is not a struct, got %v", v.Kind())
}
// Safely get field
field := v.FieldByName(fieldName)
if !field.IsValid() {
return reflect.Value{}, fmt.Errorf("field %s not found", fieldName)
}
return field, nil
}