mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
feat: add cmdline argument to control whether generate package name from proto filename (#5387)
This commit is contained in:
@@ -199,7 +199,9 @@ func mkdir(ctx *ctx.ProjectContext, proto parser.Proto, conf *conf.Config, c *ZR
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
serviceName := proto.Package.Name
|
||||
|
||||
serviceName := determineServiceName(proto, c)
|
||||
|
||||
return &defaultDirContext{
|
||||
ctx: ctx,
|
||||
inner: inner,
|
||||
@@ -270,3 +272,16 @@ func (d *defaultDirContext) GetServiceName() stringx.String {
|
||||
func (d *Dir) Valid() bool {
|
||||
return len(d.Filename) > 0 && len(d.Package) > 0
|
||||
}
|
||||
|
||||
// determineServiceName returns the service name based on the proto file and context.
|
||||
// By default, it uses the proto package name (supports multi-proto files).
|
||||
// Falls back to filename if --name-from-filename flag is set or package name is empty.
|
||||
func determineServiceName(proto parser.Proto, c *ZRpcContext) string {
|
||||
if c != nil && c.NameFromFilename {
|
||||
return strings.TrimSuffix(proto.Name, filepath.Ext(proto.Name))
|
||||
}
|
||||
if proto.Package.Package != nil && len(proto.Package.Name) > 0 {
|
||||
return proto.Package.Name
|
||||
}
|
||||
return strings.TrimSuffix(proto.Name, filepath.Ext(proto.Name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user