mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
fix panic (#3176)
This commit is contained in:
parent
1aebb3e5e4
commit
1fd0c3992b
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user