| 1 |
// Copyright 2025 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| 16 |
|
| 17 |
package scheduler |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"io" |
| 23 |
"log/slog" |
| 24 |
"net/http" |
| 25 |
|
| 26 |
"github.com/googleapis/gax-go/v2/internallog" |
| 27 |
"github.com/googleapis/gax-go/v2/internallog/grpclog" |
| 28 |
"google.golang.org/api/googleapi" |
| 29 |
"google.golang.org/api/option" |
| 30 |
"google.golang.org/grpc" |
| 31 |
"google.golang.org/protobuf/proto" |
| 32 |
"google.golang.org/protobuf/runtime/protoimpl" |
| 33 |
) |
| 34 |
|
| 35 |
const serviceName = "cloudscheduler.googleapis.com" |
| 36 |
|
| 37 |
var protoVersion = fmt.Sprintf("1.%d", protoimpl.MaxVersion) |
| 38 |
|
| 39 |
// For more information on implementing a client constructor hook, see |
| 40 |
// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. |
| 41 |
type clientHookParams struct{} |
| 42 |
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) |
| 43 |
|
| 44 |
var versionClient string |
| 45 |
|
| 46 |
func getVersionClient() string { |
| 47 |
if versionClient == "" { |
| 48 |
return "UNKNOWN" |
| 49 |
} |
| 50 |
return versionClient |
| 51 |
} |
| 52 |
|
| 53 |
// DefaultAuthScopes reports the default set of authentication scopes to use with this package. |
| 54 |
func DefaultAuthScopes() []string { |
| 55 |
return []string{ |
| 56 |
"https://www.googleapis.com/auth/cloud-platform", |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
func executeHTTPRequestWithResponse(ctx context.Context, client *http.Client, req *http.Request, logger *slog.Logger, body []byte, rpc string) ([]byte, *http.Response, error) { |
| 61 |
logger.DebugContext(ctx, "api request", "serviceName", serviceName, "rpcName", rpc, "request", internallog.HTTPRequest(req, body)) |
| 62 |
resp, err := client.Do(req) |
| 63 |
if err != nil { |
| 64 |
return nil, nil, err |
| 65 |
} |
| 66 |
defer resp.Body.Close() |
| 67 |
buf, err := io.ReadAll(resp.Body) |
| 68 |
if err != nil { |
| 69 |
return nil, nil, err |
| 70 |
} |
| 71 |
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, buf)) |
| 72 |
if err = googleapi.CheckResponseWithBody(resp, buf); err != nil { |
| 73 |
return nil, nil, err |
| 74 |
} |
| 75 |
return buf, resp, nil |
| 76 |
} |
| 77 |
|
| 78 |
func executeHTTPRequest(ctx context.Context, client *http.Client, req *http.Request, logger *slog.Logger, body []byte, rpc string) ([]byte, error) { |
| 79 |
buf, _, err := executeHTTPRequestWithResponse(ctx, client, req, logger, body, rpc) |
| 80 |
return buf, err |
| 81 |
} |
| 82 |
|
| 83 |
func executeStreamingHTTPRequest(ctx context.Context, client *http.Client, req *http.Request, logger *slog.Logger, body []byte, rpc string) (*http.Response, error) { |
| 84 |
logger.DebugContext(ctx, "api request", "serviceName", serviceName, "rpcName", rpc, "request", internallog.HTTPRequest(req, body)) |
| 85 |
resp, err := client.Do(req) |
| 86 |
if err != nil { |
| 87 |
return nil, err |
| 88 |
} |
| 89 |
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, nil)) |
| 90 |
if err = googleapi.CheckResponse(resp); err != nil { |
| 91 |
return nil, err |
| 92 |
} |
| 93 |
return resp, nil |
| 94 |
} |
| 95 |
|
| 96 |
func executeRPC[I proto.Message, O proto.Message](ctx context.Context, fn func(context.Context, I, ...grpc.CallOption) (O, error), req I, opts []grpc.CallOption, logger *slog.Logger, rpc string) (O, error) { |
| 97 |
var zero O |
| 98 |
logger.DebugContext(ctx, "api request", "serviceName", serviceName, "rpcName", rpc, "request", grpclog.ProtoMessageRequest(ctx, req)) |
| 99 |
resp, err := fn(ctx, req, opts...) |
| 100 |
if err != nil { |
| 101 |
return zero, err |
| 102 |
} |
| 103 |
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", grpclog.ProtoMessageResponse(resp)) |
| 104 |
return resp, err |
| 105 |
} |