go-kratos / kratos

Your ultimate Go microservices framework for the cloud-native era.
https://go-kratos.dev
MIT License
23.41k stars 4.01k forks source link

google.protobuf.Empty not generated correctly #2825

Closed jjkoh95 closed 1 year ago

jjkoh95 commented 1 year ago

What happened:

syntax = "proto3";

package helloworld.v1;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

option go_package = "x/api/helloworld/v1;v1";
option java_multiple_files = true;
option java_package = "dev.kratos.api.helloworld.v1";
option java_outer_classname = "HelloworldProtoV1";

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      get: "/helloworld/{name}"
    };
  }
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}
package service

import (
    "context"

    pb "x/api/helloworld/v1"
)

type GreeterService struct {
    pb.UnimplementedGreeterServer
}

func NewGreeterService() *GreeterService {
    return &GreeterService{}
}

func (s *GreeterService) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.google_protobuf_Empty, error) {
    return &pb.google_protobuf_Empty{}, nil
}

Using kratos proto server to generate server stub, it doesn't recognize google.protobuf.empty

What you expected to happen:

google.protobuf.Empty to be correctly recognized and use empty.pb instead.

How to reproduce it (as minimally and precisely as possible):

Run -- kratos new helloworld Modify api/helloworld/v1/greeter.proto to above Remove internal/service/greeter.go and run kratos proto server ./api/helloworld/v1/greeter.proto

Anything else we need to know?:

It was previously working, perhaps my local environment messed up some configs with kratos.

Environment:

henryjhenry commented 4 months ago

How did you solve this problem? In my case, kratos proto server generated service.go and import incorrectly: &pb.google_protobuf_Empty{}, pb is specified in proto option go_package = "pb"