Google protobuf를 사용하는 코드가 있습니다.protobuf가 동일한 패키지를 인식하지 못합니다.
프로토 파일 : 다음은 소스 파일입니다
syntax = "proto3";
package my_package.protocol;
option go_package = "protocol";
import "github.com/golang/protobuf/ptypes/empty/empty.proto";
...
service MyService {
rpc Flush (google.protobuf.Empty) returns (google.protobuf.Empty);
}
컴파일 된 이동 파일 :
package protocol
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/ptypes/empty"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
...
type MyServiceClient interface {
Flush(ctx context.Context, in *google_protobuf.Empty, opts ...grpc.CallOption) (*google_protobuf.Empty, error)
}
그리고 마지막으로이 같은 컴파일 된 서비스를 사용하려고하면 :
import (
"golang.org/x/net/context"
pb "myproject/protocol"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
)
...
func Flush(sink pb.MyServiceClient) {
_, err = sink.Flush(context.Background(), *google_protobuf.Empty{})
...
}
을
다음 오류가 발생합니다.
Cannot use '*google_protobuf.Empty{}' (type "myproject/vendor/github.com/golang/protobuf/ptypes/empty".Empty) as type "myproject/vendor/github.com/golang/protobuf/ptypes/empty".*google_protobuf.Empty
동일한 내용 (동일한 파일로 해석되는 경우도 있음). 내가 여기서 무엇을 놓치고 있니?
_, err = sink.Flush(context.Background(), *google_protobuf.Empty{})
*google_protobuf.Empty{}
google_protobuf.Empty
에 대한 포인터를 기대 :
없는하시기 바랍니다 같은 오류가 분명하게 나타납니다. – Adrian