From 1fd0c3992be3efb382855027f97b5171529fdb39 Mon Sep 17 00:00:00 2001 From: guonaihong Date: Sun, 30 Apr 2023 22:58:30 +0800 Subject: [PATCH] fix panic (#3176) --- tools/goctl/rpc/parser/parser.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/goctl/rpc/parser/parser.go b/tools/goctl/rpc/parser/parser.go index 1c80a4f2..ad500090 100644 --- a/tools/goctl/rpc/parser/parser.go +++ b/tools/goctl/rpc/parser/parser.go @@ -1,6 +1,7 @@ package parser import ( + "errors" "go/token" "os" "path/filepath" @@ -16,6 +17,8 @@ type ( DefaultProtoParser struct{} ) +var ErrGoPackage = errors.New(`option go_package = "" field is not filled in`) + // NewDefaultProtoParser creates a new instance func NewDefaultProtoParser() *DefaultProtoParser { return &DefaultProtoParser{} @@ -79,6 +82,9 @@ func (p *DefaultProtoParser) Parse(src string, multiple ...bool) (Proto, error) } if len(ret.GoPackage) == 0 { + if ret.Package.Package == nil { + return ret, ErrGoPackage + } ret.GoPackage = ret.Package.Name }