Last active
April 9, 2020 09:54
-
-
Save vadzappa/b24fe28b7b7ee45d46b3a07f771238a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func extractLogField(fd protoreflect.FieldDescriptor, hasPrefix bool) (string, bool) { | |
// check if there are any options available for the field | |
opts, ok := fd.Options().(*descriptorpb.FieldOptions) | |
if !ok || opts == nil { | |
return "", false | |
} | |
// check if protocol.FieldOptions specified for the field | |
// basically extracting anything from [(protocol.options).logField = "something_here"] | |
field, ok := proto.GetExtension(opts, protocol.E_Options).(*protocol.FieldOptions) | |
if !ok || field == nil { | |
return "", false | |
} | |
if field.LogField == "" && !hasPrefix { | |
return "", false | |
} | |
return field.LogField, true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment