isValidateOnlyRequest checks if a request has validate_only field set to true using protoreflect to generically detect the field.
(request any)
| 839 | // isValidateOnlyRequest checks if a request has validate_only field set to true |
| 840 | // using protoreflect to generically detect the field. |
| 841 | func isValidateOnlyRequest(request any) bool { |
| 842 | if request == nil { |
| 843 | return false |
| 844 | } |
| 845 | |
| 846 | // Check if the value is nil (for pointer types). |
| 847 | val := reflect.ValueOf(request) |
| 848 | if val.Kind() == reflect.Pointer && val.IsNil() { |
| 849 | return false |
| 850 | } |
| 851 | |
| 852 | protoMsg, ok := request.(proto.Message) |
| 853 | if !ok { |
| 854 | return false |
| 855 | } |
| 856 | |
| 857 | // Use protoreflect to check for validate_only field. |
| 858 | msg := protoMsg.ProtoReflect() |
| 859 | fields := msg.Descriptor().Fields() |
| 860 | validateOnlyField := fields.ByName("validate_only") |
| 861 | if validateOnlyField == nil { |
| 862 | return false |
| 863 | } |
| 864 | |
| 865 | // Check if the field is set and is true. |
| 866 | return msg.Get(validateOnlyField).Bool() |
| 867 | } |
| 868 | |
| 869 | // expect |
| 870 | // 1. connect.Error |