| // Copyright 2024 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| // Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| |
| package speech |
| |
| import ( |
| "bytes" |
| "context" |
| "errors" |
| "fmt" |
| "io" |
| "math" |
| "net/http" |
| "net/url" |
| "time" |
| |
| "cloud.google.com/go/longrunning" |
| lroauto "cloud.google.com/go/longrunning/autogen" |
| longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| speechpb "cloud.google.com/go/speech/apiv2/speechpb" |
| gax "github.com/googleapis/gax-go/v2" |
| "google.golang.org/api/googleapi" |
| "google.golang.org/api/iterator" |
| "google.golang.org/api/option" |
| "google.golang.org/api/option/internaloption" |
| gtransport "google.golang.org/api/transport/grpc" |
| httptransport "google.golang.org/api/transport/http" |
| locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| "google.golang.org/grpc" |
| "google.golang.org/grpc/codes" |
| "google.golang.org/protobuf/encoding/protojson" |
| "google.golang.org/protobuf/proto" |
| ) |
| |
| var newClientHook clientHook |
| |
| // CallOptions contains the retry settings for each method of Client. |
| type CallOptions struct { |
| CreateRecognizer []gax.CallOption |
| ListRecognizers []gax.CallOption |
| GetRecognizer []gax.CallOption |
| UpdateRecognizer []gax.CallOption |
| DeleteRecognizer []gax.CallOption |
| UndeleteRecognizer []gax.CallOption |
| Recognize []gax.CallOption |
| StreamingRecognize []gax.CallOption |
| BatchRecognize []gax.CallOption |
| GetConfig []gax.CallOption |
| UpdateConfig []gax.CallOption |
| CreateCustomClass []gax.CallOption |
| ListCustomClasses []gax.CallOption |
| GetCustomClass []gax.CallOption |
| UpdateCustomClass []gax.CallOption |
| DeleteCustomClass []gax.CallOption |
| UndeleteCustomClass []gax.CallOption |
| CreatePhraseSet []gax.CallOption |
| ListPhraseSets []gax.CallOption |
| GetPhraseSet []gax.CallOption |
| UpdatePhraseSet []gax.CallOption |
| DeletePhraseSet []gax.CallOption |
| UndeletePhraseSet []gax.CallOption |
| GetLocation []gax.CallOption |
| ListLocations []gax.CallOption |
| CancelOperation []gax.CallOption |
| DeleteOperation []gax.CallOption |
| GetOperation []gax.CallOption |
| ListOperations []gax.CallOption |
| } |
| |
| func defaultGRPCClientOptions() []option.ClientOption { |
| return []option.ClientOption{ |
| internaloption.WithDefaultEndpoint("speech.googleapis.com:443"), |
| internaloption.WithDefaultEndpointTemplate("speech.UNIVERSE_DOMAIN:443"), |
| internaloption.WithDefaultMTLSEndpoint("speech.mtls.googleapis.com:443"), |
| internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| internaloption.WithDefaultAudience("https://speech.googleapis.com/"), |
| internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| internaloption.EnableJwtWithScope(), |
| option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| } |
| } |
| |
| func defaultCallOptions() *CallOptions { |
| return &CallOptions{ |
| CreateRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| ListRecognizers: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| GetRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UpdateRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| DeleteRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UndeleteRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| Recognize: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| StreamingRecognize: []gax.CallOption{ |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| BatchRecognize: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| GetConfig: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UpdateConfig: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| CreateCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| ListCustomClasses: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| GetCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UpdateCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| DeleteCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UndeleteCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| CreatePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| ListPhraseSets: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| GetPhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UpdatePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| DeletePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| UndeletePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnCodes([]codes.Code{ |
| codes.DeadlineExceeded, |
| codes.Unavailable, |
| }, gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }) |
| }), |
| }, |
| GetLocation: []gax.CallOption{}, |
| ListLocations: []gax.CallOption{}, |
| CancelOperation: []gax.CallOption{}, |
| DeleteOperation: []gax.CallOption{}, |
| GetOperation: []gax.CallOption{}, |
| ListOperations: []gax.CallOption{}, |
| } |
| } |
| |
| func defaultRESTCallOptions() *CallOptions { |
| return &CallOptions{ |
| CreateRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| ListRecognizers: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| GetRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UpdateRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| DeleteRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UndeleteRecognizer: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| Recognize: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| StreamingRecognize: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| BatchRecognize: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| GetConfig: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UpdateConfig: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| CreateCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| ListCustomClasses: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| GetCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UpdateCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| DeleteCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UndeleteCustomClass: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| CreatePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| ListPhraseSets: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| GetPhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UpdatePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| DeletePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| UndeletePhraseSet: []gax.CallOption{ |
| gax.WithTimeout(5000000 * time.Millisecond), |
| gax.WithRetry(func() gax.Retryer { |
| return gax.OnHTTPCodes(gax.Backoff{ |
| Initial: 100 * time.Millisecond, |
| Max: 60000 * time.Millisecond, |
| Multiplier: 1.30, |
| }, |
| http.StatusGatewayTimeout, |
| http.StatusServiceUnavailable) |
| }), |
| }, |
| GetLocation: []gax.CallOption{}, |
| ListLocations: []gax.CallOption{}, |
| CancelOperation: []gax.CallOption{}, |
| DeleteOperation: []gax.CallOption{}, |
| GetOperation: []gax.CallOption{}, |
| ListOperations: []gax.CallOption{}, |
| } |
| } |
| |
| // internalClient is an interface that defines the methods available from Cloud Speech-to-Text API. |
| type internalClient interface { |
| Close() error |
| setGoogleClientInfo(...string) |
| Connection() *grpc.ClientConn |
| CreateRecognizer(context.Context, *speechpb.CreateRecognizerRequest, ...gax.CallOption) (*CreateRecognizerOperation, error) |
| CreateRecognizerOperation(name string) *CreateRecognizerOperation |
| ListRecognizers(context.Context, *speechpb.ListRecognizersRequest, ...gax.CallOption) *RecognizerIterator |
| GetRecognizer(context.Context, *speechpb.GetRecognizerRequest, ...gax.CallOption) (*speechpb.Recognizer, error) |
| UpdateRecognizer(context.Context, *speechpb.UpdateRecognizerRequest, ...gax.CallOption) (*UpdateRecognizerOperation, error) |
| UpdateRecognizerOperation(name string) *UpdateRecognizerOperation |
| DeleteRecognizer(context.Context, *speechpb.DeleteRecognizerRequest, ...gax.CallOption) (*DeleteRecognizerOperation, error) |
| DeleteRecognizerOperation(name string) *DeleteRecognizerOperation |
| UndeleteRecognizer(context.Context, *speechpb.UndeleteRecognizerRequest, ...gax.CallOption) (*UndeleteRecognizerOperation, error) |
| UndeleteRecognizerOperation(name string) *UndeleteRecognizerOperation |
| Recognize(context.Context, *speechpb.RecognizeRequest, ...gax.CallOption) (*speechpb.RecognizeResponse, error) |
| StreamingRecognize(context.Context, ...gax.CallOption) (speechpb.Speech_StreamingRecognizeClient, error) |
| BatchRecognize(context.Context, *speechpb.BatchRecognizeRequest, ...gax.CallOption) (*BatchRecognizeOperation, error) |
| BatchRecognizeOperation(name string) *BatchRecognizeOperation |
| GetConfig(context.Context, *speechpb.GetConfigRequest, ...gax.CallOption) (*speechpb.Config, error) |
| UpdateConfig(context.Context, *speechpb.UpdateConfigRequest, ...gax.CallOption) (*speechpb.Config, error) |
| CreateCustomClass(context.Context, *speechpb.CreateCustomClassRequest, ...gax.CallOption) (*CreateCustomClassOperation, error) |
| CreateCustomClassOperation(name string) *CreateCustomClassOperation |
| ListCustomClasses(context.Context, *speechpb.ListCustomClassesRequest, ...gax.CallOption) *CustomClassIterator |
| GetCustomClass(context.Context, *speechpb.GetCustomClassRequest, ...gax.CallOption) (*speechpb.CustomClass, error) |
| UpdateCustomClass(context.Context, *speechpb.UpdateCustomClassRequest, ...gax.CallOption) (*UpdateCustomClassOperation, error) |
| UpdateCustomClassOperation(name string) *UpdateCustomClassOperation |
| DeleteCustomClass(context.Context, *speechpb.DeleteCustomClassRequest, ...gax.CallOption) (*DeleteCustomClassOperation, error) |
| DeleteCustomClassOperation(name string) *DeleteCustomClassOperation |
| UndeleteCustomClass(context.Context, *speechpb.UndeleteCustomClassRequest, ...gax.CallOption) (*UndeleteCustomClassOperation, error) |
| UndeleteCustomClassOperation(name string) *UndeleteCustomClassOperation |
| CreatePhraseSet(context.Context, *speechpb.CreatePhraseSetRequest, ...gax.CallOption) (*CreatePhraseSetOperation, error) |
| CreatePhraseSetOperation(name string) *CreatePhraseSetOperation |
| ListPhraseSets(context.Context, *speechpb.ListPhraseSetsRequest, ...gax.CallOption) *PhraseSetIterator |
| GetPhraseSet(context.Context, *speechpb.GetPhraseSetRequest, ...gax.CallOption) (*speechpb.PhraseSet, error) |
| UpdatePhraseSet(context.Context, *speechpb.UpdatePhraseSetRequest, ...gax.CallOption) (*UpdatePhraseSetOperation, error) |
| UpdatePhraseSetOperation(name string) *UpdatePhraseSetOperation |
| DeletePhraseSet(context.Context, *speechpb.DeletePhraseSetRequest, ...gax.CallOption) (*DeletePhraseSetOperation, error) |
| DeletePhraseSetOperation(name string) *DeletePhraseSetOperation |
| UndeletePhraseSet(context.Context, *speechpb.UndeletePhraseSetRequest, ...gax.CallOption) (*UndeletePhraseSetOperation, error) |
| UndeletePhraseSetOperation(name string) *UndeletePhraseSetOperation |
| GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) |
| ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator |
| CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error |
| DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error |
| GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator |
| } |
| |
| // Client is a client for interacting with Cloud Speech-to-Text API. |
| // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| // |
| // Enables speech transcription and resource management. |
| type Client struct { |
| // The internal transport-dependent client. |
| internalClient internalClient |
| |
| // The call options for this service. |
| CallOptions *CallOptions |
| |
| // LROClient is used internally to handle long-running operations. |
| // It is exposed so that its CallOptions can be modified if required. |
| // Users should not Close this client. |
| LROClient *lroauto.OperationsClient |
| } |
| |
| // Wrapper methods routed to the internal client. |
| |
| // Close closes the connection to the API service. The user should invoke this when |
| // the client is no longer required. |
| func (c *Client) Close() error { |
| return c.internalClient.Close() |
| } |
| |
| // setGoogleClientInfo sets the name and version of the application in |
| // the `x-goog-api-client` header passed on each request. Intended for |
| // use by Google-written clients. |
| func (c *Client) setGoogleClientInfo(keyval ...string) { |
| c.internalClient.setGoogleClientInfo(keyval...) |
| } |
| |
| // Connection returns a connection to the API service. |
| // |
| // Deprecated: Connections are now pooled so this method does not always |
| // return the same resource. |
| func (c *Client) Connection() *grpc.ClientConn { |
| return c.internalClient.Connection() |
| } |
| |
| // CreateRecognizer creates a Recognizer. |
| func (c *Client) CreateRecognizer(ctx context.Context, req *speechpb.CreateRecognizerRequest, opts ...gax.CallOption) (*CreateRecognizerOperation, error) { |
| return c.internalClient.CreateRecognizer(ctx, req, opts...) |
| } |
| |
| // CreateRecognizerOperation returns a new CreateRecognizerOperation from a given name. |
| // The name must be that of a previously created CreateRecognizerOperation, possibly from a different process. |
| func (c *Client) CreateRecognizerOperation(name string) *CreateRecognizerOperation { |
| return c.internalClient.CreateRecognizerOperation(name) |
| } |
| |
| // ListRecognizers lists Recognizers. |
| func (c *Client) ListRecognizers(ctx context.Context, req *speechpb.ListRecognizersRequest, opts ...gax.CallOption) *RecognizerIterator { |
| return c.internalClient.ListRecognizers(ctx, req, opts...) |
| } |
| |
| // GetRecognizer returns the requested |
| // Recognizer. Fails with |
| // NOT_FOUND if the requested Recognizer doesn’t |
| // exist. |
| func (c *Client) GetRecognizer(ctx context.Context, req *speechpb.GetRecognizerRequest, opts ...gax.CallOption) (*speechpb.Recognizer, error) { |
| return c.internalClient.GetRecognizer(ctx, req, opts...) |
| } |
| |
| // UpdateRecognizer updates the Recognizer. |
| func (c *Client) UpdateRecognizer(ctx context.Context, req *speechpb.UpdateRecognizerRequest, opts ...gax.CallOption) (*UpdateRecognizerOperation, error) { |
| return c.internalClient.UpdateRecognizer(ctx, req, opts...) |
| } |
| |
| // UpdateRecognizerOperation returns a new UpdateRecognizerOperation from a given name. |
| // The name must be that of a previously created UpdateRecognizerOperation, possibly from a different process. |
| func (c *Client) UpdateRecognizerOperation(name string) *UpdateRecognizerOperation { |
| return c.internalClient.UpdateRecognizerOperation(name) |
| } |
| |
| // DeleteRecognizer deletes the Recognizer. |
| func (c *Client) DeleteRecognizer(ctx context.Context, req *speechpb.DeleteRecognizerRequest, opts ...gax.CallOption) (*DeleteRecognizerOperation, error) { |
| return c.internalClient.DeleteRecognizer(ctx, req, opts...) |
| } |
| |
| // DeleteRecognizerOperation returns a new DeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created DeleteRecognizerOperation, possibly from a different process. |
| func (c *Client) DeleteRecognizerOperation(name string) *DeleteRecognizerOperation { |
| return c.internalClient.DeleteRecognizerOperation(name) |
| } |
| |
| // UndeleteRecognizer undeletes the Recognizer. |
| func (c *Client) UndeleteRecognizer(ctx context.Context, req *speechpb.UndeleteRecognizerRequest, opts ...gax.CallOption) (*UndeleteRecognizerOperation, error) { |
| return c.internalClient.UndeleteRecognizer(ctx, req, opts...) |
| } |
| |
| // UndeleteRecognizerOperation returns a new UndeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created UndeleteRecognizerOperation, possibly from a different process. |
| func (c *Client) UndeleteRecognizerOperation(name string) *UndeleteRecognizerOperation { |
| return c.internalClient.UndeleteRecognizerOperation(name) |
| } |
| |
| // Recognize performs synchronous Speech recognition: receive results after all audio |
| // has been sent and processed. |
| func (c *Client) Recognize(ctx context.Context, req *speechpb.RecognizeRequest, opts ...gax.CallOption) (*speechpb.RecognizeResponse, error) { |
| return c.internalClient.Recognize(ctx, req, opts...) |
| } |
| |
| // StreamingRecognize performs bidirectional streaming speech recognition: receive results while |
| // sending audio. This method is only available via the gRPC API (not REST). |
| // |
| // This method is not supported for the REST transport. |
| func (c *Client) StreamingRecognize(ctx context.Context, opts ...gax.CallOption) (speechpb.Speech_StreamingRecognizeClient, error) { |
| return c.internalClient.StreamingRecognize(ctx, opts...) |
| } |
| |
| // BatchRecognize performs batch asynchronous speech recognition: send a request with N |
| // audio files and receive a long running operation that can be polled to see |
| // when the transcriptions are finished. |
| func (c *Client) BatchRecognize(ctx context.Context, req *speechpb.BatchRecognizeRequest, opts ...gax.CallOption) (*BatchRecognizeOperation, error) { |
| return c.internalClient.BatchRecognize(ctx, req, opts...) |
| } |
| |
| // BatchRecognizeOperation returns a new BatchRecognizeOperation from a given name. |
| // The name must be that of a previously created BatchRecognizeOperation, possibly from a different process. |
| func (c *Client) BatchRecognizeOperation(name string) *BatchRecognizeOperation { |
| return c.internalClient.BatchRecognizeOperation(name) |
| } |
| |
| // GetConfig returns the requested Config. |
| func (c *Client) GetConfig(ctx context.Context, req *speechpb.GetConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| return c.internalClient.GetConfig(ctx, req, opts...) |
| } |
| |
| // UpdateConfig updates the Config. |
| func (c *Client) UpdateConfig(ctx context.Context, req *speechpb.UpdateConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| return c.internalClient.UpdateConfig(ctx, req, opts...) |
| } |
| |
| // CreateCustomClass creates a CustomClass. |
| func (c *Client) CreateCustomClass(ctx context.Context, req *speechpb.CreateCustomClassRequest, opts ...gax.CallOption) (*CreateCustomClassOperation, error) { |
| return c.internalClient.CreateCustomClass(ctx, req, opts...) |
| } |
| |
| // CreateCustomClassOperation returns a new CreateCustomClassOperation from a given name. |
| // The name must be that of a previously created CreateCustomClassOperation, possibly from a different process. |
| func (c *Client) CreateCustomClassOperation(name string) *CreateCustomClassOperation { |
| return c.internalClient.CreateCustomClassOperation(name) |
| } |
| |
| // ListCustomClasses lists CustomClasses. |
| func (c *Client) ListCustomClasses(ctx context.Context, req *speechpb.ListCustomClassesRequest, opts ...gax.CallOption) *CustomClassIterator { |
| return c.internalClient.ListCustomClasses(ctx, req, opts...) |
| } |
| |
| // GetCustomClass returns the requested |
| // CustomClass. |
| func (c *Client) GetCustomClass(ctx context.Context, req *speechpb.GetCustomClassRequest, opts ...gax.CallOption) (*speechpb.CustomClass, error) { |
| return c.internalClient.GetCustomClass(ctx, req, opts...) |
| } |
| |
| // UpdateCustomClass updates the CustomClass. |
| func (c *Client) UpdateCustomClass(ctx context.Context, req *speechpb.UpdateCustomClassRequest, opts ...gax.CallOption) (*UpdateCustomClassOperation, error) { |
| return c.internalClient.UpdateCustomClass(ctx, req, opts...) |
| } |
| |
| // UpdateCustomClassOperation returns a new UpdateCustomClassOperation from a given name. |
| // The name must be that of a previously created UpdateCustomClassOperation, possibly from a different process. |
| func (c *Client) UpdateCustomClassOperation(name string) *UpdateCustomClassOperation { |
| return c.internalClient.UpdateCustomClassOperation(name) |
| } |
| |
| // DeleteCustomClass deletes the CustomClass. |
| func (c *Client) DeleteCustomClass(ctx context.Context, req *speechpb.DeleteCustomClassRequest, opts ...gax.CallOption) (*DeleteCustomClassOperation, error) { |
| return c.internalClient.DeleteCustomClass(ctx, req, opts...) |
| } |
| |
| // DeleteCustomClassOperation returns a new DeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created DeleteCustomClassOperation, possibly from a different process. |
| func (c *Client) DeleteCustomClassOperation(name string) *DeleteCustomClassOperation { |
| return c.internalClient.DeleteCustomClassOperation(name) |
| } |
| |
| // UndeleteCustomClass undeletes the CustomClass. |
| func (c *Client) UndeleteCustomClass(ctx context.Context, req *speechpb.UndeleteCustomClassRequest, opts ...gax.CallOption) (*UndeleteCustomClassOperation, error) { |
| return c.internalClient.UndeleteCustomClass(ctx, req, opts...) |
| } |
| |
| // UndeleteCustomClassOperation returns a new UndeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created UndeleteCustomClassOperation, possibly from a different process. |
| func (c *Client) UndeleteCustomClassOperation(name string) *UndeleteCustomClassOperation { |
| return c.internalClient.UndeleteCustomClassOperation(name) |
| } |
| |
| // CreatePhraseSet creates a PhraseSet. |
| func (c *Client) CreatePhraseSet(ctx context.Context, req *speechpb.CreatePhraseSetRequest, opts ...gax.CallOption) (*CreatePhraseSetOperation, error) { |
| return c.internalClient.CreatePhraseSet(ctx, req, opts...) |
| } |
| |
| // CreatePhraseSetOperation returns a new CreatePhraseSetOperation from a given name. |
| // The name must be that of a previously created CreatePhraseSetOperation, possibly from a different process. |
| func (c *Client) CreatePhraseSetOperation(name string) *CreatePhraseSetOperation { |
| return c.internalClient.CreatePhraseSetOperation(name) |
| } |
| |
| // ListPhraseSets lists PhraseSets. |
| func (c *Client) ListPhraseSets(ctx context.Context, req *speechpb.ListPhraseSetsRequest, opts ...gax.CallOption) *PhraseSetIterator { |
| return c.internalClient.ListPhraseSets(ctx, req, opts...) |
| } |
| |
| // GetPhraseSet returns the requested |
| // PhraseSet. |
| func (c *Client) GetPhraseSet(ctx context.Context, req *speechpb.GetPhraseSetRequest, opts ...gax.CallOption) (*speechpb.PhraseSet, error) { |
| return c.internalClient.GetPhraseSet(ctx, req, opts...) |
| } |
| |
| // UpdatePhraseSet updates the PhraseSet. |
| func (c *Client) UpdatePhraseSet(ctx context.Context, req *speechpb.UpdatePhraseSetRequest, opts ...gax.CallOption) (*UpdatePhraseSetOperation, error) { |
| return c.internalClient.UpdatePhraseSet(ctx, req, opts...) |
| } |
| |
| // UpdatePhraseSetOperation returns a new UpdatePhraseSetOperation from a given name. |
| // The name must be that of a previously created UpdatePhraseSetOperation, possibly from a different process. |
| func (c *Client) UpdatePhraseSetOperation(name string) *UpdatePhraseSetOperation { |
| return c.internalClient.UpdatePhraseSetOperation(name) |
| } |
| |
| // DeletePhraseSet deletes the PhraseSet. |
| func (c *Client) DeletePhraseSet(ctx context.Context, req *speechpb.DeletePhraseSetRequest, opts ...gax.CallOption) (*DeletePhraseSetOperation, error) { |
| return c.internalClient.DeletePhraseSet(ctx, req, opts...) |
| } |
| |
| // DeletePhraseSetOperation returns a new DeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created DeletePhraseSetOperation, possibly from a different process. |
| func (c *Client) DeletePhraseSetOperation(name string) *DeletePhraseSetOperation { |
| return c.internalClient.DeletePhraseSetOperation(name) |
| } |
| |
| // UndeletePhraseSet undeletes the PhraseSet. |
| func (c *Client) UndeletePhraseSet(ctx context.Context, req *speechpb.UndeletePhraseSetRequest, opts ...gax.CallOption) (*UndeletePhraseSetOperation, error) { |
| return c.internalClient.UndeletePhraseSet(ctx, req, opts...) |
| } |
| |
| // UndeletePhraseSetOperation returns a new UndeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created UndeletePhraseSetOperation, possibly from a different process. |
| func (c *Client) UndeletePhraseSetOperation(name string) *UndeletePhraseSetOperation { |
| return c.internalClient.UndeletePhraseSetOperation(name) |
| } |
| |
| // GetLocation gets information about a location. |
| func (c *Client) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| return c.internalClient.GetLocation(ctx, req, opts...) |
| } |
| |
| // ListLocations lists information about the supported locations for this service. |
| func (c *Client) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| return c.internalClient.ListLocations(ctx, req, opts...) |
| } |
| |
| // CancelOperation is a utility method from google.longrunning.Operations. |
| func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| return c.internalClient.CancelOperation(ctx, req, opts...) |
| } |
| |
| // DeleteOperation is a utility method from google.longrunning.Operations. |
| func (c *Client) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| return c.internalClient.DeleteOperation(ctx, req, opts...) |
| } |
| |
| // GetOperation is a utility method from google.longrunning.Operations. |
| func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| return c.internalClient.GetOperation(ctx, req, opts...) |
| } |
| |
| // ListOperations is a utility method from google.longrunning.Operations. |
| func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| return c.internalClient.ListOperations(ctx, req, opts...) |
| } |
| |
| // gRPCClient is a client for interacting with Cloud Speech-to-Text API over gRPC transport. |
| // |
| // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| type gRPCClient struct { |
| // Connection pool of gRPC connections to the service. |
| connPool gtransport.ConnPool |
| |
| // Points back to the CallOptions field of the containing Client |
| CallOptions **CallOptions |
| |
| // The gRPC API client. |
| client speechpb.SpeechClient |
| |
| // LROClient is used internally to handle long-running operations. |
| // It is exposed so that its CallOptions can be modified if required. |
| // Users should not Close this client. |
| LROClient **lroauto.OperationsClient |
| |
| operationsClient longrunningpb.OperationsClient |
| |
| locationsClient locationpb.LocationsClient |
| |
| // The x-goog-* metadata to be sent with each request. |
| xGoogHeaders []string |
| } |
| |
| // NewClient creates a new speech client based on gRPC. |
| // The returned client must be Closed when it is done being used to clean up its underlying connections. |
| // |
| // Enables speech transcription and resource management. |
| func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| clientOpts := defaultGRPCClientOptions() |
| if newClientHook != nil { |
| hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| if err != nil { |
| return nil, err |
| } |
| clientOpts = append(clientOpts, hookOpts...) |
| } |
| |
| connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| if err != nil { |
| return nil, err |
| } |
| client := Client{CallOptions: defaultCallOptions()} |
| |
| c := &gRPCClient{ |
| connPool: connPool, |
| client: speechpb.NewSpeechClient(connPool), |
| CallOptions: &client.CallOptions, |
| operationsClient: longrunningpb.NewOperationsClient(connPool), |
| locationsClient: locationpb.NewLocationsClient(connPool), |
| } |
| c.setGoogleClientInfo() |
| |
| client.internalClient = c |
| |
| client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) |
| if err != nil { |
| // This error "should not happen", since we are just reusing old connection pool |
| // and never actually need to dial. |
| // If this does happen, we could leak connp. However, we cannot close conn: |
| // If the user invoked the constructor with option.WithGRPCConn, |
| // we would close a connection that's still in use. |
| // TODO: investigate error conditions. |
| return nil, err |
| } |
| c.LROClient = &client.LROClient |
| return &client, nil |
| } |
| |
| // Connection returns a connection to the API service. |
| // |
| // Deprecated: Connections are now pooled so this method does not always |
| // return the same resource. |
| func (c *gRPCClient) Connection() *grpc.ClientConn { |
| return c.connPool.Conn() |
| } |
| |
| // setGoogleClientInfo sets the name and version of the application in |
| // the `x-goog-api-client` header passed on each request. Intended for |
| // use by Google-written clients. |
| func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version) |
| c.xGoogHeaders = []string{ |
| "x-goog-api-client", gax.XGoogHeader(kv...), |
| } |
| } |
| |
| // Close closes the connection to the API service. The user should invoke this when |
| // the client is no longer required. |
| func (c *gRPCClient) Close() error { |
| return c.connPool.Close() |
| } |
| |
| // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| type restClient struct { |
| // The http endpoint to connect to. |
| endpoint string |
| |
| // The http client. |
| httpClient *http.Client |
| |
| // LROClient is used internally to handle long-running operations. |
| // It is exposed so that its CallOptions can be modified if required. |
| // Users should not Close this client. |
| LROClient **lroauto.OperationsClient |
| |
| // The x-goog-* headers to be sent with each request. |
| xGoogHeaders []string |
| |
| // Points back to the CallOptions field of the containing Client |
| CallOptions **CallOptions |
| } |
| |
| // NewRESTClient creates a new speech rest client. |
| // |
| // Enables speech transcription and resource management. |
| func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| clientOpts := append(defaultRESTClientOptions(), opts...) |
| httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| if err != nil { |
| return nil, err |
| } |
| |
| callOpts := defaultRESTCallOptions() |
| c := &restClient{ |
| endpoint: endpoint, |
| httpClient: httpClient, |
| CallOptions: &callOpts, |
| } |
| c.setGoogleClientInfo() |
| |
| lroOpts := []option.ClientOption{ |
| option.WithHTTPClient(httpClient), |
| option.WithEndpoint(endpoint), |
| } |
| opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) |
| if err != nil { |
| return nil, err |
| } |
| c.LROClient = &opClient |
| |
| return &Client{internalClient: c, CallOptions: callOpts}, nil |
| } |
| |
| func defaultRESTClientOptions() []option.ClientOption { |
| return []option.ClientOption{ |
| internaloption.WithDefaultEndpoint("https://speech.googleapis.com"), |
| internaloption.WithDefaultEndpointTemplate("https://speech.UNIVERSE_DOMAIN"), |
| internaloption.WithDefaultMTLSEndpoint("https://speech.mtls.googleapis.com"), |
| internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| internaloption.WithDefaultAudience("https://speech.googleapis.com/"), |
| internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| } |
| } |
| |
| // setGoogleClientInfo sets the name and version of the application in |
| // the `x-goog-api-client` header passed on each request. Intended for |
| // use by Google-written clients. |
| func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN") |
| c.xGoogHeaders = []string{ |
| "x-goog-api-client", gax.XGoogHeader(kv...), |
| } |
| } |
| |
| // Close closes the connection to the API service. The user should invoke this when |
| // the client is no longer required. |
| func (c *restClient) Close() error { |
| // Replace httpClient with nil to force cleanup. |
| c.httpClient = nil |
| return nil |
| } |
| |
| // Connection returns a connection to the API service. |
| // |
| // Deprecated: This method always returns nil. |
| func (c *restClient) Connection() *grpc.ClientConn { |
| return nil |
| } |
| func (c *gRPCClient) CreateRecognizer(ctx context.Context, req *speechpb.CreateRecognizerRequest, opts ...gax.CallOption) (*CreateRecognizerOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).CreateRecognizer[0:len((*c.CallOptions).CreateRecognizer):len((*c.CallOptions).CreateRecognizer)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.CreateRecognizer(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &CreateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) ListRecognizers(ctx context.Context, req *speechpb.ListRecognizersRequest, opts ...gax.CallOption) *RecognizerIterator { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).ListRecognizers[0:len((*c.CallOptions).ListRecognizers):len((*c.CallOptions).ListRecognizers)], opts...) |
| it := &RecognizerIterator{} |
| req = proto.Clone(req).(*speechpb.ListRecognizersRequest) |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.Recognizer, string, error) { |
| resp := &speechpb.ListRecognizersResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.ListRecognizers(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, "", err |
| } |
| |
| it.Response = resp |
| return resp.GetRecognizers(), resp.GetNextPageToken(), nil |
| } |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| func (c *gRPCClient) GetRecognizer(ctx context.Context, req *speechpb.GetRecognizerRequest, opts ...gax.CallOption) (*speechpb.Recognizer, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetRecognizer[0:len((*c.CallOptions).GetRecognizer):len((*c.CallOptions).GetRecognizer)], opts...) |
| var resp *speechpb.Recognizer |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.GetRecognizer(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) UpdateRecognizer(ctx context.Context, req *speechpb.UpdateRecognizerRequest, opts ...gax.CallOption) (*UpdateRecognizerOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer.name", url.QueryEscape(req.GetRecognizer().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UpdateRecognizer[0:len((*c.CallOptions).UpdateRecognizer):len((*c.CallOptions).UpdateRecognizer)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UpdateRecognizer(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UpdateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) DeleteRecognizer(ctx context.Context, req *speechpb.DeleteRecognizerRequest, opts ...gax.CallOption) (*DeleteRecognizerOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).DeleteRecognizer[0:len((*c.CallOptions).DeleteRecognizer):len((*c.CallOptions).DeleteRecognizer)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.DeleteRecognizer(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &DeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) UndeleteRecognizer(ctx context.Context, req *speechpb.UndeleteRecognizerRequest, opts ...gax.CallOption) (*UndeleteRecognizerOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UndeleteRecognizer[0:len((*c.CallOptions).UndeleteRecognizer):len((*c.CallOptions).UndeleteRecognizer)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UndeleteRecognizer(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UndeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) Recognize(ctx context.Context, req *speechpb.RecognizeRequest, opts ...gax.CallOption) (*speechpb.RecognizeResponse, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer", url.QueryEscape(req.GetRecognizer()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).Recognize[0:len((*c.CallOptions).Recognize):len((*c.CallOptions).Recognize)], opts...) |
| var resp *speechpb.RecognizeResponse |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.Recognize(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) StreamingRecognize(ctx context.Context, opts ...gax.CallOption) (speechpb.Speech_StreamingRecognizeClient, error) { |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| var resp speechpb.Speech_StreamingRecognizeClient |
| opts = append((*c.CallOptions).StreamingRecognize[0:len((*c.CallOptions).StreamingRecognize):len((*c.CallOptions).StreamingRecognize)], opts...) |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.StreamingRecognize(ctx, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) BatchRecognize(ctx context.Context, req *speechpb.BatchRecognizeRequest, opts ...gax.CallOption) (*BatchRecognizeOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer", url.QueryEscape(req.GetRecognizer()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).BatchRecognize[0:len((*c.CallOptions).BatchRecognize):len((*c.CallOptions).BatchRecognize)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.BatchRecognize(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &BatchRecognizeOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) GetConfig(ctx context.Context, req *speechpb.GetConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetConfig[0:len((*c.CallOptions).GetConfig):len((*c.CallOptions).GetConfig)], opts...) |
| var resp *speechpb.Config |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.GetConfig(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) UpdateConfig(ctx context.Context, req *speechpb.UpdateConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "config.name", url.QueryEscape(req.GetConfig().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UpdateConfig[0:len((*c.CallOptions).UpdateConfig):len((*c.CallOptions).UpdateConfig)], opts...) |
| var resp *speechpb.Config |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UpdateConfig(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) CreateCustomClass(ctx context.Context, req *speechpb.CreateCustomClassRequest, opts ...gax.CallOption) (*CreateCustomClassOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).CreateCustomClass[0:len((*c.CallOptions).CreateCustomClass):len((*c.CallOptions).CreateCustomClass)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.CreateCustomClass(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &CreateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) ListCustomClasses(ctx context.Context, req *speechpb.ListCustomClassesRequest, opts ...gax.CallOption) *CustomClassIterator { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).ListCustomClasses[0:len((*c.CallOptions).ListCustomClasses):len((*c.CallOptions).ListCustomClasses)], opts...) |
| it := &CustomClassIterator{} |
| req = proto.Clone(req).(*speechpb.ListCustomClassesRequest) |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.CustomClass, string, error) { |
| resp := &speechpb.ListCustomClassesResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.ListCustomClasses(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, "", err |
| } |
| |
| it.Response = resp |
| return resp.GetCustomClasses(), resp.GetNextPageToken(), nil |
| } |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| func (c *gRPCClient) GetCustomClass(ctx context.Context, req *speechpb.GetCustomClassRequest, opts ...gax.CallOption) (*speechpb.CustomClass, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetCustomClass[0:len((*c.CallOptions).GetCustomClass):len((*c.CallOptions).GetCustomClass)], opts...) |
| var resp *speechpb.CustomClass |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.GetCustomClass(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) UpdateCustomClass(ctx context.Context, req *speechpb.UpdateCustomClassRequest, opts ...gax.CallOption) (*UpdateCustomClassOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "custom_class.name", url.QueryEscape(req.GetCustomClass().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UpdateCustomClass[0:len((*c.CallOptions).UpdateCustomClass):len((*c.CallOptions).UpdateCustomClass)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UpdateCustomClass(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UpdateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) DeleteCustomClass(ctx context.Context, req *speechpb.DeleteCustomClassRequest, opts ...gax.CallOption) (*DeleteCustomClassOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).DeleteCustomClass[0:len((*c.CallOptions).DeleteCustomClass):len((*c.CallOptions).DeleteCustomClass)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.DeleteCustomClass(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &DeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) UndeleteCustomClass(ctx context.Context, req *speechpb.UndeleteCustomClassRequest, opts ...gax.CallOption) (*UndeleteCustomClassOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UndeleteCustomClass[0:len((*c.CallOptions).UndeleteCustomClass):len((*c.CallOptions).UndeleteCustomClass)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UndeleteCustomClass(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UndeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) CreatePhraseSet(ctx context.Context, req *speechpb.CreatePhraseSetRequest, opts ...gax.CallOption) (*CreatePhraseSetOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).CreatePhraseSet[0:len((*c.CallOptions).CreatePhraseSet):len((*c.CallOptions).CreatePhraseSet)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.CreatePhraseSet(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &CreatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) ListPhraseSets(ctx context.Context, req *speechpb.ListPhraseSetsRequest, opts ...gax.CallOption) *PhraseSetIterator { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).ListPhraseSets[0:len((*c.CallOptions).ListPhraseSets):len((*c.CallOptions).ListPhraseSets)], opts...) |
| it := &PhraseSetIterator{} |
| req = proto.Clone(req).(*speechpb.ListPhraseSetsRequest) |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.PhraseSet, string, error) { |
| resp := &speechpb.ListPhraseSetsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.ListPhraseSets(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, "", err |
| } |
| |
| it.Response = resp |
| return resp.GetPhraseSets(), resp.GetNextPageToken(), nil |
| } |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| func (c *gRPCClient) GetPhraseSet(ctx context.Context, req *speechpb.GetPhraseSetRequest, opts ...gax.CallOption) (*speechpb.PhraseSet, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetPhraseSet[0:len((*c.CallOptions).GetPhraseSet):len((*c.CallOptions).GetPhraseSet)], opts...) |
| var resp *speechpb.PhraseSet |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.GetPhraseSet(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) UpdatePhraseSet(ctx context.Context, req *speechpb.UpdatePhraseSetRequest, opts ...gax.CallOption) (*UpdatePhraseSetOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "phrase_set.name", url.QueryEscape(req.GetPhraseSet().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UpdatePhraseSet[0:len((*c.CallOptions).UpdatePhraseSet):len((*c.CallOptions).UpdatePhraseSet)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UpdatePhraseSet(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UpdatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) DeletePhraseSet(ctx context.Context, req *speechpb.DeletePhraseSetRequest, opts ...gax.CallOption) (*DeletePhraseSetOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).DeletePhraseSet[0:len((*c.CallOptions).DeletePhraseSet):len((*c.CallOptions).DeletePhraseSet)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.DeletePhraseSet(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &DeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) UndeletePhraseSet(ctx context.Context, req *speechpb.UndeletePhraseSetRequest, opts ...gax.CallOption) (*UndeletePhraseSetOperation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).UndeletePhraseSet[0:len((*c.CallOptions).UndeletePhraseSet):len((*c.CallOptions).UndeletePhraseSet)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.client.UndeletePhraseSet(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return &UndeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| }, nil |
| } |
| |
| func (c *gRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| var resp *locationpb.Location |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.locationsClient.GetLocation(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) |
| it := &LocationIterator{} |
| req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| resp := &locationpb.ListLocationsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.locationsClient.ListLocations(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, "", err |
| } |
| |
| it.Response = resp |
| return resp.GetLocations(), resp.GetNextPageToken(), nil |
| } |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| func (c *gRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| return err |
| } |
| |
| func (c *gRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| return err |
| } |
| |
| func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| var resp *longrunningpb.Operation |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, err |
| } |
| return resp, nil |
| } |
| |
| func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) |
| it := &OperationIterator{} |
| req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| resp := &longrunningpb.ListOperationsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| var err error |
| resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) |
| return err |
| }, opts...) |
| if err != nil { |
| return nil, "", err |
| } |
| |
| it.Response = resp |
| return resp.GetOperations(), resp.GetNextPageToken(), nil |
| } |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // CreateRecognizer creates a Recognizer. |
| func (c *restClient) CreateRecognizer(ctx context.Context, req *speechpb.CreateRecognizerRequest, opts ...gax.CallOption) (*CreateRecognizerOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetRecognizer() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/recognizers", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetRecognizerId() != "" { |
| params.Add("recognizerId", fmt.Sprintf("%v", req.GetRecognizerId())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &CreateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // ListRecognizers lists Recognizers. |
| func (c *restClient) ListRecognizers(ctx context.Context, req *speechpb.ListRecognizersRequest, opts ...gax.CallOption) *RecognizerIterator { |
| it := &RecognizerIterator{} |
| req = proto.Clone(req).(*speechpb.ListRecognizersRequest) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.Recognizer, string, error) { |
| resp := &speechpb.ListRecognizersResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, "", err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/recognizers", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetPageSize() != 0 { |
| params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| } |
| if req.GetPageToken() != "" { |
| params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| } |
| if req.GetShowDeleted() { |
| params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, "", e |
| } |
| it.Response = resp |
| return resp.GetRecognizers(), resp.GetNextPageToken(), nil |
| } |
| |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // GetRecognizer returns the requested |
| // Recognizer. Fails with |
| // NOT_FOUND if the requested Recognizer doesn’t |
| // exist. |
| func (c *restClient) GetRecognizer(ctx context.Context, req *speechpb.GetRecognizerRequest, opts ...gax.CallOption) (*speechpb.Recognizer, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetRecognizer[0:len((*c.CallOptions).GetRecognizer):len((*c.CallOptions).GetRecognizer)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.Recognizer{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // UpdateRecognizer updates the Recognizer. |
| func (c *restClient) UpdateRecognizer(ctx context.Context, req *speechpb.UpdateRecognizerRequest, opts ...gax.CallOption) (*UpdateRecognizerOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetRecognizer() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetRecognizer().GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetUpdateMask() != nil { |
| updateMask, err := protojson.Marshal(req.GetUpdateMask()) |
| if err != nil { |
| return nil, err |
| } |
| params.Add("updateMask", string(updateMask[1:len(updateMask)-1])) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer.name", url.QueryEscape(req.GetRecognizer().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UpdateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // DeleteRecognizer deletes the Recognizer. |
| func (c *restClient) DeleteRecognizer(ctx context.Context, req *speechpb.DeleteRecognizerRequest, opts ...gax.CallOption) (*DeleteRecognizerOperation, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetAllowMissing() { |
| params.Add("allowMissing", fmt.Sprintf("%v", req.GetAllowMissing())) |
| } |
| if req.GetEtag() != "" { |
| params.Add("etag", fmt.Sprintf("%v", req.GetEtag())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &DeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // UndeleteRecognizer undeletes the Recognizer. |
| func (c *restClient) UndeleteRecognizer(ctx context.Context, req *speechpb.UndeleteRecognizerRequest, opts ...gax.CallOption) (*UndeleteRecognizerOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:undelete", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UndeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // Recognize performs synchronous Speech recognition: receive results after all audio |
| // has been sent and processed. |
| func (c *restClient) Recognize(ctx context.Context, req *speechpb.RecognizeRequest, opts ...gax.CallOption) (*speechpb.RecognizeResponse, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:recognize", req.GetRecognizer()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer", url.QueryEscape(req.GetRecognizer()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).Recognize[0:len((*c.CallOptions).Recognize):len((*c.CallOptions).Recognize)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.RecognizeResponse{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // StreamingRecognize performs bidirectional streaming speech recognition: receive results while |
| // sending audio. This method is only available via the gRPC API (not REST). |
| // |
| // This method is not supported for the REST transport. |
| func (c *restClient) StreamingRecognize(ctx context.Context, opts ...gax.CallOption) (speechpb.Speech_StreamingRecognizeClient, error) { |
| return nil, errors.New("StreamingRecognize not yet supported for REST clients") |
| } |
| |
| // BatchRecognize performs batch asynchronous speech recognition: send a request with N |
| // audio files and receive a long running operation that can be polled to see |
| // when the transcriptions are finished. |
| func (c *restClient) BatchRecognize(ctx context.Context, req *speechpb.BatchRecognizeRequest, opts ...gax.CallOption) (*BatchRecognizeOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:batchRecognize", req.GetRecognizer()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "recognizer", url.QueryEscape(req.GetRecognizer()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &BatchRecognizeOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // GetConfig returns the requested Config. |
| func (c *restClient) GetConfig(ctx context.Context, req *speechpb.GetConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetConfig[0:len((*c.CallOptions).GetConfig):len((*c.CallOptions).GetConfig)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.Config{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // UpdateConfig updates the Config. |
| func (c *restClient) UpdateConfig(ctx context.Context, req *speechpb.UpdateConfigRequest, opts ...gax.CallOption) (*speechpb.Config, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetConfig() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetConfig().GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetUpdateMask() != nil { |
| updateMask, err := protojson.Marshal(req.GetUpdateMask()) |
| if err != nil { |
| return nil, err |
| } |
| params.Add("updateMask", string(updateMask[1:len(updateMask)-1])) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "config.name", url.QueryEscape(req.GetConfig().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).UpdateConfig[0:len((*c.CallOptions).UpdateConfig):len((*c.CallOptions).UpdateConfig)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.Config{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // CreateCustomClass creates a CustomClass. |
| func (c *restClient) CreateCustomClass(ctx context.Context, req *speechpb.CreateCustomClassRequest, opts ...gax.CallOption) (*CreateCustomClassOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetCustomClass() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/customClasses", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetCustomClassId() != "" { |
| params.Add("customClassId", fmt.Sprintf("%v", req.GetCustomClassId())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &CreateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // ListCustomClasses lists CustomClasses. |
| func (c *restClient) ListCustomClasses(ctx context.Context, req *speechpb.ListCustomClassesRequest, opts ...gax.CallOption) *CustomClassIterator { |
| it := &CustomClassIterator{} |
| req = proto.Clone(req).(*speechpb.ListCustomClassesRequest) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.CustomClass, string, error) { |
| resp := &speechpb.ListCustomClassesResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, "", err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/customClasses", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetPageSize() != 0 { |
| params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| } |
| if req.GetPageToken() != "" { |
| params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| } |
| if req.GetShowDeleted() { |
| params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, "", e |
| } |
| it.Response = resp |
| return resp.GetCustomClasses(), resp.GetNextPageToken(), nil |
| } |
| |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // GetCustomClass returns the requested |
| // CustomClass. |
| func (c *restClient) GetCustomClass(ctx context.Context, req *speechpb.GetCustomClassRequest, opts ...gax.CallOption) (*speechpb.CustomClass, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetCustomClass[0:len((*c.CallOptions).GetCustomClass):len((*c.CallOptions).GetCustomClass)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.CustomClass{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // UpdateCustomClass updates the CustomClass. |
| func (c *restClient) UpdateCustomClass(ctx context.Context, req *speechpb.UpdateCustomClassRequest, opts ...gax.CallOption) (*UpdateCustomClassOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetCustomClass() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetCustomClass().GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetUpdateMask() != nil { |
| updateMask, err := protojson.Marshal(req.GetUpdateMask()) |
| if err != nil { |
| return nil, err |
| } |
| params.Add("updateMask", string(updateMask[1:len(updateMask)-1])) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "custom_class.name", url.QueryEscape(req.GetCustomClass().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UpdateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // DeleteCustomClass deletes the CustomClass. |
| func (c *restClient) DeleteCustomClass(ctx context.Context, req *speechpb.DeleteCustomClassRequest, opts ...gax.CallOption) (*DeleteCustomClassOperation, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetAllowMissing() { |
| params.Add("allowMissing", fmt.Sprintf("%v", req.GetAllowMissing())) |
| } |
| if req.GetEtag() != "" { |
| params.Add("etag", fmt.Sprintf("%v", req.GetEtag())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &DeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // UndeleteCustomClass undeletes the CustomClass. |
| func (c *restClient) UndeleteCustomClass(ctx context.Context, req *speechpb.UndeleteCustomClassRequest, opts ...gax.CallOption) (*UndeleteCustomClassOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:undelete", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UndeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // CreatePhraseSet creates a PhraseSet. |
| func (c *restClient) CreatePhraseSet(ctx context.Context, req *speechpb.CreatePhraseSetRequest, opts ...gax.CallOption) (*CreatePhraseSetOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetPhraseSet() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/phraseSets", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetPhraseSetId() != "" { |
| params.Add("phraseSetId", fmt.Sprintf("%v", req.GetPhraseSetId())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &CreatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // ListPhraseSets lists PhraseSets. |
| func (c *restClient) ListPhraseSets(ctx context.Context, req *speechpb.ListPhraseSetsRequest, opts ...gax.CallOption) *PhraseSetIterator { |
| it := &PhraseSetIterator{} |
| req = proto.Clone(req).(*speechpb.ListPhraseSetsRequest) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*speechpb.PhraseSet, string, error) { |
| resp := &speechpb.ListPhraseSetsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, "", err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/phraseSets", req.GetParent()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetPageSize() != 0 { |
| params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| } |
| if req.GetPageToken() != "" { |
| params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| } |
| if req.GetShowDeleted() { |
| params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, "", e |
| } |
| it.Response = resp |
| return resp.GetPhraseSets(), resp.GetNextPageToken(), nil |
| } |
| |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // GetPhraseSet returns the requested |
| // PhraseSet. |
| func (c *restClient) GetPhraseSet(ctx context.Context, req *speechpb.GetPhraseSetRequest, opts ...gax.CallOption) (*speechpb.PhraseSet, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetPhraseSet[0:len((*c.CallOptions).GetPhraseSet):len((*c.CallOptions).GetPhraseSet)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &speechpb.PhraseSet{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // UpdatePhraseSet updates the PhraseSet. |
| func (c *restClient) UpdatePhraseSet(ctx context.Context, req *speechpb.UpdatePhraseSetRequest, opts ...gax.CallOption) (*UpdatePhraseSetOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| body := req.GetPhraseSet() |
| jsonReq, err := m.Marshal(body) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetPhraseSet().GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetUpdateMask() != nil { |
| updateMask, err := protojson.Marshal(req.GetUpdateMask()) |
| if err != nil { |
| return nil, err |
| } |
| params.Add("updateMask", string(updateMask[1:len(updateMask)-1])) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "phrase_set.name", url.QueryEscape(req.GetPhraseSet().GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UpdatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // DeletePhraseSet deletes the PhraseSet. |
| func (c *restClient) DeletePhraseSet(ctx context.Context, req *speechpb.DeletePhraseSetRequest, opts ...gax.CallOption) (*DeletePhraseSetOperation, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetAllowMissing() { |
| params.Add("allowMissing", fmt.Sprintf("%v", req.GetAllowMissing())) |
| } |
| if req.GetEtag() != "" { |
| params.Add("etag", fmt.Sprintf("%v", req.GetEtag())) |
| } |
| if req.GetValidateOnly() { |
| params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &DeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // UndeletePhraseSet undeletes the PhraseSet. |
| func (c *restClient) UndeletePhraseSet(ctx context.Context, req *speechpb.UndeletePhraseSetRequest, opts ...gax.CallOption) (*UndeletePhraseSetOperation, error) { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return nil, err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:undelete", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| |
| override := fmt.Sprintf("/v2/%s", resp.GetName()) |
| return &UndeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| pollPath: override, |
| }, nil |
| } |
| |
| // GetLocation gets information about a location. |
| func (c *restClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &locationpb.Location{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // ListLocations lists information about the supported locations for this service. |
| func (c *restClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| it := &LocationIterator{} |
| req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| resp := &locationpb.ListLocationsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, "", err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/locations", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetFilter() != "" { |
| params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| } |
| if req.GetPageSize() != 0 { |
| params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| } |
| if req.GetPageToken() != "" { |
| params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, "", e |
| } |
| it.Response = resp |
| return resp.GetLocations(), resp.GetNextPageToken(), nil |
| } |
| |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // CancelOperation is a utility method from google.longrunning.Operations. |
| func (c *restClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| jsonReq, err := m.Marshal(req) |
| if err != nil { |
| return err |
| } |
| |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v:cancel", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| // Returns nil if there is no error, otherwise wraps |
| // the response code and body into a non-nil error |
| return googleapi.CheckResponse(httpRsp) |
| }, opts...) |
| } |
| |
| // DeleteOperation is a utility method from google.longrunning.Operations. |
| func (c *restClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| // Returns nil if there is no error, otherwise wraps |
| // the response code and body into a non-nil error |
| return googleapi.CheckResponse(httpRsp) |
| }, opts...) |
| } |
| |
| // GetOperation is a utility method from google.longrunning.Operations. |
| func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| |
| hds = append(c.xGoogHeaders, hds...) |
| hds = append(hds, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| resp := &longrunningpb.Operation{} |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq = httpReq.WithContext(ctx) |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, e |
| } |
| return resp, nil |
| } |
| |
| // ListOperations is a utility method from google.longrunning.Operations. |
| func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| it := &OperationIterator{} |
| req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| resp := &longrunningpb.ListOperationsResponse{} |
| if pageToken != "" { |
| req.PageToken = pageToken |
| } |
| if pageSize > math.MaxInt32 { |
| req.PageSize = math.MaxInt32 |
| } else if pageSize != 0 { |
| req.PageSize = int32(pageSize) |
| } |
| baseUrl, err := url.Parse(c.endpoint) |
| if err != nil { |
| return nil, "", err |
| } |
| baseUrl.Path += fmt.Sprintf("/v2/%v/operations", req.GetName()) |
| |
| params := url.Values{} |
| params.Add("$alt", "json;enum-encoding=int") |
| if req.GetFilter() != "" { |
| params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| } |
| if req.GetPageSize() != 0 { |
| params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| } |
| if req.GetPageToken() != "" { |
| params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| } |
| |
| baseUrl.RawQuery = params.Encode() |
| |
| // Build HTTP headers from client and context metadata. |
| hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| headers := gax.BuildHeaders(ctx, hds...) |
| e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| if settings.Path != "" { |
| baseUrl.Path = settings.Path |
| } |
| httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| if err != nil { |
| return err |
| } |
| httpReq.Header = headers |
| |
| httpRsp, err := c.httpClient.Do(httpReq) |
| if err != nil { |
| return err |
| } |
| defer httpRsp.Body.Close() |
| |
| if err = googleapi.CheckResponse(httpRsp); err != nil { |
| return err |
| } |
| |
| buf, err := io.ReadAll(httpRsp.Body) |
| if err != nil { |
| return err |
| } |
| |
| if err := unm.Unmarshal(buf, resp); err != nil { |
| return err |
| } |
| |
| return nil |
| }, opts...) |
| if e != nil { |
| return nil, "", e |
| } |
| it.Response = resp |
| return resp.GetOperations(), resp.GetNextPageToken(), nil |
| } |
| |
| fetch := func(pageSize int, pageToken string) (string, error) { |
| items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| if err != nil { |
| return "", err |
| } |
| it.items = append(it.items, items...) |
| return nextPageToken, nil |
| } |
| |
| it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| it.pageInfo.MaxSize = int(req.GetPageSize()) |
| it.pageInfo.Token = req.GetPageToken() |
| |
| return it |
| } |
| |
| // BatchRecognizeOperation returns a new BatchRecognizeOperation from a given name. |
| // The name must be that of a previously created BatchRecognizeOperation, possibly from a different process. |
| func (c *gRPCClient) BatchRecognizeOperation(name string) *BatchRecognizeOperation { |
| return &BatchRecognizeOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // BatchRecognizeOperation returns a new BatchRecognizeOperation from a given name. |
| // The name must be that of a previously created BatchRecognizeOperation, possibly from a different process. |
| func (c *restClient) BatchRecognizeOperation(name string) *BatchRecognizeOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &BatchRecognizeOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // CreateCustomClassOperation returns a new CreateCustomClassOperation from a given name. |
| // The name must be that of a previously created CreateCustomClassOperation, possibly from a different process. |
| func (c *gRPCClient) CreateCustomClassOperation(name string) *CreateCustomClassOperation { |
| return &CreateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // CreateCustomClassOperation returns a new CreateCustomClassOperation from a given name. |
| // The name must be that of a previously created CreateCustomClassOperation, possibly from a different process. |
| func (c *restClient) CreateCustomClassOperation(name string) *CreateCustomClassOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &CreateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // CreatePhraseSetOperation returns a new CreatePhraseSetOperation from a given name. |
| // The name must be that of a previously created CreatePhraseSetOperation, possibly from a different process. |
| func (c *gRPCClient) CreatePhraseSetOperation(name string) *CreatePhraseSetOperation { |
| return &CreatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // CreatePhraseSetOperation returns a new CreatePhraseSetOperation from a given name. |
| // The name must be that of a previously created CreatePhraseSetOperation, possibly from a different process. |
| func (c *restClient) CreatePhraseSetOperation(name string) *CreatePhraseSetOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &CreatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // CreateRecognizerOperation returns a new CreateRecognizerOperation from a given name. |
| // The name must be that of a previously created CreateRecognizerOperation, possibly from a different process. |
| func (c *gRPCClient) CreateRecognizerOperation(name string) *CreateRecognizerOperation { |
| return &CreateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // CreateRecognizerOperation returns a new CreateRecognizerOperation from a given name. |
| // The name must be that of a previously created CreateRecognizerOperation, possibly from a different process. |
| func (c *restClient) CreateRecognizerOperation(name string) *CreateRecognizerOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &CreateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // DeleteCustomClassOperation returns a new DeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created DeleteCustomClassOperation, possibly from a different process. |
| func (c *gRPCClient) DeleteCustomClassOperation(name string) *DeleteCustomClassOperation { |
| return &DeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // DeleteCustomClassOperation returns a new DeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created DeleteCustomClassOperation, possibly from a different process. |
| func (c *restClient) DeleteCustomClassOperation(name string) *DeleteCustomClassOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &DeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // DeletePhraseSetOperation returns a new DeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created DeletePhraseSetOperation, possibly from a different process. |
| func (c *gRPCClient) DeletePhraseSetOperation(name string) *DeletePhraseSetOperation { |
| return &DeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // DeletePhraseSetOperation returns a new DeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created DeletePhraseSetOperation, possibly from a different process. |
| func (c *restClient) DeletePhraseSetOperation(name string) *DeletePhraseSetOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &DeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // DeleteRecognizerOperation returns a new DeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created DeleteRecognizerOperation, possibly from a different process. |
| func (c *gRPCClient) DeleteRecognizerOperation(name string) *DeleteRecognizerOperation { |
| return &DeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // DeleteRecognizerOperation returns a new DeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created DeleteRecognizerOperation, possibly from a different process. |
| func (c *restClient) DeleteRecognizerOperation(name string) *DeleteRecognizerOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &DeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UndeleteCustomClassOperation returns a new UndeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created UndeleteCustomClassOperation, possibly from a different process. |
| func (c *gRPCClient) UndeleteCustomClassOperation(name string) *UndeleteCustomClassOperation { |
| return &UndeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UndeleteCustomClassOperation returns a new UndeleteCustomClassOperation from a given name. |
| // The name must be that of a previously created UndeleteCustomClassOperation, possibly from a different process. |
| func (c *restClient) UndeleteCustomClassOperation(name string) *UndeleteCustomClassOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UndeleteCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UndeletePhraseSetOperation returns a new UndeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created UndeletePhraseSetOperation, possibly from a different process. |
| func (c *gRPCClient) UndeletePhraseSetOperation(name string) *UndeletePhraseSetOperation { |
| return &UndeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UndeletePhraseSetOperation returns a new UndeletePhraseSetOperation from a given name. |
| // The name must be that of a previously created UndeletePhraseSetOperation, possibly from a different process. |
| func (c *restClient) UndeletePhraseSetOperation(name string) *UndeletePhraseSetOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UndeletePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UndeleteRecognizerOperation returns a new UndeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created UndeleteRecognizerOperation, possibly from a different process. |
| func (c *gRPCClient) UndeleteRecognizerOperation(name string) *UndeleteRecognizerOperation { |
| return &UndeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UndeleteRecognizerOperation returns a new UndeleteRecognizerOperation from a given name. |
| // The name must be that of a previously created UndeleteRecognizerOperation, possibly from a different process. |
| func (c *restClient) UndeleteRecognizerOperation(name string) *UndeleteRecognizerOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UndeleteRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UpdateCustomClassOperation returns a new UpdateCustomClassOperation from a given name. |
| // The name must be that of a previously created UpdateCustomClassOperation, possibly from a different process. |
| func (c *gRPCClient) UpdateCustomClassOperation(name string) *UpdateCustomClassOperation { |
| return &UpdateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UpdateCustomClassOperation returns a new UpdateCustomClassOperation from a given name. |
| // The name must be that of a previously created UpdateCustomClassOperation, possibly from a different process. |
| func (c *restClient) UpdateCustomClassOperation(name string) *UpdateCustomClassOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UpdateCustomClassOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UpdatePhraseSetOperation returns a new UpdatePhraseSetOperation from a given name. |
| // The name must be that of a previously created UpdatePhraseSetOperation, possibly from a different process. |
| func (c *gRPCClient) UpdatePhraseSetOperation(name string) *UpdatePhraseSetOperation { |
| return &UpdatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UpdatePhraseSetOperation returns a new UpdatePhraseSetOperation from a given name. |
| // The name must be that of a previously created UpdatePhraseSetOperation, possibly from a different process. |
| func (c *restClient) UpdatePhraseSetOperation(name string) *UpdatePhraseSetOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UpdatePhraseSetOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |
| |
| // UpdateRecognizerOperation returns a new UpdateRecognizerOperation from a given name. |
| // The name must be that of a previously created UpdateRecognizerOperation, possibly from a different process. |
| func (c *gRPCClient) UpdateRecognizerOperation(name string) *UpdateRecognizerOperation { |
| return &UpdateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| } |
| } |
| |
| // UpdateRecognizerOperation returns a new UpdateRecognizerOperation from a given name. |
| // The name must be that of a previously created UpdateRecognizerOperation, possibly from a different process. |
| func (c *restClient) UpdateRecognizerOperation(name string) *UpdateRecognizerOperation { |
| override := fmt.Sprintf("/v2/%s", name) |
| return &UpdateRecognizerOperation{ |
| lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| pollPath: override, |
| } |
| } |