summaryrefslogtreecommitdiff
path: root/populatePackagePB.go
diff options
context:
space:
mode:
Diffstat (limited to 'populatePackagePB.go')
-rw-r--r--populatePackagePB.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/populatePackagePB.go b/populatePackagePB.go
index 10fb4f2..6bd3c48 100644
--- a/populatePackagePB.go
+++ b/populatePackagePB.go
@@ -3,9 +3,11 @@ package debian
import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
+
+ "go.wit.com/lib/config"
)
-func setString(pb proto.Message, varname string, val string) bool {
+func setString(pb proto.Message, varname string, val 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.
@@ -14,12 +16,12 @@ func setString(pb proto.Message, varname string, val string) bool {
fieldDescriptor := descriptor.Fields().ByName(fieldName)
if fieldDescriptor == nil {
- return false
+ return false, config.ErrProtoNoVarName
}
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, config.ErrProtoVarNotString
}
valueToSet := protoreflect.ValueOfString(varname)
@@ -29,5 +31,5 @@ func setString(pb proto.Message, varname string, val string) bool {
msg.Set(fieldDescriptor, valueToSet)
// 7. Convert the protoreflect.Value to a native Go string.
- return true
+ return true, nil
}