|
|
@ -16,8 +16,8 @@ import ( |
|
|
|
// CmdServer the service command.
|
|
|
|
// CmdServer the service command.
|
|
|
|
var CmdServer = &cobra.Command{ |
|
|
|
var CmdServer = &cobra.Command{ |
|
|
|
Use: "server", |
|
|
|
Use: "server", |
|
|
|
Short: "Generate the proto Server implementations", |
|
|
|
Short: "Generate the proto server implementations", |
|
|
|
Long: "Generate the proto Server implementations. Example: kratos proto server api/xxx.proto --target-dir=internal/service", |
|
|
|
Long: "Generate the proto server implementations. Example: kratos proto server api/xxx.proto --target-dir=internal/service", |
|
|
|
Run: run, |
|
|
|
Run: run, |
|
|
|
} |
|
|
|
} |
|
|
|
var targetDir string |
|
|
|
var targetDir string |
|
|
@ -64,8 +64,8 @@ func run(_ *cobra.Command, args []string) { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
cs.Methods = append(cs.Methods, &Method{ |
|
|
|
cs.Methods = append(cs.Methods, &Method{ |
|
|
|
Service: serviceName(s.Name), Name: serviceName(r.Name), Request: r.RequestType, |
|
|
|
Service: serviceName(s.Name), Name: serviceName(r.Name), Request: parametersName(r.RequestType), |
|
|
|
Reply: r.ReturnsType, Type: getMethodType(r.StreamsRequest, r.StreamsReturns), |
|
|
|
Reply: parametersName(r.ReturnsType), Type: getMethodType(r.StreamsRequest, r.StreamsReturns), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
res = append(res, cs) |
|
|
|
res = append(res, cs) |
|
|
@ -105,6 +105,10 @@ func getMethodType(streamsRequest, streamsReturns bool) MethodType { |
|
|
|
return unaryType |
|
|
|
return unaryType |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func parametersName(name string) string { |
|
|
|
|
|
|
|
return strings.ReplaceAll(name, ".", "_") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func serviceName(name string) string { |
|
|
|
func serviceName(name string) string { |
|
|
|
return toUpperCamelCase(strings.Split(name, ".")[0]) |
|
|
|
return toUpperCamelCase(strings.Split(name, ".")[0]) |
|
|
|
} |
|
|
|
} |
|
|
|