如何使用google.protobuf.timestamp和cassandra

I'm using "google/protobuf/timestamp.proto" to define timestamp type in golang struct:

import "google/protobuf/timestamp.proto";    
message User {
    string id = 1; 
    ...
    google.protobuf.Timestamp created_at = 12;
    google.protobuf.Timestamp updated_at = 13;
    google.protobuf.Timestamp last_login = 14;
}

and when insert to cassandra using cqlx:

req.CreatedAt = ptypes.TimestampNow()
// I also try with:
// req.CreatedAt = &timestamp.Timestamp{Seconds: time.Now().Unix(), Nanos: int32(time.Now().Nanosecond())}

I always get this error message: can not marshal timestamp.Timestamp into timestamp. Anyone have work with this please help

I just ran into the same thing last week. You need to use ptypes

ts, err := ptypes.Timestamp(result.GetDateDone())
if err != nil {
    ts = time.Now().UTC()
}
err = trr.cassandra.Execute(query,
    result.TaskID,
    result.TaskName,
    result.Status,
    result.Result,
    ts,
    result.Traceback,
    result.Children,
)

Here result is a proto message defined by:

message TaskResult {
    string TaskID = 1;
    string TaskName = 2;
    string Status = 3;
    bytes Result = 4;
    google.protobuf.Timestamp DateDone = 5;
    bytes Traceback = 6;
    bytes Children = 7;
}

And the column family has a field

date_done timestamp,