Skip to content

Instantly share code, notes, and snippets.

@vadzappa
Last active April 9, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadzappa/b24fe28b7b7ee45d46b3a07f771238a2 to your computer and use it in GitHub Desktop.
Save vadzappa/b24fe28b7b7ee45d46b3a07f771238a2 to your computer and use it in GitHub Desktop.
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