瀏覽代碼

fix panic (#3176)

guonaihong 2 年之前
父節點
當前提交
1fd0c3992b
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      tools/goctl/rpc/parser/parser.go

+ 6 - 0
tools/goctl/rpc/parser/parser.go

@@ -1,6 +1,7 @@
 package parser
 package parser
 
 
 import (
 import (
+	"errors"
 	"go/token"
 	"go/token"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
@@ -16,6 +17,8 @@ type (
 	DefaultProtoParser struct{}
 	DefaultProtoParser struct{}
 )
 )
 
 
+var ErrGoPackage = errors.New(`option go_package = "" field is not filled in`)
+
 // NewDefaultProtoParser creates a new instance
 // NewDefaultProtoParser creates a new instance
 func NewDefaultProtoParser() *DefaultProtoParser {
 func NewDefaultProtoParser() *DefaultProtoParser {
 	return &DefaultProtoParser{}
 	return &DefaultProtoParser{}
@@ -79,6 +82,9 @@ func (p *DefaultProtoParser) Parse(src string, multiple ...bool) (Proto, error)
 	}
 	}
 
 
 	if len(ret.GoPackage) == 0 {
 	if len(ret.GoPackage) == 0 {
+		if ret.Package.Package == nil {
+			return ret, ErrGoPackage
+		}
 		ret.GoPackage = ret.Package.Name
 		ret.GoPackage = ret.Package.Name
 	}
 	}