5

I have this struct in golang

struct File {
  name string
  creatation_time time.Time
}

How do I write it in protobuf3 ?

thanhpk
  • 3,900
  • 4
  • 29
  • 36

1 Answers1

4

Create example.proto;

syntax = "proto3";

import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"

message File {
    string name = 1;
    google.protobuf.Timestamp creatation_time = 2;  
}

After compilation check the example.pb.go for the structure definition that has been created.

  • 1
    which version of protoc are you using? I am is libprotoc 3.0.0, and I have to import "github.com/golang/protobuf/ptypes/timestamp/timestamp.proto", also it gives me *google_protobuf.Timestamp not golang standard time.Time – thanhpk Jun 09 '17 at 11:31
  • `import "google/protobuf/timestamp.proto";` worked for me – Matt Aug 03 '23 at 08:56