Rajesh kumar
Rajesh kumar

Reputation: 362

Import timestamp in proto file of protobuf for GRPC

I am trying to use gRPC and using the exchange message format as protobuf. I wanted to add timestamp field inside my message.But i don't know the right way to add the import statement in proto file. I am using Golang so I need an output as .pb.go

Upvotes: 18

Views: 36961

Answers (4)

Sergeenho
Sergeenho

Reputation: 429

Make sure to import in your proto file:

import "google/protobuf/timestamp.proto";

And use the type for you variable like:

google.protobuf.Timestamp time_name = 1;

Upvotes: 36

Eric Anderson
Eric Anderson

Reputation: 26394

In your proto file:

import "google/protobuf/timestamp.proto"

Based on the documentation, that should be all that's necessary.

Upvotes: 2

Carl Mastrangelo
Carl Mastrangelo

Reputation: 6628

You can import timestamp from the ptypes package: in the standard Go Protobuf repo.

import (
    "github.com/golang/protobuf/ptypes/timestamp"
)

Upvotes: 0

weismat
weismat

Reputation: 7411

Grpc does not have a timestamp AFAIK.
I usually use the Unix Epoch - the go function

 Unix(sec int64, nsec int64)

and

func (t Time) Unix() int64

is your fried

Upvotes: -1

Related Questions