如何通过 grpcurl 发送时间戳?
我正在使用 GRPC/proto-buffers 在 GoLang 中编写我的第一个 API 端点。我对 GoLang 比较陌生。以下是我为测试用例编写的文件package my_packageimport ( "context" "testing" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/structpb" "github.com/MyTeam/myproject/cmd/eventstream/setup" v1handler "github.com/MyTeam/myproject/internal/handlers/myproject/v1" v1interface "github.com/MyTeam/myproject/proto/.gen/go/myteam/myproject/v1")func TestEndpoint(t *testing.T) { conf := &setup.Config{} // Initialize our API handlers myhandler := v1handler.New(&v1handler.Config{}) t.Run("Success", func(t *testing.T) { res, err := myhandler.Endpoint(context.Background(), &v1interface.EndpointRequest{ A: "S", B: &structpb.Struct{ Fields: map[string]*structpb.Value{ "T": &structpb.Value{ Kind: &structpb.Value_StringValue{ StringValue: "U", }, }, "V": &structpb.Value{ Kind: &structpb.Value_StringValue{ StringValue: "W", }, }, }, }, C: ×tamppb.Timestamp{Seconds: 1590179525, Nanos: 0}, }) require.Nil(t, err) // Assert we got what we want. require.Equal(t, "Ok", res.Text) })}上面的测试用例似乎工作正常。但我想用 grpcurl 模拟同样的测试用例。这有效:grpcurl -d '{"a": "S", "b": {"T": "U", "V": "W"}}' -plaintext localhost:11000 myteam.myproject.v1.MyProject/Endpoint但是当我尝试以下操作时,它失败了:grpcurl -d '{"a": "S", "b": {"T": "U", "V": "W"}, "c": "1590179525"}' -plaintext localhost:11000 myteam.myproject.v1.MyProject/EndpointError invoking method "myteam.myproject.v1.MyProject/Endpoint": error getting request data: bad Timestamp: parsing time "1590179525" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "179525" as "-"如何通过 grpcurl 发送时间戳?
查看完整描述