duanjie2940 2017-12-27 14:43
浏览 600

将gorm.Model字段集成到protobuf定义中

I am trying to figure out how to integrate the gorm.Model fields (deleted_at, create_at, id, etc) into my proto3 definitions. However, I can't a datetime type for proto3. I tried looking for documentation on how to serialize the gorm fields to strings (since proto3 handles strings) but I have not found anything.

Has anyone been able to successfully use the gorm model fields in their proto definitions? I'm using go-micro's plugin to generate *pb.go files.

Here's my current message definition which doesn't work. It seems like empty strings are being stored in the database for deleted_at since when querying for deleted_at is null the postgres database returns nothing.

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;
}

UPDATE: I've updated my proto def to the following but gorm still isn't properly using the Id, CreatedAt, UpdatedAt, and DeletedAt fields

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;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题