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