| 1 |
// Copyright 2025 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| 16 |
|
| 17 |
package tables |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
tablespb "cloud.google.com/go/area120/tables/apiv1alpha1/tablespb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
gtransport "google.golang.org/api/transport/grpc" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/protobuf/encoding/protojson" |
| 38 |
"google.golang.org/protobuf/proto" |
| 39 |
) |
| 40 |
|
| 41 |
var newClientHook clientHook |
| 42 |
|
| 43 |
// CallOptions contains the retry settings for each method of Client. |
| 44 |
type CallOptions struct { |
| 45 |
GetTable []gax.CallOption |
| 46 |
ListTables []gax.CallOption |
| 47 |
GetWorkspace []gax.CallOption |
| 48 |
ListWorkspaces []gax.CallOption |
| 49 |
GetRow []gax.CallOption |
| 50 |
ListRows []gax.CallOption |
| 51 |
CreateRow []gax.CallOption |
| 52 |
BatchCreateRows []gax.CallOption |
| 53 |
UpdateRow []gax.CallOption |
| 54 |
BatchUpdateRows []gax.CallOption |
| 55 |
DeleteRow []gax.CallOption |
| 56 |
BatchDeleteRows []gax.CallOption |
| 57 |
} |
| 58 |
|
| 59 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 60 |
return []option.ClientOption{ |
| 61 |
internaloption.WithDefaultEndpoint("area120tables.googleapis.com:443"), |
| 62 |
internaloption.WithDefaultEndpointTemplate("area120tables.UNIVERSE_DOMAIN:443"), |
| 63 |
internaloption.WithDefaultMTLSEndpoint("area120tables.mtls.googleapis.com:443"), |
| 64 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 65 |
internaloption.WithDefaultAudience("https://area120tables.googleapis.com/"), |
| 66 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 67 |
internaloption.EnableJwtWithScope(), |
| 68 |
internaloption.EnableNewAuthLibrary(), |
| 69 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 70 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
func defaultCallOptions() *CallOptions { |
| 75 |
return &CallOptions{ |
| 76 |
GetTable: []gax.CallOption{ |
| 77 |
gax.WithTimeout(60000 * time.Millisecond), |
| 78 |
}, |
| 79 |
ListTables: []gax.CallOption{ |
| 80 |
gax.WithTimeout(60000 * time.Millisecond), |
| 81 |
}, |
| 82 |
GetWorkspace: []gax.CallOption{ |
| 83 |
gax.WithTimeout(60000 * time.Millisecond), |
| 84 |
}, |
| 85 |
ListWorkspaces: []gax.CallOption{ |
| 86 |
gax.WithTimeout(60000 * time.Millisecond), |
| 87 |
}, |
| 88 |
GetRow: []gax.CallOption{ |
| 89 |
gax.WithTimeout(60000 * time.Millisecond), |
| 90 |
}, |
| 91 |
ListRows: []gax.CallOption{ |
| 92 |
gax.WithTimeout(60000 * time.Millisecond), |
| 93 |
}, |
| 94 |
CreateRow: []gax.CallOption{ |
| 95 |
gax.WithTimeout(60000 * time.Millisecond), |
| 96 |
}, |
| 97 |
BatchCreateRows: []gax.CallOption{ |
| 98 |
gax.WithTimeout(60000 * time.Millisecond), |
| 99 |
}, |
| 100 |
UpdateRow: []gax.CallOption{ |
| 101 |
gax.WithTimeout(60000 * time.Millisecond), |
| 102 |
}, |
| 103 |
BatchUpdateRows: []gax.CallOption{ |
| 104 |
gax.WithTimeout(60000 * time.Millisecond), |
| 105 |
}, |
| 106 |
DeleteRow: []gax.CallOption{ |
| 107 |
gax.WithTimeout(60000 * time.Millisecond), |
| 108 |
}, |
| 109 |
BatchDeleteRows: []gax.CallOption{ |
| 110 |
gax.WithTimeout(60000 * time.Millisecond), |
| 111 |
}, |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
func defaultRESTCallOptions() *CallOptions { |
| 116 |
return &CallOptions{ |
| 117 |
GetTable: []gax.CallOption{ |
| 118 |
gax.WithTimeout(60000 * time.Millisecond), |
| 119 |
}, |
| 120 |
ListTables: []gax.CallOption{ |
| 121 |
gax.WithTimeout(60000 * time.Millisecond), |
| 122 |
}, |
| 123 |
GetWorkspace: []gax.CallOption{ |
| 124 |
gax.WithTimeout(60000 * time.Millisecond), |
| 125 |
}, |
| 126 |
ListWorkspaces: []gax.CallOption{ |
| 127 |
gax.WithTimeout(60000 * time.Millisecond), |
| 128 |
}, |
| 129 |
GetRow: []gax.CallOption{ |
| 130 |
gax.WithTimeout(60000 * time.Millisecond), |
| 131 |
}, |
| 132 |
ListRows: []gax.CallOption{ |
| 133 |
gax.WithTimeout(60000 * time.Millisecond), |
| 134 |
}, |
| 135 |
CreateRow: []gax.CallOption{ |
| 136 |
gax.WithTimeout(60000 * time.Millisecond), |
| 137 |
}, |
| 138 |
BatchCreateRows: []gax.CallOption{ |
| 139 |
gax.WithTimeout(60000 * time.Millisecond), |
| 140 |
}, |
| 141 |
UpdateRow: []gax.CallOption{ |
| 142 |
gax.WithTimeout(60000 * time.Millisecond), |
| 143 |
}, |
| 144 |
BatchUpdateRows: []gax.CallOption{ |
| 145 |
gax.WithTimeout(60000 * time.Millisecond), |
| 146 |
}, |
| 147 |
DeleteRow: []gax.CallOption{ |
| 148 |
gax.WithTimeout(60000 * time.Millisecond), |
| 149 |
}, |
| 150 |
BatchDeleteRows: []gax.CallOption{ |
| 151 |
gax.WithTimeout(60000 * time.Millisecond), |
| 152 |
}, |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
// internalClient is an interface that defines the methods available from Area120 Tables API. |
| 157 |
type internalClient interface { |
| 158 |
Close() error |
| 159 |
setGoogleClientInfo(...string) |
| 160 |
Connection() *grpc.ClientConn |
| 161 |
GetTable(context.Context, *tablespb.GetTableRequest, ...gax.CallOption) (*tablespb.Table, error) |
| 162 |
ListTables(context.Context, *tablespb.ListTablesRequest, ...gax.CallOption) *TableIterator |
| 163 |
GetWorkspace(context.Context, *tablespb.GetWorkspaceRequest, ...gax.CallOption) (*tablespb.Workspace, error) |
| 164 |
ListWorkspaces(context.Context, *tablespb.ListWorkspacesRequest, ...gax.CallOption) *WorkspaceIterator |
| 165 |
GetRow(context.Context, *tablespb.GetRowRequest, ...gax.CallOption) (*tablespb.Row, error) |
| 166 |
ListRows(context.Context, *tablespb.ListRowsRequest, ...gax.CallOption) *RowIterator |
| 167 |
CreateRow(context.Context, *tablespb.CreateRowRequest, ...gax.CallOption) (*tablespb.Row, error) |
| 168 |
BatchCreateRows(context.Context, *tablespb.BatchCreateRowsRequest, ...gax.CallOption) (*tablespb.BatchCreateRowsResponse, error) |
| 169 |
UpdateRow(context.Context, *tablespb.UpdateRowRequest, ...gax.CallOption) (*tablespb.Row, error) |
| 170 |
BatchUpdateRows(context.Context, *tablespb.BatchUpdateRowsRequest, ...gax.CallOption) (*tablespb.BatchUpdateRowsResponse, error) |
| 171 |
DeleteRow(context.Context, *tablespb.DeleteRowRequest, ...gax.CallOption) error |
| 172 |
BatchDeleteRows(context.Context, *tablespb.BatchDeleteRowsRequest, ...gax.CallOption) error |
| 173 |
} |
| 174 |
|
| 175 |
// Client is a client for interacting with Area120 Tables API. |
| 176 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 177 |
// |
| 178 |
// The Tables Service provides an API for reading and updating tables. |
| 179 |
// It defines the following resource model: |
| 180 |
// |
| 181 |
// The API has a collection of [Table][google.area120.tables.v1alpha1.Table] |
| 182 |
// resources, named tables/* |
| 183 |
// |
| 184 |
// Each Table has a collection of [Row][google.area120.tables.v1alpha1.Row] |
| 185 |
// resources, named tables/*/rows/* |
| 186 |
// |
| 187 |
// The API has a collection of |
| 188 |
// [Workspace][google.area120.tables.v1alpha1.Workspace] |
| 189 |
// resources, named workspaces/*. |
| 190 |
type Client struct { |
| 191 |
// The internal transport-dependent client. |
| 192 |
internalClient internalClient |
| 193 |
|
| 194 |
// The call options for this service. |
| 195 |
CallOptions *CallOptions |
| 196 |
} |
| 197 |
|
| 198 |
// Wrapper methods routed to the internal client. |
| 199 |
|
| 200 |
// Close closes the connection to the API service. The user should invoke this when |
| 201 |
// the client is no longer required. |
| 202 |
func (c *Client) Close() error { |
| 203 |
return c.internalClient.Close() |
| 204 |
} |
| 205 |
|
| 206 |
// setGoogleClientInfo sets the name and version of the application in |
| 207 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 208 |
// use by Google-written clients. |
| 209 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 210 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 211 |
} |
| 212 |
|
| 213 |
// Connection returns a connection to the API service. |
| 214 |
// |
| 215 |
// Deprecated: Connections are now pooled so this method does not always |
| 216 |
// return the same resource. |
| 217 |
func (c *Client) Connection() *grpc.ClientConn { |
| 218 |
return c.internalClient.Connection() |
| 219 |
} |
| 220 |
|
| 221 |
// GetTable gets a table. Returns NOT_FOUND if the table does not exist. |
| 222 |
func (c *Client) GetTable(ctx context.Context, req *tablespb.GetTableRequest, opts ...gax.CallOption) (*tablespb.Table, error) { |
| 223 |
return c.internalClient.GetTable(ctx, req, opts...) |
| 224 |
} |
| 225 |
|
| 226 |
// ListTables lists tables for the user. |
| 227 |
func (c *Client) ListTables(ctx context.Context, req *tablespb.ListTablesRequest, opts ...gax.CallOption) *TableIterator { |
| 228 |
return c.internalClient.ListTables(ctx, req, opts...) |
| 229 |
} |
| 230 |
|
| 231 |
// GetWorkspace gets a workspace. Returns NOT_FOUND if the workspace does not exist. |
| 232 |
func (c *Client) GetWorkspace(ctx context.Context, req *tablespb.GetWorkspaceRequest, opts ...gax.CallOption) (*tablespb.Workspace, error) { |
| 233 |
return c.internalClient.GetWorkspace(ctx, req, opts...) |
| 234 |
} |
| 235 |
|
| 236 |
// ListWorkspaces lists workspaces for the user. |
| 237 |
func (c *Client) ListWorkspaces(ctx context.Context, req *tablespb.ListWorkspacesRequest, opts ...gax.CallOption) *WorkspaceIterator { |
| 238 |
return c.internalClient.ListWorkspaces(ctx, req, opts...) |
| 239 |
} |
| 240 |
|
| 241 |
// GetRow gets a row. Returns NOT_FOUND if the row does not exist in the table. |
| 242 |
func (c *Client) GetRow(ctx context.Context, req *tablespb.GetRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 243 |
return c.internalClient.GetRow(ctx, req, opts...) |
| 244 |
} |
| 245 |
|
| 246 |
// ListRows lists rows in a table. Returns NOT_FOUND if the table does not exist. |
| 247 |
func (c *Client) ListRows(ctx context.Context, req *tablespb.ListRowsRequest, opts ...gax.CallOption) *RowIterator { |
| 248 |
return c.internalClient.ListRows(ctx, req, opts...) |
| 249 |
} |
| 250 |
|
| 251 |
// CreateRow creates a row. |
| 252 |
func (c *Client) CreateRow(ctx context.Context, req *tablespb.CreateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 253 |
return c.internalClient.CreateRow(ctx, req, opts...) |
| 254 |
} |
| 255 |
|
| 256 |
// BatchCreateRows creates multiple rows. |
| 257 |
func (c *Client) BatchCreateRows(ctx context.Context, req *tablespb.BatchCreateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchCreateRowsResponse, error) { |
| 258 |
return c.internalClient.BatchCreateRows(ctx, req, opts...) |
| 259 |
} |
| 260 |
|
| 261 |
// UpdateRow updates a row. |
| 262 |
func (c *Client) UpdateRow(ctx context.Context, req *tablespb.UpdateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 263 |
return c.internalClient.UpdateRow(ctx, req, opts...) |
| 264 |
} |
| 265 |
|
| 266 |
// BatchUpdateRows updates multiple rows. |
| 267 |
func (c *Client) BatchUpdateRows(ctx context.Context, req *tablespb.BatchUpdateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchUpdateRowsResponse, error) { |
| 268 |
return c.internalClient.BatchUpdateRows(ctx, req, opts...) |
| 269 |
} |
| 270 |
|
| 271 |
// DeleteRow deletes a row. |
| 272 |
func (c *Client) DeleteRow(ctx context.Context, req *tablespb.DeleteRowRequest, opts ...gax.CallOption) error { |
| 273 |
return c.internalClient.DeleteRow(ctx, req, opts...) |
| 274 |
} |
| 275 |
|
| 276 |
// BatchDeleteRows deletes multiple rows. |
| 277 |
func (c *Client) BatchDeleteRows(ctx context.Context, req *tablespb.BatchDeleteRowsRequest, opts ...gax.CallOption) error { |
| 278 |
return c.internalClient.BatchDeleteRows(ctx, req, opts...) |
| 279 |
} |
| 280 |
|
| 281 |
// gRPCClient is a client for interacting with Area120 Tables API over gRPC transport. |
| 282 |
// |
| 283 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 284 |
type gRPCClient struct { |
| 285 |
// Connection pool of gRPC connections to the service. |
| 286 |
connPool gtransport.ConnPool |
| 287 |
|
| 288 |
// Points back to the CallOptions field of the containing Client |
| 289 |
CallOptions **CallOptions |
| 290 |
|
| 291 |
// The gRPC API client. |
| 292 |
client tablespb.TablesServiceClient |
| 293 |
|
| 294 |
// The x-goog-* metadata to be sent with each request. |
| 295 |
xGoogHeaders []string |
| 296 |
|
| 297 |
logger *slog.Logger |
| 298 |
} |
| 299 |
|
| 300 |
// NewClient creates a new tables service client based on gRPC. |
| 301 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 302 |
// |
| 303 |
// The Tables Service provides an API for reading and updating tables. |
| 304 |
// It defines the following resource model: |
| 305 |
// |
| 306 |
// The API has a collection of [Table][google.area120.tables.v1alpha1.Table] |
| 307 |
// resources, named tables/* |
| 308 |
// |
| 309 |
// Each Table has a collection of [Row][google.area120.tables.v1alpha1.Row] |
| 310 |
// resources, named tables/*/rows/* |
| 311 |
// |
| 312 |
// The API has a collection of |
| 313 |
// [Workspace][google.area120.tables.v1alpha1.Workspace] |
| 314 |
// resources, named workspaces/*. |
| 315 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 316 |
clientOpts := defaultGRPCClientOptions() |
| 317 |
if newClientHook != nil { |
| 318 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 319 |
if err != nil { |
| 320 |
return nil, err |
| 321 |
} |
| 322 |
clientOpts = append(clientOpts, hookOpts...) |
| 323 |
} |
| 324 |
|
| 325 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 326 |
if err != nil { |
| 327 |
return nil, err |
| 328 |
} |
| 329 |
client := Client{CallOptions: defaultCallOptions()} |
| 330 |
|
| 331 |
c := &gRPCClient{ |
| 332 |
connPool: connPool, |
| 333 |
client: tablespb.NewTablesServiceClient(connPool), |
| 334 |
CallOptions: &client.CallOptions, |
| 335 |
logger: internaloption.GetLogger(opts), |
| 336 |
} |
| 337 |
c.setGoogleClientInfo() |
| 338 |
|
| 339 |
client.internalClient = c |
| 340 |
|
| 341 |
return &client, nil |
| 342 |
} |
| 343 |
|
| 344 |
// Connection returns a connection to the API service. |
| 345 |
// |
| 346 |
// Deprecated: Connections are now pooled so this method does not always |
| 347 |
// return the same resource. |
| 348 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 349 |
return c.connPool.Conn() |
| 350 |
} |
| 351 |
|
| 352 |
// setGoogleClientInfo sets the name and version of the application in |
| 353 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 354 |
// use by Google-written clients. |
| 355 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 356 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 357 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 358 |
c.xGoogHeaders = []string{ |
| 359 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
// Close closes the connection to the API service. The user should invoke this when |
| 364 |
// the client is no longer required. |
| 365 |
func (c *gRPCClient) Close() error { |
| 366 |
return c.connPool.Close() |
| 367 |
} |
| 368 |
|
| 369 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 370 |
type restClient struct { |
| 371 |
// The http endpoint to connect to. |
| 372 |
endpoint string |
| 373 |
|
| 374 |
// The http client. |
| 375 |
httpClient *http.Client |
| 376 |
|
| 377 |
// The x-goog-* headers to be sent with each request. |
| 378 |
xGoogHeaders []string |
| 379 |
|
| 380 |
// Points back to the CallOptions field of the containing Client |
| 381 |
CallOptions **CallOptions |
| 382 |
|
| 383 |
logger *slog.Logger |
| 384 |
} |
| 385 |
|
| 386 |
// NewRESTClient creates a new tables service rest client. |
| 387 |
// |
| 388 |
// The Tables Service provides an API for reading and updating tables. |
| 389 |
// It defines the following resource model: |
| 390 |
// |
| 391 |
// The API has a collection of [Table][google.area120.tables.v1alpha1.Table] |
| 392 |
// resources, named tables/* |
| 393 |
// |
| 394 |
// Each Table has a collection of [Row][google.area120.tables.v1alpha1.Row] |
| 395 |
// resources, named tables/*/rows/* |
| 396 |
// |
| 397 |
// The API has a collection of |
| 398 |
// [Workspace][google.area120.tables.v1alpha1.Workspace] |
| 399 |
// resources, named workspaces/*. |
| 400 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 401 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 402 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 403 |
if err != nil { |
| 404 |
return nil, err |
| 405 |
} |
| 406 |
|
| 407 |
callOpts := defaultRESTCallOptions() |
| 408 |
c := &restClient{ |
| 409 |
endpoint: endpoint, |
| 410 |
httpClient: httpClient, |
| 411 |
CallOptions: &callOpts, |
| 412 |
logger: internaloption.GetLogger(opts), |
| 413 |
} |
| 414 |
c.setGoogleClientInfo() |
| 415 |
|
| 416 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 417 |
} |
| 418 |
|
| 419 |
func defaultRESTClientOptions() []option.ClientOption { |
| 420 |
return []option.ClientOption{ |
| 421 |
internaloption.WithDefaultEndpoint("https://area120tables.googleapis.com"), |
| 422 |
internaloption.WithDefaultEndpointTemplate("https://area120tables.UNIVERSE_DOMAIN"), |
| 423 |
internaloption.WithDefaultMTLSEndpoint("https://area120tables.mtls.googleapis.com"), |
| 424 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 425 |
internaloption.WithDefaultAudience("https://area120tables.googleapis.com/"), |
| 426 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 427 |
internaloption.EnableNewAuthLibrary(), |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
// setGoogleClientInfo sets the name and version of the application in |
| 432 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 433 |
// use by Google-written clients. |
| 434 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 435 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 436 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 437 |
c.xGoogHeaders = []string{ |
| 438 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
// Close closes the connection to the API service. The user should invoke this when |
| 443 |
// the client is no longer required. |
| 444 |
func (c *restClient) Close() error { |
| 445 |
// Replace httpClient with nil to force cleanup. |
| 446 |
c.httpClient = nil |
| 447 |
return nil |
| 448 |
} |
| 449 |
|
| 450 |
// Connection returns a connection to the API service. |
| 451 |
// |
| 452 |
// Deprecated: This method always returns nil. |
| 453 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 454 |
return nil |
| 455 |
} |
| 456 |
func (c *gRPCClient) GetTable(ctx context.Context, req *tablespb.GetTableRequest, opts ...gax.CallOption) (*tablespb.Table, error) { |
| 457 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 458 |
|
| 459 |
hds = append(c.xGoogHeaders, hds...) |
| 460 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 461 |
opts = append((*c.CallOptions).GetTable[0:len((*c.CallOptions).GetTable):len((*c.CallOptions).GetTable)], opts...) |
| 462 |
var resp *tablespb.Table |
| 463 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 464 |
var err error |
| 465 |
resp, err = executeRPC(ctx, c.client.GetTable, req, settings.GRPC, c.logger, "GetTable") |
| 466 |
return err |
| 467 |
}, opts...) |
| 468 |
if err != nil { |
| 469 |
return nil, err |
| 470 |
} |
| 471 |
return resp, nil |
| 472 |
} |
| 473 |
|
| 474 |
func (c *gRPCClient) ListTables(ctx context.Context, req *tablespb.ListTablesRequest, opts ...gax.CallOption) *TableIterator { |
| 475 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 476 |
opts = append((*c.CallOptions).ListTables[0:len((*c.CallOptions).ListTables):len((*c.CallOptions).ListTables)], opts...) |
| 477 |
it := &TableIterator{} |
| 478 |
req = proto.Clone(req).(*tablespb.ListTablesRequest) |
| 479 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Table, string, error) { |
| 480 |
resp := &tablespb.ListTablesResponse{} |
| 481 |
if pageToken != "" { |
| 482 |
req.PageToken = pageToken |
| 483 |
} |
| 484 |
if pageSize > math.MaxInt32 { |
| 485 |
req.PageSize = math.MaxInt32 |
| 486 |
} else if pageSize != 0 { |
| 487 |
req.PageSize = int32(pageSize) |
| 488 |
} |
| 489 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 490 |
var err error |
| 491 |
resp, err = executeRPC(ctx, c.client.ListTables, req, settings.GRPC, c.logger, "ListTables") |
| 492 |
return err |
| 493 |
}, opts...) |
| 494 |
if err != nil { |
| 495 |
return nil, "", err |
| 496 |
} |
| 497 |
|
| 498 |
it.Response = resp |
| 499 |
return resp.GetTables(), resp.GetNextPageToken(), nil |
| 500 |
} |
| 501 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 502 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 503 |
if err != nil { |
| 504 |
return "", err |
| 505 |
} |
| 506 |
it.items = append(it.items, items...) |
| 507 |
return nextPageToken, nil |
| 508 |
} |
| 509 |
|
| 510 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 511 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 512 |
it.pageInfo.Token = req.GetPageToken() |
| 513 |
|
| 514 |
return it |
| 515 |
} |
| 516 |
|
| 517 |
func (c *gRPCClient) GetWorkspace(ctx context.Context, req *tablespb.GetWorkspaceRequest, opts ...gax.CallOption) (*tablespb.Workspace, error) { |
| 518 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 519 |
|
| 520 |
hds = append(c.xGoogHeaders, hds...) |
| 521 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 522 |
opts = append((*c.CallOptions).GetWorkspace[0:len((*c.CallOptions).GetWorkspace):len((*c.CallOptions).GetWorkspace)], opts...) |
| 523 |
var resp *tablespb.Workspace |
| 524 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 525 |
var err error |
| 526 |
resp, err = executeRPC(ctx, c.client.GetWorkspace, req, settings.GRPC, c.logger, "GetWorkspace") |
| 527 |
return err |
| 528 |
}, opts...) |
| 529 |
if err != nil { |
| 530 |
return nil, err |
| 531 |
} |
| 532 |
return resp, nil |
| 533 |
} |
| 534 |
|
| 535 |
func (c *gRPCClient) ListWorkspaces(ctx context.Context, req *tablespb.ListWorkspacesRequest, opts ...gax.CallOption) *WorkspaceIterator { |
| 536 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 537 |
opts = append((*c.CallOptions).ListWorkspaces[0:len((*c.CallOptions).ListWorkspaces):len((*c.CallOptions).ListWorkspaces)], opts...) |
| 538 |
it := &WorkspaceIterator{} |
| 539 |
req = proto.Clone(req).(*tablespb.ListWorkspacesRequest) |
| 540 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Workspace, string, error) { |
| 541 |
resp := &tablespb.ListWorkspacesResponse{} |
| 542 |
if pageToken != "" { |
| 543 |
req.PageToken = pageToken |
| 544 |
} |
| 545 |
if pageSize > math.MaxInt32 { |
| 546 |
req.PageSize = math.MaxInt32 |
| 547 |
} else if pageSize != 0 { |
| 548 |
req.PageSize = int32(pageSize) |
| 549 |
} |
| 550 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 551 |
var err error |
| 552 |
resp, err = executeRPC(ctx, c.client.ListWorkspaces, req, settings.GRPC, c.logger, "ListWorkspaces") |
| 553 |
return err |
| 554 |
}, opts...) |
| 555 |
if err != nil { |
| 556 |
return nil, "", err |
| 557 |
} |
| 558 |
|
| 559 |
it.Response = resp |
| 560 |
return resp.GetWorkspaces(), resp.GetNextPageToken(), nil |
| 561 |
} |
| 562 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 563 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 564 |
if err != nil { |
| 565 |
return "", err |
| 566 |
} |
| 567 |
it.items = append(it.items, items...) |
| 568 |
return nextPageToken, nil |
| 569 |
} |
| 570 |
|
| 571 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 572 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 573 |
it.pageInfo.Token = req.GetPageToken() |
| 574 |
|
| 575 |
return it |
| 576 |
} |
| 577 |
|
| 578 |
func (c *gRPCClient) GetRow(ctx context.Context, req *tablespb.GetRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 579 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 580 |
|
| 581 |
hds = append(c.xGoogHeaders, hds...) |
| 582 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 583 |
opts = append((*c.CallOptions).GetRow[0:len((*c.CallOptions).GetRow):len((*c.CallOptions).GetRow)], opts...) |
| 584 |
var resp *tablespb.Row |
| 585 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 586 |
var err error |
| 587 |
resp, err = executeRPC(ctx, c.client.GetRow, req, settings.GRPC, c.logger, "GetRow") |
| 588 |
return err |
| 589 |
}, opts...) |
| 590 |
if err != nil { |
| 591 |
return nil, err |
| 592 |
} |
| 593 |
return resp, nil |
| 594 |
} |
| 595 |
|
| 596 |
func (c *gRPCClient) ListRows(ctx context.Context, req *tablespb.ListRowsRequest, opts ...gax.CallOption) *RowIterator { |
| 597 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 598 |
|
| 599 |
hds = append(c.xGoogHeaders, hds...) |
| 600 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 601 |
opts = append((*c.CallOptions).ListRows[0:len((*c.CallOptions).ListRows):len((*c.CallOptions).ListRows)], opts...) |
| 602 |
it := &RowIterator{} |
| 603 |
req = proto.Clone(req).(*tablespb.ListRowsRequest) |
| 604 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Row, string, error) { |
| 605 |
resp := &tablespb.ListRowsResponse{} |
| 606 |
if pageToken != "" { |
| 607 |
req.PageToken = pageToken |
| 608 |
} |
| 609 |
if pageSize > math.MaxInt32 { |
| 610 |
req.PageSize = math.MaxInt32 |
| 611 |
} else if pageSize != 0 { |
| 612 |
req.PageSize = int32(pageSize) |
| 613 |
} |
| 614 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 615 |
var err error |
| 616 |
resp, err = executeRPC(ctx, c.client.ListRows, req, settings.GRPC, c.logger, "ListRows") |
| 617 |
return err |
| 618 |
}, opts...) |
| 619 |
if err != nil { |
| 620 |
return nil, "", err |
| 621 |
} |
| 622 |
|
| 623 |
it.Response = resp |
| 624 |
return resp.GetRows(), resp.GetNextPageToken(), nil |
| 625 |
} |
| 626 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 627 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 628 |
if err != nil { |
| 629 |
return "", err |
| 630 |
} |
| 631 |
it.items = append(it.items, items...) |
| 632 |
return nextPageToken, nil |
| 633 |
} |
| 634 |
|
| 635 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 636 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 637 |
it.pageInfo.Token = req.GetPageToken() |
| 638 |
|
| 639 |
return it |
| 640 |
} |
| 641 |
|
| 642 |
func (c *gRPCClient) CreateRow(ctx context.Context, req *tablespb.CreateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 643 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 644 |
|
| 645 |
hds = append(c.xGoogHeaders, hds...) |
| 646 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 647 |
opts = append((*c.CallOptions).CreateRow[0:len((*c.CallOptions).CreateRow):len((*c.CallOptions).CreateRow)], opts...) |
| 648 |
var resp *tablespb.Row |
| 649 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 650 |
var err error |
| 651 |
resp, err = executeRPC(ctx, c.client.CreateRow, req, settings.GRPC, c.logger, "CreateRow") |
| 652 |
return err |
| 653 |
}, opts...) |
| 654 |
if err != nil { |
| 655 |
return nil, err |
| 656 |
} |
| 657 |
return resp, nil |
| 658 |
} |
| 659 |
|
| 660 |
func (c *gRPCClient) BatchCreateRows(ctx context.Context, req *tablespb.BatchCreateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchCreateRowsResponse, error) { |
| 661 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 662 |
|
| 663 |
hds = append(c.xGoogHeaders, hds...) |
| 664 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 665 |
opts = append((*c.CallOptions).BatchCreateRows[0:len((*c.CallOptions).BatchCreateRows):len((*c.CallOptions).BatchCreateRows)], opts...) |
| 666 |
var resp *tablespb.BatchCreateRowsResponse |
| 667 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 668 |
var err error |
| 669 |
resp, err = executeRPC(ctx, c.client.BatchCreateRows, req, settings.GRPC, c.logger, "BatchCreateRows") |
| 670 |
return err |
| 671 |
}, opts...) |
| 672 |
if err != nil { |
| 673 |
return nil, err |
| 674 |
} |
| 675 |
return resp, nil |
| 676 |
} |
| 677 |
|
| 678 |
func (c *gRPCClient) UpdateRow(ctx context.Context, req *tablespb.UpdateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 679 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "row.name", url.QueryEscape(req.GetRow().GetName()))} |
| 680 |
|
| 681 |
hds = append(c.xGoogHeaders, hds...) |
| 682 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 683 |
opts = append((*c.CallOptions).UpdateRow[0:len((*c.CallOptions).UpdateRow):len((*c.CallOptions).UpdateRow)], opts...) |
| 684 |
var resp *tablespb.Row |
| 685 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 686 |
var err error |
| 687 |
resp, err = executeRPC(ctx, c.client.UpdateRow, req, settings.GRPC, c.logger, "UpdateRow") |
| 688 |
return err |
| 689 |
}, opts...) |
| 690 |
if err != nil { |
| 691 |
return nil, err |
| 692 |
} |
| 693 |
return resp, nil |
| 694 |
} |
| 695 |
|
| 696 |
func (c *gRPCClient) BatchUpdateRows(ctx context.Context, req *tablespb.BatchUpdateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchUpdateRowsResponse, error) { |
| 697 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 698 |
|
| 699 |
hds = append(c.xGoogHeaders, hds...) |
| 700 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 701 |
opts = append((*c.CallOptions).BatchUpdateRows[0:len((*c.CallOptions).BatchUpdateRows):len((*c.CallOptions).BatchUpdateRows)], opts...) |
| 702 |
var resp *tablespb.BatchUpdateRowsResponse |
| 703 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 704 |
var err error |
| 705 |
resp, err = executeRPC(ctx, c.client.BatchUpdateRows, req, settings.GRPC, c.logger, "BatchUpdateRows") |
| 706 |
return err |
| 707 |
}, opts...) |
| 708 |
if err != nil { |
| 709 |
return nil, err |
| 710 |
} |
| 711 |
return resp, nil |
| 712 |
} |
| 713 |
|
| 714 |
func (c *gRPCClient) DeleteRow(ctx context.Context, req *tablespb.DeleteRowRequest, opts ...gax.CallOption) error { |
| 715 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 716 |
|
| 717 |
hds = append(c.xGoogHeaders, hds...) |
| 718 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 719 |
opts = append((*c.CallOptions).DeleteRow[0:len((*c.CallOptions).DeleteRow):len((*c.CallOptions).DeleteRow)], opts...) |
| 720 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 721 |
var err error |
| 722 |
_, err = executeRPC(ctx, c.client.DeleteRow, req, settings.GRPC, c.logger, "DeleteRow") |
| 723 |
return err |
| 724 |
}, opts...) |
| 725 |
return err |
| 726 |
} |
| 727 |
|
| 728 |
func (c *gRPCClient) BatchDeleteRows(ctx context.Context, req *tablespb.BatchDeleteRowsRequest, opts ...gax.CallOption) error { |
| 729 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 730 |
|
| 731 |
hds = append(c.xGoogHeaders, hds...) |
| 732 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 733 |
opts = append((*c.CallOptions).BatchDeleteRows[0:len((*c.CallOptions).BatchDeleteRows):len((*c.CallOptions).BatchDeleteRows)], opts...) |
| 734 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 735 |
var err error |
| 736 |
_, err = executeRPC(ctx, c.client.BatchDeleteRows, req, settings.GRPC, c.logger, "BatchDeleteRows") |
| 737 |
return err |
| 738 |
}, opts...) |
| 739 |
return err |
| 740 |
} |
| 741 |
|
| 742 |
// GetTable gets a table. Returns NOT_FOUND if the table does not exist. |
| 743 |
func (c *restClient) GetTable(ctx context.Context, req *tablespb.GetTableRequest, opts ...gax.CallOption) (*tablespb.Table, error) { |
| 744 |
baseUrl, err := url.Parse(c.endpoint) |
| 745 |
if err != nil { |
| 746 |
return nil, err |
| 747 |
} |
| 748 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v", req.GetName()) |
| 749 |
|
| 750 |
params := url.Values{} |
| 751 |
params.Add("$alt", "json;enum-encoding=int") |
| 752 |
|
| 753 |
baseUrl.RawQuery = params.Encode() |
| 754 |
|
| 755 |
// Build HTTP headers from client and context metadata. |
| 756 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 757 |
|
| 758 |
hds = append(c.xGoogHeaders, hds...) |
| 759 |
hds = append(hds, "Content-Type", "application/json") |
| 760 |
headers := gax.BuildHeaders(ctx, hds...) |
| 761 |
opts = append((*c.CallOptions).GetTable[0:len((*c.CallOptions).GetTable):len((*c.CallOptions).GetTable)], opts...) |
| 762 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 763 |
resp := &tablespb.Table{} |
| 764 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 765 |
if settings.Path != "" { |
| 766 |
baseUrl.Path = settings.Path |
| 767 |
} |
| 768 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 769 |
if err != nil { |
| 770 |
return err |
| 771 |
} |
| 772 |
httpReq = httpReq.WithContext(ctx) |
| 773 |
httpReq.Header = headers |
| 774 |
|
| 775 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTable") |
| 776 |
if err != nil { |
| 777 |
return err |
| 778 |
} |
| 779 |
|
| 780 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 781 |
return err |
| 782 |
} |
| 783 |
|
| 784 |
return nil |
| 785 |
}, opts...) |
| 786 |
if e != nil { |
| 787 |
return nil, e |
| 788 |
} |
| 789 |
return resp, nil |
| 790 |
} |
| 791 |
|
| 792 |
// ListTables lists tables for the user. |
| 793 |
func (c *restClient) ListTables(ctx context.Context, req *tablespb.ListTablesRequest, opts ...gax.CallOption) *TableIterator { |
| 794 |
it := &TableIterator{} |
| 795 |
req = proto.Clone(req).(*tablespb.ListTablesRequest) |
| 796 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 797 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Table, string, error) { |
| 798 |
resp := &tablespb.ListTablesResponse{} |
| 799 |
if pageToken != "" { |
| 800 |
req.PageToken = pageToken |
| 801 |
} |
| 802 |
if pageSize > math.MaxInt32 { |
| 803 |
req.PageSize = math.MaxInt32 |
| 804 |
} else if pageSize != 0 { |
| 805 |
req.PageSize = int32(pageSize) |
| 806 |
} |
| 807 |
baseUrl, err := url.Parse(c.endpoint) |
| 808 |
if err != nil { |
| 809 |
return nil, "", err |
| 810 |
} |
| 811 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/tables") |
| 812 |
|
| 813 |
params := url.Values{} |
| 814 |
params.Add("$alt", "json;enum-encoding=int") |
| 815 |
if req.GetPageSize() != 0 { |
| 816 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 817 |
} |
| 818 |
if req.GetPageToken() != "" { |
| 819 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 820 |
} |
| 821 |
|
| 822 |
baseUrl.RawQuery = params.Encode() |
| 823 |
|
| 824 |
// Build HTTP headers from client and context metadata. |
| 825 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 826 |
headers := gax.BuildHeaders(ctx, hds...) |
| 827 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 828 |
if settings.Path != "" { |
| 829 |
baseUrl.Path = settings.Path |
| 830 |
} |
| 831 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 832 |
if err != nil { |
| 833 |
return err |
| 834 |
} |
| 835 |
httpReq.Header = headers |
| 836 |
|
| 837 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTables") |
| 838 |
if err != nil { |
| 839 |
return err |
| 840 |
} |
| 841 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 842 |
return err |
| 843 |
} |
| 844 |
|
| 845 |
return nil |
| 846 |
}, opts...) |
| 847 |
if e != nil { |
| 848 |
return nil, "", e |
| 849 |
} |
| 850 |
it.Response = resp |
| 851 |
return resp.GetTables(), resp.GetNextPageToken(), nil |
| 852 |
} |
| 853 |
|
| 854 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 855 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 856 |
if err != nil { |
| 857 |
return "", err |
| 858 |
} |
| 859 |
it.items = append(it.items, items...) |
| 860 |
return nextPageToken, nil |
| 861 |
} |
| 862 |
|
| 863 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 864 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 865 |
it.pageInfo.Token = req.GetPageToken() |
| 866 |
|
| 867 |
return it |
| 868 |
} |
| 869 |
|
| 870 |
// GetWorkspace gets a workspace. Returns NOT_FOUND if the workspace does not exist. |
| 871 |
func (c *restClient) GetWorkspace(ctx context.Context, req *tablespb.GetWorkspaceRequest, opts ...gax.CallOption) (*tablespb.Workspace, error) { |
| 872 |
baseUrl, err := url.Parse(c.endpoint) |
| 873 |
if err != nil { |
| 874 |
return nil, err |
| 875 |
} |
| 876 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v", req.GetName()) |
| 877 |
|
| 878 |
params := url.Values{} |
| 879 |
params.Add("$alt", "json;enum-encoding=int") |
| 880 |
|
| 881 |
baseUrl.RawQuery = params.Encode() |
| 882 |
|
| 883 |
// Build HTTP headers from client and context metadata. |
| 884 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 885 |
|
| 886 |
hds = append(c.xGoogHeaders, hds...) |
| 887 |
hds = append(hds, "Content-Type", "application/json") |
| 888 |
headers := gax.BuildHeaders(ctx, hds...) |
| 889 |
opts = append((*c.CallOptions).GetWorkspace[0:len((*c.CallOptions).GetWorkspace):len((*c.CallOptions).GetWorkspace)], opts...) |
| 890 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 891 |
resp := &tablespb.Workspace{} |
| 892 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 893 |
if settings.Path != "" { |
| 894 |
baseUrl.Path = settings.Path |
| 895 |
} |
| 896 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 897 |
if err != nil { |
| 898 |
return err |
| 899 |
} |
| 900 |
httpReq = httpReq.WithContext(ctx) |
| 901 |
httpReq.Header = headers |
| 902 |
|
| 903 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetWorkspace") |
| 904 |
if err != nil { |
| 905 |
return err |
| 906 |
} |
| 907 |
|
| 908 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 909 |
return err |
| 910 |
} |
| 911 |
|
| 912 |
return nil |
| 913 |
}, opts...) |
| 914 |
if e != nil { |
| 915 |
return nil, e |
| 916 |
} |
| 917 |
return resp, nil |
| 918 |
} |
| 919 |
|
| 920 |
// ListWorkspaces lists workspaces for the user. |
| 921 |
func (c *restClient) ListWorkspaces(ctx context.Context, req *tablespb.ListWorkspacesRequest, opts ...gax.CallOption) *WorkspaceIterator { |
| 922 |
it := &WorkspaceIterator{} |
| 923 |
req = proto.Clone(req).(*tablespb.ListWorkspacesRequest) |
| 924 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 925 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Workspace, string, error) { |
| 926 |
resp := &tablespb.ListWorkspacesResponse{} |
| 927 |
if pageToken != "" { |
| 928 |
req.PageToken = pageToken |
| 929 |
} |
| 930 |
if pageSize > math.MaxInt32 { |
| 931 |
req.PageSize = math.MaxInt32 |
| 932 |
} else if pageSize != 0 { |
| 933 |
req.PageSize = int32(pageSize) |
| 934 |
} |
| 935 |
baseUrl, err := url.Parse(c.endpoint) |
| 936 |
if err != nil { |
| 937 |
return nil, "", err |
| 938 |
} |
| 939 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/workspaces") |
| 940 |
|
| 941 |
params := url.Values{} |
| 942 |
params.Add("$alt", "json;enum-encoding=int") |
| 943 |
if req.GetPageSize() != 0 { |
| 944 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 945 |
} |
| 946 |
if req.GetPageToken() != "" { |
| 947 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 948 |
} |
| 949 |
|
| 950 |
baseUrl.RawQuery = params.Encode() |
| 951 |
|
| 952 |
// Build HTTP headers from client and context metadata. |
| 953 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 954 |
headers := gax.BuildHeaders(ctx, hds...) |
| 955 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 956 |
if settings.Path != "" { |
| 957 |
baseUrl.Path = settings.Path |
| 958 |
} |
| 959 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 960 |
if err != nil { |
| 961 |
return err |
| 962 |
} |
| 963 |
httpReq.Header = headers |
| 964 |
|
| 965 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListWorkspaces") |
| 966 |
if err != nil { |
| 967 |
return err |
| 968 |
} |
| 969 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 970 |
return err |
| 971 |
} |
| 972 |
|
| 973 |
return nil |
| 974 |
}, opts...) |
| 975 |
if e != nil { |
| 976 |
return nil, "", e |
| 977 |
} |
| 978 |
it.Response = resp |
| 979 |
return resp.GetWorkspaces(), resp.GetNextPageToken(), nil |
| 980 |
} |
| 981 |
|
| 982 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 983 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 984 |
if err != nil { |
| 985 |
return "", err |
| 986 |
} |
| 987 |
it.items = append(it.items, items...) |
| 988 |
return nextPageToken, nil |
| 989 |
} |
| 990 |
|
| 991 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 992 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 993 |
it.pageInfo.Token = req.GetPageToken() |
| 994 |
|
| 995 |
return it |
| 996 |
} |
| 997 |
|
| 998 |
// GetRow gets a row. Returns NOT_FOUND if the row does not exist in the table. |
| 999 |
func (c *restClient) GetRow(ctx context.Context, req *tablespb.GetRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 1000 |
baseUrl, err := url.Parse(c.endpoint) |
| 1001 |
if err != nil { |
| 1002 |
return nil, err |
| 1003 |
} |
| 1004 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v", req.GetName()) |
| 1005 |
|
| 1006 |
params := url.Values{} |
| 1007 |
params.Add("$alt", "json;enum-encoding=int") |
| 1008 |
if req.GetView() != 0 { |
| 1009 |
params.Add("view", fmt.Sprintf("%v", req.GetView())) |
| 1010 |
} |
| 1011 |
|
| 1012 |
baseUrl.RawQuery = params.Encode() |
| 1013 |
|
| 1014 |
// Build HTTP headers from client and context metadata. |
| 1015 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1016 |
|
| 1017 |
hds = append(c.xGoogHeaders, hds...) |
| 1018 |
hds = append(hds, "Content-Type", "application/json") |
| 1019 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1020 |
opts = append((*c.CallOptions).GetRow[0:len((*c.CallOptions).GetRow):len((*c.CallOptions).GetRow)], opts...) |
| 1021 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1022 |
resp := &tablespb.Row{} |
| 1023 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1024 |
if settings.Path != "" { |
| 1025 |
baseUrl.Path = settings.Path |
| 1026 |
} |
| 1027 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1028 |
if err != nil { |
| 1029 |
return err |
| 1030 |
} |
| 1031 |
httpReq = httpReq.WithContext(ctx) |
| 1032 |
httpReq.Header = headers |
| 1033 |
|
| 1034 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRow") |
| 1035 |
if err != nil { |
| 1036 |
return err |
| 1037 |
} |
| 1038 |
|
| 1039 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1040 |
return err |
| 1041 |
} |
| 1042 |
|
| 1043 |
return nil |
| 1044 |
}, opts...) |
| 1045 |
if e != nil { |
| 1046 |
return nil, e |
| 1047 |
} |
| 1048 |
return resp, nil |
| 1049 |
} |
| 1050 |
|
| 1051 |
// ListRows lists rows in a table. Returns NOT_FOUND if the table does not exist. |
| 1052 |
func (c *restClient) ListRows(ctx context.Context, req *tablespb.ListRowsRequest, opts ...gax.CallOption) *RowIterator { |
| 1053 |
it := &RowIterator{} |
| 1054 |
req = proto.Clone(req).(*tablespb.ListRowsRequest) |
| 1055 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1056 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*tablespb.Row, string, error) { |
| 1057 |
resp := &tablespb.ListRowsResponse{} |
| 1058 |
if pageToken != "" { |
| 1059 |
req.PageToken = pageToken |
| 1060 |
} |
| 1061 |
if pageSize > math.MaxInt32 { |
| 1062 |
req.PageSize = math.MaxInt32 |
| 1063 |
} else if pageSize != 0 { |
| 1064 |
req.PageSize = int32(pageSize) |
| 1065 |
} |
| 1066 |
baseUrl, err := url.Parse(c.endpoint) |
| 1067 |
if err != nil { |
| 1068 |
return nil, "", err |
| 1069 |
} |
| 1070 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v/rows", req.GetParent()) |
| 1071 |
|
| 1072 |
params := url.Values{} |
| 1073 |
params.Add("$alt", "json;enum-encoding=int") |
| 1074 |
if req.GetFilter() != "" { |
| 1075 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1076 |
} |
| 1077 |
if req.GetPageSize() != 0 { |
| 1078 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1079 |
} |
| 1080 |
if req.GetPageToken() != "" { |
| 1081 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1082 |
} |
| 1083 |
if req.GetView() != 0 { |
| 1084 |
params.Add("view", fmt.Sprintf("%v", req.GetView())) |
| 1085 |
} |
| 1086 |
|
| 1087 |
baseUrl.RawQuery = params.Encode() |
| 1088 |
|
| 1089 |
// Build HTTP headers from client and context metadata. |
| 1090 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1091 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1092 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1093 |
if settings.Path != "" { |
| 1094 |
baseUrl.Path = settings.Path |
| 1095 |
} |
| 1096 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1097 |
if err != nil { |
| 1098 |
return err |
| 1099 |
} |
| 1100 |
httpReq.Header = headers |
| 1101 |
|
| 1102 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRows") |
| 1103 |
if err != nil { |
| 1104 |
return err |
| 1105 |
} |
| 1106 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1107 |
return err |
| 1108 |
} |
| 1109 |
|
| 1110 |
return nil |
| 1111 |
}, opts...) |
| 1112 |
if e != nil { |
| 1113 |
return nil, "", e |
| 1114 |
} |
| 1115 |
it.Response = resp |
| 1116 |
return resp.GetRows(), resp.GetNextPageToken(), nil |
| 1117 |
} |
| 1118 |
|
| 1119 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1120 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1121 |
if err != nil { |
| 1122 |
return "", err |
| 1123 |
} |
| 1124 |
it.items = append(it.items, items...) |
| 1125 |
return nextPageToken, nil |
| 1126 |
} |
| 1127 |
|
| 1128 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1129 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1130 |
it.pageInfo.Token = req.GetPageToken() |
| 1131 |
|
| 1132 |
return it |
| 1133 |
} |
| 1134 |
|
| 1135 |
// CreateRow creates a row. |
| 1136 |
func (c *restClient) CreateRow(ctx context.Context, req *tablespb.CreateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 1137 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1138 |
body := req.GetRow() |
| 1139 |
jsonReq, err := m.Marshal(body) |
| 1140 |
if err != nil { |
| 1141 |
return nil, err |
| 1142 |
} |
| 1143 |
|
| 1144 |
baseUrl, err := url.Parse(c.endpoint) |
| 1145 |
if err != nil { |
| 1146 |
return nil, err |
| 1147 |
} |
| 1148 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v/rows", req.GetParent()) |
| 1149 |
|
| 1150 |
params := url.Values{} |
| 1151 |
params.Add("$alt", "json;enum-encoding=int") |
| 1152 |
if req.GetView() != 0 { |
| 1153 |
params.Add("view", fmt.Sprintf("%v", req.GetView())) |
| 1154 |
} |
| 1155 |
|
| 1156 |
baseUrl.RawQuery = params.Encode() |
| 1157 |
|
| 1158 |
// Build HTTP headers from client and context metadata. |
| 1159 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1160 |
|
| 1161 |
hds = append(c.xGoogHeaders, hds...) |
| 1162 |
hds = append(hds, "Content-Type", "application/json") |
| 1163 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1164 |
opts = append((*c.CallOptions).CreateRow[0:len((*c.CallOptions).CreateRow):len((*c.CallOptions).CreateRow)], opts...) |
| 1165 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1166 |
resp := &tablespb.Row{} |
| 1167 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1168 |
if settings.Path != "" { |
| 1169 |
baseUrl.Path = settings.Path |
| 1170 |
} |
| 1171 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1172 |
if err != nil { |
| 1173 |
return err |
| 1174 |
} |
| 1175 |
httpReq = httpReq.WithContext(ctx) |
| 1176 |
httpReq.Header = headers |
| 1177 |
|
| 1178 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateRow") |
| 1179 |
if err != nil { |
| 1180 |
return err |
| 1181 |
} |
| 1182 |
|
| 1183 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1184 |
return err |
| 1185 |
} |
| 1186 |
|
| 1187 |
return nil |
| 1188 |
}, opts...) |
| 1189 |
if e != nil { |
| 1190 |
return nil, e |
| 1191 |
} |
| 1192 |
return resp, nil |
| 1193 |
} |
| 1194 |
|
| 1195 |
// BatchCreateRows creates multiple rows. |
| 1196 |
func (c *restClient) BatchCreateRows(ctx context.Context, req *tablespb.BatchCreateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchCreateRowsResponse, error) { |
| 1197 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1198 |
jsonReq, err := m.Marshal(req) |
| 1199 |
if err != nil { |
| 1200 |
return nil, err |
| 1201 |
} |
| 1202 |
|
| 1203 |
baseUrl, err := url.Parse(c.endpoint) |
| 1204 |
if err != nil { |
| 1205 |
return nil, err |
| 1206 |
} |
| 1207 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v/rows:batchCreate", req.GetParent()) |
| 1208 |
|
| 1209 |
params := url.Values{} |
| 1210 |
params.Add("$alt", "json;enum-encoding=int") |
| 1211 |
|
| 1212 |
baseUrl.RawQuery = params.Encode() |
| 1213 |
|
| 1214 |
// Build HTTP headers from client and context metadata. |
| 1215 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1216 |
|
| 1217 |
hds = append(c.xGoogHeaders, hds...) |
| 1218 |
hds = append(hds, "Content-Type", "application/json") |
| 1219 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1220 |
opts = append((*c.CallOptions).BatchCreateRows[0:len((*c.CallOptions).BatchCreateRows):len((*c.CallOptions).BatchCreateRows)], opts...) |
| 1221 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1222 |
resp := &tablespb.BatchCreateRowsResponse{} |
| 1223 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1224 |
if settings.Path != "" { |
| 1225 |
baseUrl.Path = settings.Path |
| 1226 |
} |
| 1227 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1228 |
if err != nil { |
| 1229 |
return err |
| 1230 |
} |
| 1231 |
httpReq = httpReq.WithContext(ctx) |
| 1232 |
httpReq.Header = headers |
| 1233 |
|
| 1234 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchCreateRows") |
| 1235 |
if err != nil { |
| 1236 |
return err |
| 1237 |
} |
| 1238 |
|
| 1239 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1240 |
return err |
| 1241 |
} |
| 1242 |
|
| 1243 |
return nil |
| 1244 |
}, opts...) |
| 1245 |
if e != nil { |
| 1246 |
return nil, e |
| 1247 |
} |
| 1248 |
return resp, nil |
| 1249 |
} |
| 1250 |
|
| 1251 |
// UpdateRow updates a row. |
| 1252 |
func (c *restClient) UpdateRow(ctx context.Context, req *tablespb.UpdateRowRequest, opts ...gax.CallOption) (*tablespb.Row, error) { |
| 1253 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1254 |
body := req.GetRow() |
| 1255 |
jsonReq, err := m.Marshal(body) |
| 1256 |
if err != nil { |
| 1257 |
return nil, err |
| 1258 |
} |
| 1259 |
|
| 1260 |
baseUrl, err := url.Parse(c.endpoint) |
| 1261 |
if err != nil { |
| 1262 |
return nil, err |
| 1263 |
} |
| 1264 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v", req.GetRow().GetName()) |
| 1265 |
|
| 1266 |
params := url.Values{} |
| 1267 |
params.Add("$alt", "json;enum-encoding=int") |
| 1268 |
if req.GetUpdateMask() != nil { |
| 1269 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1270 |
if err != nil { |
| 1271 |
return nil, err |
| 1272 |
} |
| 1273 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1274 |
} |
| 1275 |
if req.GetView() != 0 { |
| 1276 |
params.Add("view", fmt.Sprintf("%v", req.GetView())) |
| 1277 |
} |
| 1278 |
|
| 1279 |
baseUrl.RawQuery = params.Encode() |
| 1280 |
|
| 1281 |
// Build HTTP headers from client and context metadata. |
| 1282 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "row.name", url.QueryEscape(req.GetRow().GetName()))} |
| 1283 |
|
| 1284 |
hds = append(c.xGoogHeaders, hds...) |
| 1285 |
hds = append(hds, "Content-Type", "application/json") |
| 1286 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1287 |
opts = append((*c.CallOptions).UpdateRow[0:len((*c.CallOptions).UpdateRow):len((*c.CallOptions).UpdateRow)], opts...) |
| 1288 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1289 |
resp := &tablespb.Row{} |
| 1290 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1291 |
if settings.Path != "" { |
| 1292 |
baseUrl.Path = settings.Path |
| 1293 |
} |
| 1294 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1295 |
if err != nil { |
| 1296 |
return err |
| 1297 |
} |
| 1298 |
httpReq = httpReq.WithContext(ctx) |
| 1299 |
httpReq.Header = headers |
| 1300 |
|
| 1301 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateRow") |
| 1302 |
if err != nil { |
| 1303 |
return err |
| 1304 |
} |
| 1305 |
|
| 1306 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1307 |
return err |
| 1308 |
} |
| 1309 |
|
| 1310 |
return nil |
| 1311 |
}, opts...) |
| 1312 |
if e != nil { |
| 1313 |
return nil, e |
| 1314 |
} |
| 1315 |
return resp, nil |
| 1316 |
} |
| 1317 |
|
| 1318 |
// BatchUpdateRows updates multiple rows. |
| 1319 |
func (c *restClient) BatchUpdateRows(ctx context.Context, req *tablespb.BatchUpdateRowsRequest, opts ...gax.CallOption) (*tablespb.BatchUpdateRowsResponse, error) { |
| 1320 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1321 |
jsonReq, err := m.Marshal(req) |
| 1322 |
if err != nil { |
| 1323 |
return nil, err |
| 1324 |
} |
| 1325 |
|
| 1326 |
baseUrl, err := url.Parse(c.endpoint) |
| 1327 |
if err != nil { |
| 1328 |
return nil, err |
| 1329 |
} |
| 1330 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v/rows:batchUpdate", req.GetParent()) |
| 1331 |
|
| 1332 |
params := url.Values{} |
| 1333 |
params.Add("$alt", "json;enum-encoding=int") |
| 1334 |
|
| 1335 |
baseUrl.RawQuery = params.Encode() |
| 1336 |
|
| 1337 |
// Build HTTP headers from client and context metadata. |
| 1338 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1339 |
|
| 1340 |
hds = append(c.xGoogHeaders, hds...) |
| 1341 |
hds = append(hds, "Content-Type", "application/json") |
| 1342 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1343 |
opts = append((*c.CallOptions).BatchUpdateRows[0:len((*c.CallOptions).BatchUpdateRows):len((*c.CallOptions).BatchUpdateRows)], opts...) |
| 1344 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1345 |
resp := &tablespb.BatchUpdateRowsResponse{} |
| 1346 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1347 |
if settings.Path != "" { |
| 1348 |
baseUrl.Path = settings.Path |
| 1349 |
} |
| 1350 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1351 |
if err != nil { |
| 1352 |
return err |
| 1353 |
} |
| 1354 |
httpReq = httpReq.WithContext(ctx) |
| 1355 |
httpReq.Header = headers |
| 1356 |
|
| 1357 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchUpdateRows") |
| 1358 |
if err != nil { |
| 1359 |
return err |
| 1360 |
} |
| 1361 |
|
| 1362 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1363 |
return err |
| 1364 |
} |
| 1365 |
|
| 1366 |
return nil |
| 1367 |
}, opts...) |
| 1368 |
if e != nil { |
| 1369 |
return nil, e |
| 1370 |
} |
| 1371 |
return resp, nil |
| 1372 |
} |
| 1373 |
|
| 1374 |
// DeleteRow deletes a row. |
| 1375 |
func (c *restClient) DeleteRow(ctx context.Context, req *tablespb.DeleteRowRequest, opts ...gax.CallOption) error { |
| 1376 |
baseUrl, err := url.Parse(c.endpoint) |
| 1377 |
if err != nil { |
| 1378 |
return err |
| 1379 |
} |
| 1380 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v", req.GetName()) |
| 1381 |
|
| 1382 |
params := url.Values{} |
| 1383 |
params.Add("$alt", "json;enum-encoding=int") |
| 1384 |
|
| 1385 |
baseUrl.RawQuery = params.Encode() |
| 1386 |
|
| 1387 |
// Build HTTP headers from client and context metadata. |
| 1388 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1389 |
|
| 1390 |
hds = append(c.xGoogHeaders, hds...) |
| 1391 |
hds = append(hds, "Content-Type", "application/json") |
| 1392 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1393 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1394 |
if settings.Path != "" { |
| 1395 |
baseUrl.Path = settings.Path |
| 1396 |
} |
| 1397 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1398 |
if err != nil { |
| 1399 |
return err |
| 1400 |
} |
| 1401 |
httpReq = httpReq.WithContext(ctx) |
| 1402 |
httpReq.Header = headers |
| 1403 |
|
| 1404 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRow") |
| 1405 |
return err |
| 1406 |
}, opts...) |
| 1407 |
} |
| 1408 |
|
| 1409 |
// BatchDeleteRows deletes multiple rows. |
| 1410 |
func (c *restClient) BatchDeleteRows(ctx context.Context, req *tablespb.BatchDeleteRowsRequest, opts ...gax.CallOption) error { |
| 1411 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1412 |
jsonReq, err := m.Marshal(req) |
| 1413 |
if err != nil { |
| 1414 |
return err |
| 1415 |
} |
| 1416 |
|
| 1417 |
baseUrl, err := url.Parse(c.endpoint) |
| 1418 |
if err != nil { |
| 1419 |
return err |
| 1420 |
} |
| 1421 |
baseUrl.Path += fmt.Sprintf("/v1alpha1/%v/rows:batchDelete", req.GetParent()) |
| 1422 |
|
| 1423 |
params := url.Values{} |
| 1424 |
params.Add("$alt", "json;enum-encoding=int") |
| 1425 |
|
| 1426 |
baseUrl.RawQuery = params.Encode() |
| 1427 |
|
| 1428 |
// Build HTTP headers from client and context metadata. |
| 1429 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1430 |
|
| 1431 |
hds = append(c.xGoogHeaders, hds...) |
| 1432 |
hds = append(hds, "Content-Type", "application/json") |
| 1433 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1434 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1435 |
if settings.Path != "" { |
| 1436 |
baseUrl.Path = settings.Path |
| 1437 |
} |
| 1438 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1439 |
if err != nil { |
| 1440 |
return err |
| 1441 |
} |
| 1442 |
httpReq = httpReq.WithContext(ctx) |
| 1443 |
httpReq.Header = headers |
| 1444 |
|
| 1445 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchDeleteRows") |
| 1446 |
return err |
| 1447 |
}, opts...) |
| 1448 |
} |