diff options
| -rw-r--r-- | findFilename.go | 8 | ||||
| -rw-r--r-- | generate.go | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/findFilename.go b/findFilename.go index 1b36f38..85ccbf4 100644 --- a/findFilename.go +++ b/findFilename.go @@ -1,12 +1,16 @@ package config import ( + "errors" "fmt" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" ) +var ErrProtoNoVarName error = errors.New("name not in .proto") +var ErrProtoVarNotString error = errors.New("name exists but is not a string") + // Gemini AI can help author some pretty good protobuf code. // I never remember the syntax for 'reflect' on these things. @@ -35,13 +39,13 @@ func GetFilename(pb proto.Message) (string, error) { // 4. Check if the field was found. If not, return false. if fieldDescriptor == nil { - return "", fmt.Errorf("fieldDescriptor == nil") + return "", ErrProtoNoVarName } // 5. (Optional but recommended) Verify the field is a string type. if fieldDescriptor.Kind() != protoreflect.StringKind { // The field exists but is not a string, so we can't return it as one. - return "", fmt.Errorf("The field exists but is not a string") + return "", ErrProtoVarNotString } // 6. If the field exists and is a string, get its value. diff --git a/generate.go b/generate.go index 0424400..8b2c357 100644 --- a/generate.go +++ b/generate.go @@ -6,8 +6,6 @@ package config // then this process could be fully automated // //go:generate make go-generate -// # go:generate go get go.wit.com/apps/autogenpb # can't do this here since this repo is a GO "primitive" library (no deps) -// # go:generate go install -v go.wit.com/apps/autogenpb //go:generate autogenpb --proto config.proto // # go:generate go get golang.org/x/tools # repo seems broken at this time (?) // # go:generate go install -v golang.org/x/tools/cmd/goimports |
