diff --git a/cmd/protoc-gen-dyn-gin/gin.go b/cmd/protoc-gen-dyn-gin/gin.go index d0b3bb2..17d7f88 100644 --- a/cmd/protoc-gen-dyn-gin/gin.go +++ b/cmd/protoc-gen-dyn-gin/gin.go @@ -365,12 +365,19 @@ func lineComment(s string) string { return "" } b := &strings.Builder{} + first := true lines := strings.Split(strings.TrimSuffix(s, "\n"), "\n") - for i, line := range lines { - b.WriteString(strings.TrimSpace(strings.TrimPrefix(line, "//"))) - if i+1 < len(lines) { + for _, line := range lines { + ss := strings.TrimSpace(strings.TrimPrefix(line, "//")) + if ss == "" { + continue + } + if !first { b.WriteString(", ") + } else { + first = false } + b.WriteString(ss) } return b.String() } diff --git a/example/gen/hello/hello.gin.pb.go b/example/gen/hello/hello.gin.pb.go index b10cd64..bab3c94 100644 --- a/example/gen/hello/hello.gin.pb.go +++ b/example/gen/hello/hello.gin.pb.go @@ -25,6 +25,8 @@ const __Greeter_Metadata_Service = "The greeting service definition." // GreeterHTTPServer The greeting service definition. type GreeterHTTPServer interface { // SayHello Sends a hello + // + // 多一行 // I am a trailing comment SayHello(context.Context, *HelloRequest) (*HelloReply, error) // GetHello Get a hello @@ -34,7 +36,7 @@ type GreeterHTTPServer interface { func RegisterGreeterHTTPServer(g *gin.RouterGroup, srv GreeterHTTPServer) { r := g.Group("") { - r.POST("/v1/hello", http.MetadataInterceptor(http.Metadata{Service: __Greeter_Metadata_Service, Method: "Sends a hello"}), _Greeter_SayHello0_HTTP_Handler(srv)) + r.POST("/v1/hello", http.MetadataInterceptor(http.Metadata{Service: __Greeter_Metadata_Service, Method: "Sends a hello, 多一行"}), _Greeter_SayHello0_HTTP_Handler(srv)) r.GET("/v1/hello/:id", http.MetadataInterceptor(http.Metadata{Service: __Greeter_Metadata_Service, Method: "Get a hello"}), _Greeter_GetHello0_HTTP_Handler(srv)) } } diff --git a/example/gen/hello/hello.resty.pb.go b/example/gen/hello/hello.resty.pb.go index 69909fe..2b1bfab 100644 --- a/example/gen/hello/hello.resty.pb.go +++ b/example/gen/hello/hello.resty.pb.go @@ -20,6 +20,8 @@ var _ = http.NewClient // GreeterHTTPClient type GreeterHTTPClient interface { // SayHello Sends a hello + // + // 多一行 // I am a trailing comment SayHello(context.Context, *HelloRequest, ...http.CallOption) (*HelloReply, error) // GetHello Get a hello @@ -37,6 +39,8 @@ func NewGreeterHTTPClient(c *http.Client) GreeterHTTPClient { } // SayHello Sends a hello +// +// 多一行 // I am a trailing comment func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, req *HelloRequest, opts ...http.CallOption) (*HelloReply, error) { var err error diff --git a/example/gen/hello/hello_grpc.pb.go b/example/gen/hello/hello_grpc.pb.go index 62ccfc0..cf963f4 100644 --- a/example/gen/hello/hello_grpc.pb.go +++ b/example/gen/hello/hello_grpc.pb.go @@ -28,6 +28,8 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type GreeterClient interface { // Sends a hello + // + // 多一行 SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) // Get a hello GetHello(ctx context.Context, in *GetHelloRequest, opts ...grpc.CallOption) (*GetHelloReply, error) @@ -64,6 +66,8 @@ func (c *greeterClient) GetHello(ctx context.Context, in *GetHelloRequest, opts // for forward compatibility type GreeterServer interface { // Sends a hello + // + // 多一行 SayHello(context.Context, *HelloRequest) (*HelloReply, error) // Get a hello GetHello(context.Context, *GetHelloRequest) (*GetHelloReply, error) diff --git a/example/proto/hello/hello.proto b/example/proto/hello/hello.proto index 8f54f83..173e6a8 100644 --- a/example/proto/hello/hello.proto +++ b/example/proto/hello/hello.proto @@ -12,6 +12,8 @@ import "google/api/annotations.proto"; // The greeting service definition. service Greeter { // Sends a hello + // + // 多一行 rpc SayHello(HelloRequest) returns (HelloReply) { // I am a trailing comment option (google.api.http) = { post: "/v1/hello",