Protobuf(gRPC)代码生成器,用于创建无效代码

当我的原始文件定义了具有 streaming </ em>响应的服务时,一切都将正常工作。 但是,当我返回一个单个</ em>值时,则生成的代码无效!</ p>

原始文件</ strong>:</ p>
\ n

  syntax =“ proto3”; 

package analyticsServicesGlobal;
option go_package =“ Generated / analyticsServices”;

service HealthCheck {
rpc Health(HealthCheckParam)返回(HealthCheckPayload){}
}

message HealthCheckPayload {
字符串消息= 1;
}

message HealthCheckParam {
字符串响应= 1;
}
</ code> </ pre>

代码生成完成没有问题: protoc --go_out = plugins = grpc:$ GOPATH / src / gauss minimal.proto </ code> </ p>

ide和命令行编译返回 生成的Go代码中的以下错误:</ p>

 。/minimal.pb.go:130:无法使用处理程序(类型func(“ gauss / vendor / golang.org / x  / net / context“。上下文,接口{})(接口{},错误)),类型为grpc.UnaryHandler,位于拦截器的参数中
./minimal.pb.go:139:无法使用_HealthCheck_Health_Handler(类型func(interface { },“高斯 /vendor/golang.org/x/net/context“。上下文,func(interface {})错误,grpc.UnaryServerInterceptor)(interface {},错误))作为字段值中的grpc.methodHandler类型
</ code> </ pre>

对于任何</ em>服务,返回非流响应的情况都会出现此问题。 我已经创建了这个最小的原始文件来演示,但是每个类似的服务定义都有相同的问题。</ p>

我在OS X上使用Go版本1.8.1, protoc </ code> 版本3.3.0,以及Go的最新协议插件 go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

由于缺乏有关此问题的报告,我确定我在</ em>做错了-但我不知道怎么办。 任何建议表示赞赏!</ p>
</ div>

展开原文

原文

Everything works when I have my proto file defining a service with a streaming response. However when I return a single value, then the generated code is invalid!

Proto File:

syntax = "proto3";

package analyticsServicesGlobal;
option go_package = "generated/analyticsServices";

service HealthCheck {
    rpc Health (HealthCheckParam) returns (HealthCheckPayload) {}
}

message HealthCheckPayload {
    string message = 1;
}

message HealthCheckParam {
    string response = 1;
}

The code generation completes without issue : protoc --go_out=plugins=grpc:$GOPATH/src/gauss minimal.proto

The ide and command line compilation return this error in the generated Go code though:

