summaryrefslogtreecommitdiff
path: root/findFilename.go
diff options
context:
space:
mode:
Diffstat (limited to 'findFilename.go')
-rw-r--r--findFilename.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/findFilename.go b/findFilename.go
index 1160e08..1b36f38 100644
--- a/findFilename.go
+++ b/findFilename.go
@@ -53,7 +53,7 @@ func GetFilename(pb proto.Message) (string, error) {
}
// sets "Filename" if it exists in the protobuf
-func SetFilename(pb proto.Message, filename string) bool {
+func SetFilename(pb proto.Message, filename string) (bool, error) {
msg := pb.ProtoReflect() // This is the entry point to the reflection API.
descriptor := msg.Descriptor() // Get the message's descriptor, which contains metadata about its fields.
@@ -62,12 +62,17 @@ func SetFilename(pb proto.Message, filename string) bool {
fieldDescriptor := descriptor.Fields().ByName(fieldName)
if fieldDescriptor == nil {
- return false
+ fieldName = protoreflect.Name("filename")
+ fieldDescriptor = descriptor.Fields().ByName(fieldName)
+ }
+
+ if fieldDescriptor == nil {
+ return false, fmt.Errorf("fieldDescriptor == nil")
}
if fieldDescriptor.Kind() != protoreflect.StringKind {
// The field exists but is not a string, so we can't return it as one.
- return false
+ return false, fmt.Errorf("The field exists but is not a string")
}
valueToSet := protoreflect.ValueOfString(filename)
@@ -77,5 +82,5 @@ func SetFilename(pb proto.Message, filename string) bool {
msg.Set(fieldDescriptor, valueToSet)
// 7. Convert the protoreflect.Value to a native Go string.
- return true
+ return true, nil
}