From 5e39931020121dea848dce096ab23e1061193a58 Mon Sep 17 00:00:00 2001 From: yuxialuozi <3159452953@qq.com> Date: Wed, 29 May 2024 17:13:40 +0800 Subject: [PATCH 1/3] fix:change the parameter service to server_name --- cmd/static/server_flags.go | 1 + config/server.go | 13 +++++++------ pkg/client/check.go | 4 ++-- pkg/client/hz.go | 7 ++++++- pkg/client/kitex.go | 6 ++++++ pkg/consts/const.go | 1 + pkg/server/check.go | 4 ++-- pkg/server/hz.go | 7 ++++++- pkg/server/kitex.go | 7 ++++++- 9 files changed, 37 insertions(+), 13 deletions(-) diff --git a/cmd/static/server_flags.go b/cmd/static/server_flags.go index f1ae5fff..a70351f0 100644 --- a/cmd/static/server_flags.go +++ b/cmd/static/server_flags.go @@ -26,6 +26,7 @@ func serverFlags() []cli.Flag { globalArgs := config.GetGlobalArgs() return []cli.Flag{ &cli.StringFlag{Name: consts.Service, Usage: "Specify the service name.", Destination: &globalArgs.ServerArgument.Service}, + &cli.StringFlag{Name: consts.ServerName, Usage: "Specify the server name.", Destination: &globalArgs.ServerArgument.ServerName}, &cli.StringFlag{Name: consts.ServiceType, Usage: "Specify the generate type. (RPC or HTTP)", Value: consts.RPC}, &cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.ServerArgument.GoMod}, &cli.StringFlag{Name: consts.IDLPath, Usage: "Specify the IDL file path. (.thrift or .proto)", Destination: &globalArgs.ServerArgument.IdlPath}, diff --git a/config/server.go b/config/server.go index cc3e4ce5..6e4a97e6 100644 --- a/config/server.go +++ b/config/server.go @@ -40,12 +40,13 @@ type ServerArgument struct { } type CommonParam struct { - Service string // service name - Type string // GenerateType: RPC or HTTP - GoMod string // Go Mod name - IdlPath string - OutDir string // output path - Registry string + Service string // service name + ServerName string //server name + Type string // GenerateType: RPC or HTTP + GoMod string // Go Mod name + IdlPath string + OutDir string // output path + Registry string } func NewServerArgument() *ServerArgument { diff --git a/pkg/client/check.go b/pkg/client/check.go index 08a4ef68..ea41e96a 100644 --- a/pkg/client/check.go +++ b/pkg/client/check.go @@ -41,8 +41,8 @@ func check(ca *config.ClientArgument) error { return errors.New("unsupported registry") } - if ca.Service == "" { - return errors.New("must specify service name when use registry") + if ca.Service == "" && ca.ServerName == "" { + return errors.New("must specify server name when use registry") } // handle cwd and output dir diff --git a/pkg/client/hz.go b/pkg/client/hz.go index 4dc40774..c89ddcd0 100644 --- a/pkg/client/hz.go +++ b/pkg/client/hz.go @@ -61,7 +61,12 @@ func convertHzArgument(ca *config.ClientArgument, hzArgument *hzConfig.Argument) hzArgument.IdlPaths = []string{abPath} hzArgument.Gomod = ca.GoMod - hzArgument.ServiceName = ca.Service + if ca.Service != "" { + hzArgument.ServiceName = ca.Service + } + if ca.ServerName != "" { + hzArgument.ServiceName = ca.ServerName + } hzArgument.Includes = ca.SliceParam.ProtoSearchPath hzArgument.Cwd = ca.Cwd hzArgument.Gosrc = ca.GoSrc diff --git a/pkg/client/kitex.go b/pkg/client/kitex.go index 638d55aa..e2a5d73f 100644 --- a/pkg/client/kitex.go +++ b/pkg/client/kitex.go @@ -39,6 +39,12 @@ func convertKitexArgs(sa *config.ClientArgument, kitexArgument *kargs.Arguments) kitexArgument.ModuleName = sa.GoMod kitexArgument.ServiceName = sa.Service + if sa.Service != "" { + kitexArgument.ServiceName = sa.Service + } + if sa.ServerName != "" { + kitexArgument.ServiceName = sa.ServerName + } kitexArgument.Includes = sa.SliceParam.ProtoSearchPath kitexArgument.Version = kitex.Version kitexArgument.RecordCmd = os.Args diff --git a/pkg/consts/const.go b/pkg/consts/const.go index a3c02df4..5dee3a1b 100644 --- a/pkg/consts/const.go +++ b/pkg/consts/const.go @@ -131,6 +131,7 @@ const ( DaoDir = "dao_dir" Service = "service" + ServerName = "server_name" ServiceType = "type" Module = "module" IDLPath = "idl" diff --git a/pkg/server/check.go b/pkg/server/check.go index b56c3eee..d8c92b76 100644 --- a/pkg/server/check.go +++ b/pkg/server/check.go @@ -41,8 +41,8 @@ func check(sa *config.ServerArgument) error { return errors.New("unsupported registry") } - if sa.Service == "" { - return errors.New("must specify service name") + if sa.Service == "" && sa.ServerName == "" { + return errors.New("must specify server name") } // handle cwd and output dir diff --git a/pkg/server/hz.go b/pkg/server/hz.go index 2192c8b5..bc8c9f8c 100644 --- a/pkg/server/hz.go +++ b/pkg/server/hz.go @@ -74,7 +74,12 @@ func convertHzArgument(sa *config.ServerArgument, hzArgument *hzConfig.Argument) hzArgument.IdlPaths = []string{abPath} hzArgument.Gomod = sa.GoMod - hzArgument.ServiceName = sa.Service + if sa.Service != "" { + hzArgument.ServiceName = sa.Service + } + if sa.ServerName != "" { + hzArgument.ServiceName = sa.ServerName + } hzArgument.OutDir = sa.OutDir hzArgument.Includes = sa.SliceParam.ProtoSearchPath hzArgument.Cwd = sa.Cwd diff --git a/pkg/server/kitex.go b/pkg/server/kitex.go index dd090aa3..c221d214 100644 --- a/pkg/server/kitex.go +++ b/pkg/server/kitex.go @@ -46,7 +46,12 @@ func convertKitexArgs(sa *config.ServerArgument, kitexArgument *kargs.Arguments) f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) kitexArgument.ModuleName = sa.GoMod - kitexArgument.ServiceName = sa.Service + if sa.Service != "" { + kitexArgument.ServiceName = sa.Service + } + if sa.ServerName != "" { + kitexArgument.ServiceName = sa.ServerName + } kitexArgument.Includes = sa.SliceParam.ProtoSearchPath kitexArgument.Version = kitex.Version kitexArgument.RecordCmd = os.Args From d5127c32f8916e0d5fd0ea710bbe44db403e4adb Mon Sep 17 00:00:00 2001 From: yuxialuozi <3159452953@qq.com> Date: Wed, 29 May 2024 22:51:41 +0800 Subject: [PATCH 2/3] fix:modify two variables to point to one parameter --- cmd/static/client_flags.go | 3 ++- cmd/static/server_flags.go | 2 +- config/server.go | 1 - pkg/client/check.go | 4 ++-- pkg/client/hz.go | 7 +------ pkg/client/kitex.go | 8 +------- pkg/common/kx_registry/registry.go | 8 ++++---- pkg/server/check.go | 2 +- pkg/server/hz.go | 7 +------ pkg/server/kitex.go | 7 +------ 10 files changed, 14 insertions(+), 35 deletions(-) diff --git a/cmd/static/client_flags.go b/cmd/static/client_flags.go index 37c712c3..38cd4796 100644 --- a/cmd/static/client_flags.go +++ b/cmd/static/client_flags.go @@ -25,7 +25,8 @@ import ( func clientFlags() []cli.Flag { globalArgs := config.GetGlobalArgs() return []cli.Flag{ - &cli.StringFlag{Name: consts.Service, Usage: "Specify the service name.", Destination: &globalArgs.ClientArgument.Service}, + &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended)", Destination: &globalArgs.ClientArgument.ServerName}, + &cli.StringFlag{Name: consts.ServerName, Usage: "Specify the server name.", Destination: &globalArgs.ClientArgument.ServerName}, &cli.StringFlag{Name: consts.ServiceType, Usage: "Specify the generate type. (RPC or HTTP)", Value: consts.RPC}, &cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.ClientArgument.GoMod}, &cli.StringFlag{Name: consts.IDLPath, Usage: "Specify the IDL file path. (.thrift or .proto)", Destination: &globalArgs.ClientArgument.IdlPath}, diff --git a/cmd/static/server_flags.go b/cmd/static/server_flags.go index a70351f0..3774348e 100644 --- a/cmd/static/server_flags.go +++ b/cmd/static/server_flags.go @@ -25,7 +25,7 @@ import ( func serverFlags() []cli.Flag { globalArgs := config.GetGlobalArgs() return []cli.Flag{ - &cli.StringFlag{Name: consts.Service, Usage: "Specify the service name.", Destination: &globalArgs.ServerArgument.Service}, + &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended)", Destination: &globalArgs.ServerArgument.ServerName}, &cli.StringFlag{Name: consts.ServerName, Usage: "Specify the server name.", Destination: &globalArgs.ServerArgument.ServerName}, &cli.StringFlag{Name: consts.ServiceType, Usage: "Specify the generate type. (RPC or HTTP)", Value: consts.RPC}, &cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.ServerArgument.GoMod}, diff --git a/config/server.go b/config/server.go index 6e4a97e6..78a7af5f 100644 --- a/config/server.go +++ b/config/server.go @@ -40,7 +40,6 @@ type ServerArgument struct { } type CommonParam struct { - Service string // service name ServerName string //server name Type string // GenerateType: RPC or HTTP GoMod string // Go Mod name diff --git a/pkg/client/check.go b/pkg/client/check.go index ea41e96a..6f533b83 100644 --- a/pkg/client/check.go +++ b/pkg/client/check.go @@ -41,8 +41,8 @@ func check(ca *config.ClientArgument) error { return errors.New("unsupported registry") } - if ca.Service == "" && ca.ServerName == "" { - return errors.New("must specify server name when use registry") + if ca.ServerName == "" { + return errors.New("must specify server name") } // handle cwd and output dir diff --git a/pkg/client/hz.go b/pkg/client/hz.go index c89ddcd0..1f3effcc 100644 --- a/pkg/client/hz.go +++ b/pkg/client/hz.go @@ -61,12 +61,7 @@ func convertHzArgument(ca *config.ClientArgument, hzArgument *hzConfig.Argument) hzArgument.IdlPaths = []string{abPath} hzArgument.Gomod = ca.GoMod - if ca.Service != "" { - hzArgument.ServiceName = ca.Service - } - if ca.ServerName != "" { - hzArgument.ServiceName = ca.ServerName - } + hzArgument.ServiceName = ca.ServerName hzArgument.Includes = ca.SliceParam.ProtoSearchPath hzArgument.Cwd = ca.Cwd hzArgument.Gosrc = ca.GoSrc diff --git a/pkg/client/kitex.go b/pkg/client/kitex.go index e2a5d73f..e91456fc 100644 --- a/pkg/client/kitex.go +++ b/pkg/client/kitex.go @@ -38,13 +38,7 @@ func convertKitexArgs(sa *config.ClientArgument, kitexArgument *kargs.Arguments) f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) kitexArgument.ModuleName = sa.GoMod - kitexArgument.ServiceName = sa.Service - if sa.Service != "" { - kitexArgument.ServiceName = sa.Service - } - if sa.ServerName != "" { - kitexArgument.ServiceName = sa.ServerName - } + kitexArgument.ServiceName = sa.ServerName kitexArgument.Includes = sa.SliceParam.ProtoSearchPath kitexArgument.Version = kitex.Version kitexArgument.RecordCmd = os.Args diff --git a/pkg/common/kx_registry/registry.go b/pkg/common/kx_registry/registry.go index c1d64a94..7f7d98f8 100644 --- a/pkg/common/kx_registry/registry.go +++ b/pkg/common/kx_registry/registry.go @@ -41,7 +41,7 @@ func HandleRegistry(ca *config.CommonParam, dir string) { te.Dependencies["github.com/kitex-contrib/registry-etcd"] = "etcd" te.ExtendServer = &generator.APIExtension{ ImportPaths: append(importPath, "github.com/kitex-contrib/registry-etcd", "github.com/cloudwego/kitex/pkg/rpcinfo"), - ExtendOption: fmt.Sprintf(etcdServer, ca.Service), + ExtendOption: fmt.Sprintf(etcdServer, ca.ServerName), } te.ExtendClient = &generator.APIExtension{ ImportPaths: append(importPath, "github.com/kitex-contrib/registry-etcd"), @@ -64,18 +64,18 @@ func HandleRegistry(ca *config.CommonParam, dir string) { te.Dependencies["github.com/cloudwego/kitex/pkg/registry"] = "registry" te.ExtendServer = &generator.APIExtension{ ImportPaths: []string{"github.com/cloudwego/kitex/pkg/registry", "github.com/kitex-contrib/registry-polaris", "github.com/cloudwego/kitex/pkg/klog"}, - ExtendOption: fmt.Sprintf(polarisServer, ca.Service), + ExtendOption: fmt.Sprintf(polarisServer, ca.ServerName), } te.ExtendClient = &generator.APIExtension{ ImportPaths: []string{"github.com/cloudwego/kitex/pkg/registry", "github.com/kitex-contrib/registry-polaris", "github.com/cloudwego/kitex/pkg/klog"}, - ExtendOption: fmt.Sprintf(polarisClient, ca.Service), + ExtendOption: fmt.Sprintf(polarisClient, ca.ServerName), } case consts.Nacos: te.Dependencies["github.com/kitex-contrib/registry-nacos/registry"] = "registry" te.Dependencies["github.com/kitex-contrib/registry-nacos/resolver"] = "resolver" te.ExtendServer = &generator.APIExtension{ ImportPaths: []string{"github.com/cloudwego/kitex/pkg/klog", "github.com/kitex-contrib/registry-nacos/registry", "github.com/cloudwego/kitex/pkg/rpcinfo"}, - ExtendOption: fmt.Sprintf(nacosServer, ca.Service), + ExtendOption: fmt.Sprintf(nacosServer, ca.ServerName), } te.ExtendClient = &generator.APIExtension{ ImportPaths: []string{"github.com/cloudwego/kitex/pkg/klog", "github.com/kitex-contrib/registry-nacos/resolver"}, diff --git a/pkg/server/check.go b/pkg/server/check.go index d8c92b76..0f372844 100644 --- a/pkg/server/check.go +++ b/pkg/server/check.go @@ -41,7 +41,7 @@ func check(sa *config.ServerArgument) error { return errors.New("unsupported registry") } - if sa.Service == "" && sa.ServerName == "" { + if sa.ServerName == "" { return errors.New("must specify server name") } diff --git a/pkg/server/hz.go b/pkg/server/hz.go index bc8c9f8c..057844a8 100644 --- a/pkg/server/hz.go +++ b/pkg/server/hz.go @@ -74,12 +74,7 @@ func convertHzArgument(sa *config.ServerArgument, hzArgument *hzConfig.Argument) hzArgument.IdlPaths = []string{abPath} hzArgument.Gomod = sa.GoMod - if sa.Service != "" { - hzArgument.ServiceName = sa.Service - } - if sa.ServerName != "" { - hzArgument.ServiceName = sa.ServerName - } + hzArgument.ServiceName = sa.ServerName hzArgument.OutDir = sa.OutDir hzArgument.Includes = sa.SliceParam.ProtoSearchPath hzArgument.Cwd = sa.Cwd diff --git a/pkg/server/kitex.go b/pkg/server/kitex.go index c221d214..50b4ae31 100644 --- a/pkg/server/kitex.go +++ b/pkg/server/kitex.go @@ -46,12 +46,7 @@ func convertKitexArgs(sa *config.ServerArgument, kitexArgument *kargs.Arguments) f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) kitexArgument.ModuleName = sa.GoMod - if sa.Service != "" { - kitexArgument.ServiceName = sa.Service - } - if sa.ServerName != "" { - kitexArgument.ServiceName = sa.ServerName - } + kitexArgument.ServiceName = sa.ServerName kitexArgument.Includes = sa.SliceParam.ProtoSearchPath kitexArgument.Version = kitex.Version kitexArgument.RecordCmd = os.Args From bde9f468905f99eb1e45085a6409dc729d2dea78 Mon Sep 17 00:00:00 2001 From: yuxialuozi <3159452953@qq.com> Date: Thu, 30 May 2024 19:49:16 +0800 Subject: [PATCH 3/3] fix:service parameter description --- cmd/static/client_flags.go | 2 +- cmd/static/server_flags.go | 2 +- config/server.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/static/client_flags.go b/cmd/static/client_flags.go index 38cd4796..d45c1230 100644 --- a/cmd/static/client_flags.go +++ b/cmd/static/client_flags.go @@ -25,7 +25,7 @@ import ( func clientFlags() []cli.Flag { globalArgs := config.GetGlobalArgs() return []cli.Flag{ - &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended)", Destination: &globalArgs.ClientArgument.ServerName}, + &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended,Deprecate in v0.2.0)", Destination: &globalArgs.ClientArgument.ServerName}, &cli.StringFlag{Name: consts.ServerName, Usage: "Specify the server name.", Destination: &globalArgs.ClientArgument.ServerName}, &cli.StringFlag{Name: consts.ServiceType, Usage: "Specify the generate type. (RPC or HTTP)", Value: consts.RPC}, &cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.ClientArgument.GoMod}, diff --git a/cmd/static/server_flags.go b/cmd/static/server_flags.go index 3774348e..e9f9510a 100644 --- a/cmd/static/server_flags.go +++ b/cmd/static/server_flags.go @@ -25,7 +25,7 @@ import ( func serverFlags() []cli.Flag { globalArgs := config.GetGlobalArgs() return []cli.Flag{ - &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended)", Destination: &globalArgs.ServerArgument.ServerName}, + &cli.StringFlag{Name: consts.Service, Usage: "Specify the server name.(Not recommended,Deprecate in v0.2.0)", Destination: &globalArgs.ServerArgument.ServerName}, &cli.StringFlag{Name: consts.ServerName, Usage: "Specify the server name.", Destination: &globalArgs.ServerArgument.ServerName}, &cli.StringFlag{Name: consts.ServiceType, Usage: "Specify the generate type. (RPC or HTTP)", Value: consts.RPC}, &cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod.", Destination: &globalArgs.ServerArgument.GoMod}, diff --git a/config/server.go b/config/server.go index 78a7af5f..f55d2243 100644 --- a/config/server.go +++ b/config/server.go @@ -40,7 +40,7 @@ type ServerArgument struct { } type CommonParam struct { - ServerName string //server name + ServerName string // server name Type string // GenerateType: RPC or HTTP GoMod string // Go Mod name IdlPath string