./minimal.pb.go:130: cannot use handler (type func("gauss/vendor/golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type grpc.UnaryHandler in argument to interceptor
./minimal.pb.go:139: cannot use _HealthCheck_Health_Handler (type func(interface {}, "gauss/vendor/golang.org/x/net/context".Context, func(interface {}) error, grpc.UnaryServerInterceptor) (interface {}, error)) as type grpc.methodHandler in field value

This issue shows up for any service where a non-stream response is returned. I have create this minimal proto file to demonstrate, but every similar service definition has the same issue.

I am on OSX using Go version 1.8.1, protoc version 3.3.0, and the latest protoc plugin for Go go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

I'm sure I'm doing something wrong given the lack of reports on this issue - but I don't see what. Any suggestions are appreciated!

dongtanzhu5417
dongtanzhu5417 是的-整理出来了!谢谢!!!!
大约 3 年之前 回复
doushan1863
doushan1863 删除目录gauss/vendor/golang.org/x/net/context
大约 3 年之前 回复
dongzong3053
dongzong3053 我不知道您是否需要更改gauss项目中的默认上下文包。golang.org/pkg/context
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
php方法在protobuf生成的类中未定义

<div class="post-text" itemprop="text"> <p>I am writing a client app to connect to the DA sandbox. The following code: </p> <pre><code>$grpc_channel = Grpc\ChannelCredentials::createInsecure(); $client = new Com\Digitalasset\Ledger\Api\V1\LedgerIdentityServiceClient('localhost:7600', [ 'credentials' =&gt; $grpc_channel, ]); $request = new Com\Digitalasset\Ledger\Api\V1\GetLedgerIdentityRequest(); $ledger_id_response = $client-&gt;GetLedgerIdentity($request); $ledger_id = $ledger_id_response-&gt;getLedgerId(); </code></pre> <p>causes the following error:</p> <pre><code>PHP Fatal error: Uncaught Error: Call to undefined method Grpc\UnaryCall::getLedgerId() in /.../damlprojects/loaner_car/php/ledger_client.php:31 </code></pre> <p>However, it should be defined since $ledger_id_response is of type GetLedgerIdentityResponse which does have a method:</p> <pre><code>public function getLedgerId() { return $this-&gt;ledger_id; } </code></pre> <p>What's causing the error?</p> </div>

如何使用gradle生成go grpc代码?

<div class="post-text" itemprop="text"> <p>My build.gradle is able to generate protobuf code for Go. What do I need to change to make it generate grpc code for the Go code?</p> <pre><code>apply plugin: 'com.google.protobuf' buildscript { dependencies { classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3' } } def grpcVersion = '1.11.0' dependencies { compile "io.grpc:grpc-netty:${grpcVersion}" compile "io.grpc:grpc-protobuf:${grpcVersion}" compile "io.grpc:grpc-stub:${grpcVersion}" } protobuf { protoc { artifact = "com.google.protobuf:protoc:3.5.1-1" } plugins { grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" } } generateProtoTasks { all().each { task -&gt; task.builtins { go { } } } all()*.plugins { grpc {} } } } </code></pre> </div>

使用protobuf简化对瘦golang api的grpc调用

<div class="post-text" itemprop="text"> <p>I am currently playing around with grpc on golang and trying to figure out the best way to make an extensible 'thin' api that i can use to pass all requests to their relevant services. </p> <p>I currently have the structure of: </p> <ul> <li>Service 1 <ul> <li>routes.go</li> <li>rpc.go</li> </ul></li> <li>Service 2 <ul> <li>routes.go</li> <li>rpc.go</li> </ul></li> </ul> <p>Within the routes files, it creates a new routeGroup that i then register in main, then each handler for a route parses any params etc into a protobuf request and calls a function within RPC:</p> <pre><code>func showFeed(c *gin.Context) { message, err := RpcFeedGet(&amp;social.ShowRequest{LocationId: 1}) resp := http.HttpResponse{c, "feed", err, message} http.ParseResponse(&amp;resp) //Checks if there is an error and handles response headers etc. } </code></pre> <p>Now within rpc im currently defining the below for each service which seems to be really inefficient to me as there is a lot of code reuse, how would i optimize/reduce the code reuse within this method</p> <pre><code>func connect() (*grpc.ClientConn, pb.Service1Client) { //Consul is being used for discovery, this just gets the address to dial consul := discovery.Init() service, err := consul.Lookup("service1", "") if err != nil { log.Fatalf("Unable to get service definition: %w", err) } //Dial the connection to the service conn, err := grpc.Dial(service.Address(), grpc.WithInsecure()) if err != nil { log.Fatalf("Unable to connect to client service: %v", err) } //Creates the service client (service1) and returns it client := pb.NewService1Client(conn) return conn, client } func RpcFeedGet(data *pb.ShowRequest) (string, error) { conn, client := connect() defer conn.Close() //This line calls the protobuf GetFeed rpc service resp, err := client.GetFeed(context.Background(), data) return rpcHelp.CheckResponse(resp, err) //Handles any errors returned } </code></pre> <p>Is there a way i can pass a function to a sub function that calls the connect/defer within the Rpc function and also normalise the <code>connect()</code> method so i dont have to redeclare it for each service? bearing in mind it returns a different client on each instance?</p> </div>

grpc protobuf用字符串创建新结构

<div class="post-text" itemprop="text"> <p>I'm using micro framework to develop my new project, and I have finished the GRPC work. But now, I need to write the gateway to interacting with the frontend. I don't really want to write repetitive code, and I find some code in <code>pb.go</code> file.</p> <p>the code is defined some struct and init function. like below:</p> <pre><code>type AuthLoginReq struct { Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } func init() { proto.RegisterType((*AuthLoginReq)(nil), "device.info.provider.service.AuthLoginReq") } </code></pre> <p>Meanwhile, I found this article <a href="https://stackoverflow.com/questions/23030884/is-there-a-way-to-create-an-instance-of-a-struct-from-a-string">is there a way to create an instance of a struct from a string?</a>. </p> <p>Fortunately. pb file already defines it for me, but protoc auto generate file is defined nil pointer <code>(*AuthLoginReq)(nil)</code>.</p> <p>api.go</p> <pre><code> qiniuType := proto.MessageType("device.info.provider.service.AuthLoginReq") pbValue := reflect.New(qiniuType) pbStruct := pbValue.Elem().Interface() </code></pre> <p>When I change pbSturct is not really change, because is nil pointer</p> <pre><code>ctx.ShouldBind(&amp;pbStruct) </code></pre> <p><code>pbStruct</code> is already change. but <code>pbValue</code> is not change. </p> <p>How do I change <code>pbValue</code>? </p> </div>

请教一下protobuf如何在eclipse生成java代码

我怎样才能把图片中的test.proto生成的java代码路径在src目录下。我看网上在cmd中执行的protoc.exe --java_out=./ test.proto之后是直接在proto目录下生成了Java代码。有没有什么好的办法能用eclipse把生成的Java代码放到src下。![图片说明](http://img.bbs.csdn.net/upload/201603/08/1457406916_655169.png)

gRPC直接发送protobuf格式

<div class="post-text" itemprop="text"> <p>I got an service where I also want to use protobuf for the storage system. So instead of serialize the object from a protobuf wire format, I just want to read the database and send this result direct as response. I already researched within the generated and grpc code but it is, at the moment, still a mystery how it works. I get the response from the database as type of []byte. How can I achieve this?</p> </div>

正确处理gRPC类型到SQL ORM

<div class="post-text" itemprop="text"> <p>I'm implementing a gRPC server and using an ORM called Boiler for Go. I've gotten to a point where I've built all my models and protos and now I'm handling specific type issues.</p> <p>Within my protobuf files I've declared most types as <code>strings</code>. However my ORM treats (due to how it interfaces with Postgres) strings as null.String in it's models. Hence when I attempt something like so I get an error:</p> <pre><code>user := &amp;models.User{ FirstName: req.FirstName, LastName: req.LastName, Email: req.Email, Gender: req.Gender, PhoneNumber: req.PhoneNumber, } </code></pre> <p>The error: <code>services/users.go:46:3: cannot use req.FirstName (type string) as type null.String in field value</code></p> <p>The question is what would be the most appropriate way of handling this situation. I could: generate a new struct (which I'm already using for data validation) and cast them into null.String or I suppose I could attempt to force the casting somehow?</p> <p>The question then becomes if a user doesn't supply a value in the API and the validation process allows it, how would that handle the non-existing record?</p> <p>Edit: Seems like SQLBoiler developers have a package for handling nulls separately. ie. <code>null.StringFrom()</code>, <code>null.Int15From</code> etc. which I'd in essence wrap all my fields with as such:</p> <pre><code>user := &amp;models.User{ FirstName: null.StringFrom(req.FirstName), LastName: null.StringFrom(req.LastName), Email: null.StringFrom(req.Email), Password: string(password_hash), Role: "BASIC_USER", Status: "ACTIVE", Gender: null.Int16From(req.Gender), PhoneNumber: null.StringFrom(req.PhoneNumber), VerificationCode: null.StringFrom(code.String()), } </code></pre> <p>Feels kind of dirty but I don't see any other options. Suggestions/opinions anyone?</p> </div>

将protobuf枚举消息发送到grpc服务器

<div class="post-text" itemprop="text"> <p>Given a</p> <pre><code>message Foo { enum State { STATE1 = 0; STATE2 = 1; STATE3 = 2; } } </code></pre> <p>and a grpc service definition of</p> <pre><code>rpc Method(stream Foo) returns (Empty) {} </code></pre> <p>What does the go grpc client code to send this to a grpc server look like? To clarify, suppose I have a <code>streamClient.Send()</code>. What would I pass to <code>Send()</code>? How do I construct the enum?</p> </div>

Protobuf Field Mask是否可以应用于仅grpc的情况?

<div class="post-text" itemprop="text"> <p>Let's take this example from the official <a href="https://cloud.google.com/apis/design/standard_methods#update" rel="noreferrer">doc</a>:</p> <pre><code>// Updates a book. rpc UpdateBook(UpdateBookRequest) returns (Book) { // Update maps to HTTP PATCH. Resource name is mapped to a URL path. // Resource is contained in the HTTP request body. option (google.api.http) = { // Note the URL template variable which captures the resource name of the // book to update. patch: "/v1/{book.name=shelves/*/books/*}" body: "book" }; } message UpdateBookRequest { // The book resource which replaces the resource on the server. Book book = 1; // The update mask applies to the resource. For the `FieldMask` definition, // see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask FieldMask update_mask = 2; } </code></pre> <p>If I don't have a grpc gateway and use grpc only, can I use mask in that way:</p> <pre><code>// Updates a book. rpc UpdateBook(UpdateBookRequest) returns (Book); message UpdateBookRequest { // The book resource which replaces the resource on the server. Book book = 1; // The update mask applies to the resource. For the `FieldMask` definition, // see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask FieldMask update_mask = 2; } </code></pre> <p>If so, how should that mask works - filters request? or be applied during db saving and how does it know about db ... So I am a bit confused about using it. In my own grpc sample I see that mask doesn't filter the request.</p> </div>

Google Protobuf依赖冲突

<div class="post-text" itemprop="text"> <p>I am working on a Golang library that leverages Google <a href="https://github.com/golang/protobuf" rel="nofollow noreferrer">Protobuf</a>. It does so by using code auto-generated by protoc-gen-go, the compiler plugin. I am using <a href="https://github.com/golang/dep" rel="nofollow noreferrer">Dep</a> for dependency management. The generated code exports the <code>InstanceStatusUpdate</code> struct, for which the field <code>Timestamp</code> is of the type <code>github.com/golang/protobuf/ptypes/timestamp.Timestamp</code>:</p> <pre><code>type InstanceStatusUpdate struct { EvaluationId string VariationId string AttemptNumber int32 Timestamp *google_protobuf.Timestamp Stage string Metadata string JobId string } </code></pre> <p>The problem I have is that writing library code to populate the Timestamp field triggers a redundant auto-importing of <code>"github.com/golang/protobuf/ptypes"</code>, since that is where the type that needs to be assigned to Timestamp lives. This redundancy causes this error:</p> <blockquote> <p>cannot use timestamp (type *"my_path/vendor/github.com/golang/protobuf/ptypes/timestamp".Timestamp) as type *"github.com/golang/protobuf/ptypes/timestamp".Timestamp in field value</p> </blockquote> <p>Any ideas? </p> <p>library structure (only one vendor folder):</p> <pre><code>code_root | -lib | | | -go-statuses -my_package /*Contains code that refers to the auto-generated code in | go-statuses*/ | -vendor </code></pre> </div>

如何解码被拦截的gRPC请求/响应,以查看golang中已发送/已接收的protobuf消息?

<div class="post-text" itemprop="text"> <p>I am intercepting the raw gRPC requests/responses going across a UNIX socket (the containerd socket using the <a href="https://github.com/kubernetes/cri-api" rel="nofollow noreferrer">cri-api</a>, using eBPF to perform the interception) and I want to work out what is being sent/received. I have access to the <a href="https://github.com/kubernetes/cri-api/blob/master/pkg/apis/runtime/v1alpha2/api.proto" rel="nofollow noreferrer">.proto</a> file used to generate the gRPC interface using the <a href="https://grpc.io/docs/quickstart/go/#generate-grpc-code" rel="nofollow noreferrer">gRPC plugin</a> so this should be possible to do but I'm not sure how to start as I am not part the gRPC connection.</p> <p>How can I go about doing this in golang? </p> </div>

Protobuf:如何获得方法的正确选项顺序?

<div class="post-text" itemprop="text"> <p>I am writing protoc plugin in Go which should generate documentation for our GRPC services and currently struggle in attempt to know right order of options. </p> <p>First, how the protobuf looks like</p> <pre><code> syntax = "proto3"; option go_package = "sample"; package sample import "common/extensions.proto" message SimpleMessage { // Id represents the message identifier. string id = 1; int64 num = 2; } message Response { int32 code = 1; } enum ErrorCodes { RESERVED = 0; OK = 200 ERROR = 6000 PANIC = 6001 } service EchoService { rpc Echo (SimpleMessage) returns (Response) { // common.grpc_status is an extension defined somewhere // these are list of possible return statuses option (common.grpc_status) = { status: "OK" status: "ERROR" status: "PANIC" // Every status string will must be one of ErrorCodes items }; option (common.middlewares) = { middleware: "csrf" middleware: "session" } } }; </code></pre> <p>As you see, there're two options here. The problem is <code>protoc</code> doesn't bind position directly to tokens. It leaves this information in a special sections where it can be restored via using so called "paths". And these paths are rely on order, while options are hidden and can only be retrieved using <code>proto.GetExtension</code> function which doesn't report option index either. I need this token location information to report errors. Is there any way to get option index or something equivalent?</p> <p>I am thinking about using standalone parser just to retrieve the right order, but this feels somewhat awkward. Hope there's a better way.</p> </div>

将内部go struct数组转换为protobuf生成的指针数组

<div class="post-text" itemprop="text"> <p>I'm trying to convert an internal type to the protobuf generated type and I can't get the array to convert. I'm new to go so I don't know all the methods that could help. But this is my attempt. When run this code I get</p> <blockquote> <p>panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x86c724]</p> </blockquote> <p>along with a lot other byte data. I'm wondering what the best way to convert internal structs to the protobufs is. I think I'm having the most trouble with the protobuf generated code being pointers.</p> <p>Proto Definitions</p> <pre><code>message GameHistory { message Game { int64 gameId = 1; } repeated Game matches = 1; string username = 2; } message GetRequest { string username = 1; } message GetGameResponse { GameHistory gameHistory = 1; } </code></pre> <p>Go Code</p> <pre><code>// GameHistory model type GameHistory struct { Game []struct { GameID int64 `json:"gameId"` } `json:"games"` UserName string `json:"username"` } func constructGameHistoryResponse(gameHistory models.GameHistory) *pb.GetGameResponse { games := make([]*pb.GameHistory_Game, len(gameHistory.Games)) for i := range matchHistory.Matches { games[i].GameID = gameHistory.Games[i].GameID } res := &amp;pb.GetGameResponse{ GameHistory: &amp;pb.GameHistory{ Games: games, }, } } </code></pre> </div>

生成Golang grpc +自定义原型对象

<div class="post-text" itemprop="text"> <p>I am trying to generate a gRPC client that returns a self defined proto object. This is my current proto command</p> <p><code>protoc -I.:../ --go_out=plugins=grpc:Muser/messages.proto=github.com/.../.../user:. messages.proto</code></p> <p>and this is the error <code>Muser/messages.proto=github.com/.../.../user:./: No such file or directory</code></p> <p>However this command:</p> <p><code>protoc -I.:../ --go_out=Muser/messages.proto=github.com/.../.../user:. messages.proto</code></p> <p>and this one:</p> <p><code>protoc -I.:../ --go_out=plugins=grpc:. messages.proto</code> </p> <p>work perfectly. The problem is when I try to use the <code>plugins:grpc</code> part in conjunction to the path of the <code>user/messages.proto</code> file.</p> <p>Any clue what the problem might be?</p> </div>

如何在gRPC中使用预定义的protobuf类型(即“ google / protobuf / timestamp.proto”)

<div class="post-text" itemprop="text"> <p>I'm trying to use <code>google/protobuf/timestamp.proto</code> in with gRPC plugin and Go. This is how I run <code>protoc</code>:</p> <pre><code>protoc -I ./ ./*.proto --go_out=plugins=grpc:. </code></pre> <p>And this is my <code>.proto</code>:</p> <pre><code>#domain.proto syntax = "proto3"; option java_multiple_files = true; option java_package = "com.viant.xyz"; option java_outer_classname = "domain"; import "google/protobuf/timestamp.proto"; message Foo { Timestamp modifiedTime = 1; ... } </code></pre> <p>I'm seeing the following errors:</p> <pre><code>domain.proto: Import "google/protobuf/timestamp.proto" was not found or had errors. domain.proto:44:5: "Timestamp" is not defined. </code></pre> <p>Am I missing something, or this is not yet supported?</p> </div>

是否应该将protobuf用作处理或仅用于传输的数据类型?

<div class="post-text" itemprop="text"> <p>I have a matrix struct written in Go. That matrix struct has a bunch of methods. I want to be able to efficiently compute matrix operations but I also want to be able to send it over the wire in order to distribute the computation.</p> <p>I currently have the matrix and its methods separate from the protobuf definition. When I need to send it over the wire I have to create a new <code>pb.Matrix{}</code> from the existing <code>Matrix{}</code> struct and then make my grpc call. That seems like a waste. So, is it a waste? And should I just be defining my matrix struct as a protobuf definition and then use embedding to define operations on it? Or is it better to keep them separate from each other?</p> </div>

用于golang和节点的gRPC protobuf文件设置

<div class="post-text" itemprop="text"> <p>I am trying to get a project going with gRPC that has the servers written in golang and the clients written in node</p> <p>I have a protobuf file structure like this</p> <pre><code>- $GOPATH/src/company/api |- server |- svc1 |- svc1.proto |- svc2 |- svc2.proto |- hardware |- hardware1 |- hardware1.proto |- hardware2 |- hardware2.proto |- lib |- used-by-both |- used-by-both.proto </code></pre> <p>When defining a service that uses something in the lib directory, I use <code>-I$GOPATH/src</code> then import using <code>import "company/api/lib/used-by-both";</code> in the proto file and that seems to work <strong>for golang</strong> when I generate everything.</p> <p>However, when I generate the node files, the import paths in the packages that depend on files from <code>lib</code> to be incorrect when the while <code>api</code> directory is installed as a node module</p> <p>If I try to make the <code>-I</code> option for the compiler more specific and shorten the <code>import</code> statement, the golang package import gets messed up </p> <p>Any advice on how best to compile these proto files in order to make use of them easliy as go packages <strong>and</strong> node modules? </p> </div>

如何row.Scan()int32进入Golang gRPC protobuf枚举字段?

<div class="post-text" itemprop="text"> <pre><code>// agent.proto message Agent { Permission permission = 1; google.protobuf.Timestamp born_time = 2; message Permission { Type type = 1; enum Type { KILLNONE = 0; KILLALL = 1; DANCE = 2; } } } </code></pre> <p>Then scanning SQL row into agent protobuf struct:</p> <pre><code>// main.go var a proto.Agent ..... ... row.Scan(&amp;a.Permission.Type,...) </code></pre> <p>That permission type is stored as simple MariaDB INT() <code>value = 0</code> for default type. So, i can't scan it directly. So i made temp struct where <code>Type int32</code> and scaned row into that temp struct after what tried to map temp struct fields to protobuf struct, but with no luck. Similar issues i had when want to scan MariaDB string values into []byte type fields but i solved that with my temp struct <code>[]byte(tmp.UUID)</code>.</p> <p>What is common patterns to scan database ROW (single row) into protubuf message when non-standard protobuf field types are used?</p> <p>EDIT: Does there should be some additional <code>0</code> value handling?</p> </div>

如何在monorepo中设置protobuf,grpc和Go模块?

<div class="post-text" itemprop="text"> <p>I'm trying to create a microservice-based API in Go, very basic, just to learn some stuff. I have three main goals I have to achieve.</p> <ol> <li>Monorepo.</li> <li>Be able to use different back-end languages as need arises (ie. one microservice in Go, two in Node.js, one in Python).</li> <li>Use gRPC.</li> </ol> <p>Currently my structure looks like this (and is stored in <code>~/Projects/tkg</code>, outside of GOPATH).</p> <p><a href="https://i.stack.imgur.com/oYOkn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oYOkn.png" alt="project structure"></a></p> <p>Each "service" should be a self-contained application written in a "whatever". As you can see I have a Go service and a React front-end application. Additionally there is a Makefile there that I want to use for building stuff, but I might move to shell scripts, Docker, whatever. Doesn't matter.</p> <p>So now the question. How can I make generated proto files play well with this setup? I think I don't understand something about Go modules and packages because I cannot set it so <code>articles.go</code> (from <code>cmd</code>) can access the generated <code>api/article.pb.go</code>. How to do it?</p> <pre class="lang-golang prettyprint-override"><code>// services/articles/go.mod module tkg/services/articles go 1.12 require ( github.com/golang/protobuf v1.3.2 google.golang.org/grpc v1.22.1 ) </code></pre> <pre class="lang-golang prettyprint-override"><code>// services/articles/cmd/article.go package main import ( pb "tkg/services/articles/api/article" ) type repository interface { Create(*pb.Article) (*pb.Article, error) } func main() { } </code></pre> <pre class="lang-proto prettyprint-override"><code>// services/articles/api/article.proto syntax = "proto3"; package article; option go_package = "tkg/services/articles/api/article"; ... </code></pre> <pre><code>// Makefile build: protoc services/articles/api/article.proto --go_out=. </code></pre> <p>I have tried various different package names in go.mod, different go_packages in the proto file, I had tried different protoc commands and paths. I bet this is silly and it's very obvious to someone who is well-versed in Go, but for someone from Node.js backgroud like me the inability to do <code>import "../api/article.pb.go"</code> is infuriating. :(</p> <p>The error I am getting is: <code>could not import tkg/services/articles/api/article (no parsed files for package tkg/services/articles/api/article)</code>. Of course with different values for package names. I've been trying to solve it for two days now.</p> <p>How would you approach this problem?</p> </div>

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

课程主要面向嵌入式Linux初学者、工程师、学生 主要从一下几方面进行讲解: 1.linux学习路线、基本命令、高级命令 2.shell、vi及vim入门讲解 3.软件安装下载、NFS、Samba、FTP等服务器配置及使用

我以为我对Mysql事务很熟,直到我遇到了阿里面试官

太惨了,面试又被吊打

Python代码实现飞机大战

文章目录经典飞机大战一.游戏设定二.我方飞机三.敌方飞机四.发射子弹五.发放补给包六.主模块 经典飞机大战 源代码以及素材资料(图片,音频)可从下面的github中下载: 飞机大战源代码以及素材资料github项目地址链接 ————————————————————————————————————————————————————————— 不知道大家有没有打过飞机,喜不喜欢打飞机。当我第一次接触这个东西的时候,我的内心是被震撼到的。第一次接触打飞机的时候作者本人是身心愉悦的,因为周边的朋友都在打飞机, 每

Python数据分析与挖掘

92讲视频课+16大项目实战+源码+¥800元课程礼包+讲师社群1V1答疑+社群闭门分享会=99元 &nbsp; 为什么学习数据分析? &nbsp; &nbsp; &nbsp; 人工智能、大数据时代有什么技能是可以运用在各种行业的?数据分析就是。 &nbsp; &nbsp; &nbsp; 从海量数据中获得别人看不见的信息,创业者可以通过数据分析来优化产品,营销人员可以通过数据分析改进营销策略,产品经理可以通过数据分析洞察用户习惯,金融从业者可以通过数据分析规避投资风险,程序员可以通过数据分析进一步挖掘出数据价值,它和编程一样,本质上也是一个工具,通过数据来对现实事物进行分析和识别的能力。不管你从事什么行业,掌握了数据分析能力,往往在其岗位上更有竞争力。 &nbsp;&nbsp; 本课程共包含五大模块: 一、先导篇: 通过分析数据分析师的一天,让学员了解全面了解成为一个数据分析师的所有必修功法,对数据分析师不在迷惑。 &nbsp; 二、基础篇: 围绕Python基础语法介绍、数据预处理、数据可视化以及数据分析与挖掘......这些核心技能模块展开,帮助你快速而全面的掌握和了解成为一个数据分析师的所有必修功法。 &nbsp; 三、数据采集篇: 通过网络爬虫实战解决数据分析的必经之路:数据从何来的问题,讲解常见的爬虫套路并利用三大实战帮助学员扎实数据采集能力,避免没有数据可分析的尴尬。 &nbsp; 四、分析工具篇: 讲解数据分析避不开的科学计算库Numpy、数据分析工具Pandas及常见可视化工具Matplotlib。 &nbsp; 五、算法篇: 算法是数据分析的精华,课程精选10大算法,包括分类、聚类、预测3大类型,每个算法都从原理和案例两个角度学习,让你不仅能用起来,了解原理,还能知道为什么这么做。

如何在虚拟机VM上使用串口

在系统内核开发中,经常会用到串口调试,利用VMware的Virtual Machine更是为调试系统内核如虎添翼。那么怎么搭建串口调试环境呢?因为最近工作涉及到这方面,利用强大的google搜索和自己

程序员的兼职技能课

获取讲师答疑方式: 在付费视频第一节(触摸命令_ALL)片头有二维码及加群流程介绍 限时福利 原价99元,今日仅需39元!购课添加小助手(微信号:csdn590)按提示还可领取价值800元的编程大礼包! 讲师介绍: 苏奕嘉&nbsp;前阿里UC项目工程师 脚本开发平台官方认证满级(六级)开发者。 我将如何教会你通过【定制脚本】赚到你人生的第一桶金? 零基础程序定制脚本开发课程,是完全针对零脚本开发经验的小白而设计,课程内容共分为3大阶段: ①前期将带你掌握Q开发语言和界面交互开发能力; ②中期通过实战来制作有具体需求的定制脚本; ③后期将解锁脚本的更高阶玩法,打通任督二脉; ④应用定制脚本合法赚取额外收入的完整经验分享,带你通过程序定制脚本开发这项副业,赚取到你的第一桶金!

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

C++语言基础视频教程

C++语言基础视频培训课程:本课与主讲者在大学开出的程序设计课程直接对接,准确把握知识点,注重教学视频与实践体系的结合,帮助初学者有效学习。本教程详细介绍C++语言中的封装、数据隐藏、继承、多态的实现等入门知识;主要包括类的声明、对象定义、构造函数和析构函数、运算符重载、继承和派生、多态性实现等。 课程需要有C语言程序设计的基础(可以利用本人开出的《C语言与程序设计》系列课学习)。学习者能够通过实践的方式,学会利用C++语言解决问题,具备进一步学习利用C++开发应用程序的基础。

北京师范大学信息科学与技术学院笔试10复试真题

北京师范大学信息科学与技术学院笔试,可以更好的让你了解北师大该学院的复试内容,获得更好的成绩。

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

本课程适合CCNA或HCNA网络小白同志,高手请绕道,可以直接学习进价课程。通过本预科课程的学习,为学习网络工程师、思科CCNA、华为HCNA这些认证打下坚实的基础! 重要!思科认证2020年2月24日起,已启用新版认证和考试,包括题库都会更新,由于疫情原因,请关注官网和本地考点信息。题库网络上很容易下载到。

Python界面版学生管理系统

前不久上传了一个控制台版本的学生管理系统,这个是Python界面版学生管理系统,这个是使用pycharm开发的一个有界面的学生管理系统,基本的增删改查,里面又演示视频和完整代码,有需要的伙伴可以自行下

软件测试2小时入门

本课程内容系统、全面、简洁、通俗易懂,通过2个多小时的介绍,让大家对软件测试有个系统的理解和认识,具备基本的软件测试理论基础。 主要内容分为5个部分: 1 软件测试概述,了解测试是什么、测试的对象、原则、流程、方法、模型;&nbsp; 2.常用的黑盒测试用例设计方法及示例演示;&nbsp; 3 常用白盒测试用例设计方法及示例演示;&nbsp; 4.自动化测试优缺点、使用范围及示例‘;&nbsp; 5.测试经验谈。

Tomcat服务器下载、安装、配置环境变量教程(超详细)

未经我的允许,请不要转载我的文章,在此郑重声明!!! 请先配置安装好Java的环境,若没有安装,请参照我博客上的步骤进行安装! 安装Java环境教程https://blog.csdn.net/qq_40881680/article/details/83585542 Tomcat部署Web项目(一)·内嵌https://blog.csdn.net/qq_40881680/article/d...

2019数学建模A题高压油管的压力控制 省一论文即代码

2019数学建模A题高压油管的压力控制省一完整论文即详细C++和Matlab代码,希望对同学们有所帮助

图书管理系统(Java + Mysql)我的第一个完全自己做的实训项目

图书管理系统 Java + MySQL 完整实训代码,MVC三层架构组织,包含所有用到的图片资源以及数据库文件,大三上学期实训,注释很详细,按照阿里巴巴Java编程规范编写

linux下利用/proc进行进程树的打印

在linux下利用c语言实现的进程树的打印,主要通过/proc下的目录中的进程文件,获取status中的进程信息内容,然后利用递归实现进程树的打印

微信小程序开发实战之番茄时钟开发

微信小程序番茄时钟视频教程,本课程将带着各位学员开发一个小程序初级实战类项目,针对只看过官方文档而又无从下手的开发者来说,可以作为一个较好的练手项目,对于有小程序开发经验的开发者而言,可以更好加深对小程序各类组件和API 的理解,为更深层次高难度的项目做铺垫。

[已解决]踩过的坑之mysql连接报“Communications link failure”错误

目录 前言 第一种方法: 第二种方法 第三种方法(适用于项目和数据库在同一台服务器) 第四种方法 第五种方法(项目和数据库不在同一台服务器) 总结 前言 先给大家简述一下我的坑吧,(我用的是mysql,至于oracle有没有这样的问题,有心的小伙伴们可以测试一下哈), 在自己做个javaweb测试项目的时候,因为买的是云服务器,所以数据库连接的是用ip地址,用IDE开发好...

人工智能-计算机视觉实战之路(必备算法+深度学习+项目实战)

系列课程主要分为3大阶段:(1)首先掌握计算机视觉必备算法原理,结合Opencv进行学习与练手,通过实际视项目进行案例应用展示。(2)进军当下最火的深度学习进行视觉任务实战,掌握深度学习中必备算法原理与网络模型架构。(3)结合经典深度学习框架与实战项目进行实战,基于真实数据集展开业务分析与建模实战。整体风格通俗易懂,项目驱动学习与就业面试。 建议同学们按照下列顺序来进行学习:1.Python入门视频课程 2.Opencv计算机视觉实战(Python版) 3.深度学习框架-PyTorch实战/人工智能框架实战精讲:Keras项目 4.Python-深度学习-物体检测实战 5.后续实战课程按照自己喜好选择就可以

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

Python数据分析师-实战系列

系列课程主要包括Python数据分析必备工具包,数据分析案例实战,核心算法实战与企业级数据分析与建模解决方案实战,建议大家按照系列课程阶段顺序进行学习。所有数据集均为企业收集的真实数据集,整体风格以实战为导向,通俗讲解Python数据分析核心技巧与实战解决方案。

YOLOv3目标检测实战系列课程

《YOLOv3目标检测实战系列课程》旨在帮助大家掌握YOLOv3目标检测的训练、原理、源码与网络模型改进方法。 本课程的YOLOv3使用原作darknet(c语言编写),在Ubuntu系统上做项目演示。 本系列课程包括三门课: (1)《YOLOv3目标检测实战:训练自己的数据集》 包括:安装darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 (2)《YOLOv3目标检测:原理与源码解析》讲解YOLOv1、YOLOv2、YOLOv3的原理、程序流程并解析各层的源码。 (3)《YOLOv3目标检测:网络模型改进方法》讲解YOLOv3的改进方法,包括改进1:不显示指定类别目标的方法 (增加功能) ;改进2:合并BN层到卷积层 (加快推理速度) ; 改进3:使用GIoU指标和损失函数 (提高检测精度) ;改进4:tiny YOLOv3 (简化网络模型)并介绍 AlexeyAB/darknet项目。

2021考研数学张宇基础30讲.pdf

张宇:博士,全国著名考研数学辅导专家,教育部“国家精品课程建设骨干教师”,全国畅销书《张宇高等数学18讲》《张宇线性代数9讲》《张宇概率论与数理统计9讲》《张宇考研数学题源探析经典1000题》《张宇考

三个项目玩转深度学习(附1G源码)

从事大数据与人工智能开发与实践约十年,钱老师亲自见证了大数据行业的发展与人工智能的从冷到热。事实证明,计算机技术的发展,算力突破,海量数据,机器人技术等,开启了第四次工业革命的序章。深度学习图像分类一直是人工智能的经典任务,是智慧零售、安防、无人驾驶等机器视觉应用领域的核心技术之一,掌握图像分类技术是机器视觉学习的重中之重。针对现有线上学习的特点与实际需求,我们开发了人工智能案例实战系列课程。打造:以项目案例实践为驱动的课程学习方式,覆盖了智能零售,智慧交通等常见领域,通过基础学习、项目案例实践、社群答疑,三维立体的方式,打造最好的学习效果。

DirectX修复工具V4.0增强版

DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复

期末考试评分标准的数学模型

大学期末考试与高中的考试存在很大的不同之处,大学的期末考试成绩是主要分为两个部分:平时成绩和期末考试成绩。平时成绩和期末考试成绩总分一般为一百分,然而平时成绩与期末考试成绩所占的比例不同会导致出现不同

Vue.js 2.0之全家桶系列视频课程

基于新的Vue.js 2.3版本, 目前新全的Vue.js教学视频,让你少走弯路,直达技术前沿! 1. 包含Vue.js全家桶(vue.js、vue-router、axios、vuex、vue-cli、webpack、ElementUI等) 2. 采用笔记+代码案例的形式讲解,通俗易懂

c语言项目开发实例

十个c语言案例 (1)贪吃蛇 (2)五子棋游戏 (3)电话薄管理系统 (4)计算器 (5)万年历 (6)电子表 (7)客户端和服务器通信 (8)潜艇大战游戏 (9)鼠标器程序 (10)手机通讯录系统

相关热词 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行 c# 循环给数组插入数据 c# 多线程死锁的例子 c# 钉钉读取员工排班 c# label 不显示 c#裁剪影像 c#工作进程更新ui
立即提问