1

私は現在、protobuf を使用して、残りの API ベースの go サービスを gRPC に移行する作業を行っています。私はインターネットからいくつかの例を使用しています。私のservice.protoファイルは次のようなものです

syntax = "proto3";
package v1;

import "google/protobuf/timestamp.proto";

// Taks we have to do
message ToDo {
    // Unique integer identifier of the todo task
    int64 id = 1;
    // Title of the task
    string title = 2;
    // Detail description of the todo task
    string description = 3;
    // Date and time to remind the todo task
    google.protobuf.Timestamp reminder = 4;
}

// Request data to create new todo task
message CreateRequest{
    // API versioning: it is my best practice to specify version explicitly
    string api = 1;

    // Task entity to add
    ToDo toDo = 2;
}

// Response that contains data for created todo task
message CreateResponse{
    // API versioning: it is my best practice to specify version explicitly
    string api = 1;

    // ID of created task
    int64 id = 2;
}

// Service to manage list of todo tasks
service ToDoService {
    // Create new todo task
    rpc Create(CreateRequest) returns (CreateResponse);
}

与えられたスニペットでは、すべてのリクエストとレスポンスを同じ .proto ファイルで定義していることがわかります。

これらをプロジェクト全体で使用できるように、これらを別の go ファイルで定義したいと考えています。その CreateRequest モデルも使用できるので、同じモデルを 2 回定義する必要はありません。

1)これを行うことは可能ですか?

2) はいの場合、正しい構文は何ですか?

私はこれに慣れていないので、質問がばかげているように見える場合は、大笑いして忘れてください。

4

1 に答える 1