This commit is contained in:
guonaihong
2023-04-30 22:58:30 +08:00
committed by GitHub
parent 1aebb3e5e4
commit 1fd0c3992b

View File

@@ -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
} }