1// Copyright 2020 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 redis is an auto-generated package for the
18// Google Cloud Memorystore for Redis API.
19//
20// Creates and manages Redis instances on the Google Cloud Platform.
21//
22// Use of Context
23//
24// The ctx passed to NewClient is used for authentication requests and
25// for creating the underlying connection, but is not used for subsequent calls.
26// Individual methods on the client use the ctx given to them.
27//
28// To close the open connection, use the Close() method.
29//
30// For information about setting deadlines, reusing contexts, and more
31// please visit pkg.go.dev/cloud.google.com/go.
32package redis // import "cloud.google.com/go/redis/apiv1"
33
34import (
35	"context"
36	"os"
37	"runtime"
38	"strconv"
39	"strings"
40	"unicode"
41
42	"google.golang.org/api/option"
43	"google.golang.org/grpc/metadata"
44)
45
46// For more information on implementing a client constructor hook, see
47// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
48type clientHookParams struct{}
49type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
50
51const versionClient = "20201110"
52
53func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
54	out, _ := metadata.FromOutgoingContext(ctx)
55	out = out.Copy()
56	for _, md := range mds {
57		for k, v := range md {
58			out[k] = append(out[k], v...)
59		}
60	}
61	return metadata.NewOutgoingContext(ctx, out)
62}
63
64func checkDisableDeadlines() (bool, error) {
65	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
66	if !ok {
67		return false, nil
68	}
69
70	b, err := strconv.ParseBool(raw)
71	return b, err
72}
73
74// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
75func DefaultAuthScopes() []string {
76	return []string{
77		"https://www.googleapis.com/auth/cloud-platform",
78	}
79}
80
81// versionGo returns the Go runtime version. The returned string
82// has no whitespace, suitable for reporting in header.
83func versionGo() string {
84	const develPrefix = "devel +"
85
86	s := runtime.Version()
87	if strings.HasPrefix(s, develPrefix) {
88		s = s[len(develPrefix):]
89		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
90			s = s[:p]
91		}
92		return s
93	}
94
95	notSemverRune := func(r rune) bool {
96		return !strings.ContainsRune("0123456789.", r)
97	}
98
99	if strings.HasPrefix(s, "go1") {
100		s = s[2:]
101		var prerelease string
102		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
103			s, prerelease = s[:p], s[p:]
104		}
105		if strings.HasSuffix(s, ".") {
106			s += "0"
107		} else if strings.Count(s, ".") < 2 {
108			s += ".0"
109		}
110		if prerelease != "" {
111			s += "-" + prerelease
112		}
113		return s
114	}
115	return "UNKNOWN"
116}
117