MCPcopy Create free account
hub / github.com/bytebase/bytebase / isValidateOnlyRequest

Function isValidateOnlyRequest

backend/api/v1/audit.go:841–867  ·  view source on GitHub ↗

isValidateOnlyRequest checks if a request has validate_only field set to true using protoreflect to generically detect the field.

(request any)

Source from the content-addressed store, hash-verified

839// isValidateOnlyRequest checks if a request has validate_only field set to true
840// using protoreflect to generically detect the field.
841func 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

Callers 2

createAuditLogMethod · 0.85

Calls 3

GetMethod · 0.80
ProtoReflectMethod · 0.45
DescriptorMethod · 0.45

Tested by 1