我试图弄清楚如何将gorm.Model字段(deleted_at,create_at,id等)集成到我的proto3定义中 . 但是,我不能为proto3设置日期时间类型 . 我试图寻找有关如何将gorm字段序列化为字符串的文档(因为proto3处理字符串)但我还没有找到任何东西 .

有没有人能够在他们的原型定义中成功使用gorm模型字段?我正在使用go-micro的插件来生成* pb.go文件 .

这是我当前的消息定义,它不起作用 . 似乎空字符串存储在数据库中为deleted_at,因为当查询deleted_at为null时,postgres数据库不返回任何内容 .

message DatabaseConfig {
    string address = 1;
    int32 port = 2;
    string databaseName = 3;
    string username = 4;
    string password = 5;
    string databaseType = 6;
    string quertStatement = 7;
    int32 id = 8;
    string createdAt = 9;
    string updatedAt = 10;
    string deletedAt = 11;
}

更新:我已将我的proto def更新为以下内容,但gorm仍未正确使用Id,CreatedAt,UpdatedAt和DeletedAt字段

syntax = "proto3";

package go.micro.srv.importer;

import "google/protobuf/timestamp.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";

service ImporterService {
    rpc CreateDatabaseConfig(DatabaseConfig) returns (Response) {}
    rpc RetrieveDatabaseConfig(GetRequest) returns (Response) {}
    rpc UpdateDatabaseConfig(DatabaseConfig) returns (Response) {}
    rpc DeleteDatabaseConfig(DatabaseConfig) returns (Response) {}
}


message GetRequest {}


message DatabaseConfig {
    string address = 1;
    int32 port = 2;
    string databaseName = 3;
    string username = 4;
    string password = 5;
    string databaseType = 6;
    string quertStatement = 7;
    int32 id = 8;
    google.protobuf.Timestamp createdAt = 9 [(gogoproto.stdtime) = true];
    google.protobuf.Timestamp updatedAt = 10 [(gogoproto.stdtime) = true];
    google.protobuf.Timestamp deletedAt = 11 [(gogoproto.stdtime) = true];
}


message Response {
    bool created = 1;
    DatabaseConfig database_config = 2;

    repeated DatabaseConfig databaseConfigs = 3;
}