让我们从正式的文档中拿出这个例子
// Updates a book.
rpc UpdateBook(UpdateBookRequest) returns (Book) {
// Update maps to HTTP PATCH. Resource name is mapped to a URL path.
// Resource is contained in the HTTP request body.
option (google.api.http) = {
// Note the URL template variable which captures the resource name of the
// book to update.
patch: "/v1/{book.name=shelves/*/books/*}"
body: "book"
};
}
message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;
// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}如果我没有grpc网关并且只使用grpc,那么我是否可以这样使用掩码:
// Updates a book.
rpc UpdateBook(UpdateBookRequest) returns (Book);
message UpdateBookRequest {
// The book resource which replaces the resource on the server.
Book book = 1;
// The update mask applies to the resource. For the `FieldMask` definition,
// see https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask
FieldMask update_mask = 2;
}如果是这样的话,面具应该如何工作-过滤器请求?或者在数据库保存过程中应用,以及它是如何知道数据库的.所以我对使用它有点困惑。在我自己的grpc示例中,我看到这个掩码没有过滤请求。
发布于 2019-01-18 07:29:25
根据原型机文档
更新操作中的字段掩码 update操作中的字段掩码指定要更新目标资源的哪些字段。API只需要更改掩码中指定的字段的值,而其他字段则保持不变。如果传入资源来描述更新的值,API将忽略掩码未覆盖的所有字段的值。
应用字段掩码时,它指定要在gRPC请求中更新哪些特定字段。请记住,如果您在HTTP请求中使用它(据我收集的是您正在做的事情),则必须是修补程序请求,而不是PUT请求。
例如,假设您有一个名为Books的声明,其属性是:title作为字符串,year_published作为int32,author作为作者。声明Author的字段first_name为字符串,last_name为字符串。如果要使用author.first_name的字段掩码,则只更新book中的author字段。
请注意,这是基于protobufs文档的,我可能会完全误解它,所以请稍加考虑。
https://stackoverflow.com/questions/53948361
复制相似问题