1 // Copyright 2023 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 // Package debugger is an auto-generated package for the 16 // Stackdriver Debugger API. 17 // 18 // Examines the call stack and variables of a running application without 19 // stopping or slowing it down. 20 // 21 // # General documentation 22 // 23 // For information about setting deadlines, reusing contexts, and more 24 // please visit https://pkg.go.dev/cloud.google.com/go. 25 // 26 // # Example usage 27 // 28 // To get started with this package, create a client. 29 // 30 // ctx := context.Background() 31 // // This snippet has been automatically generated and should be regarded as a code template only. 32 // // It will require modifications to work: 33 // // - It may require correct/in-range values for request initialization. 34 // // - It may require specifying regional endpoints when creating the service client as shown in: 35 // // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 36 // c, err := debugger.NewController2Client(ctx) 37 // if err != nil { 38 // // TODO: Handle error. 39 // } 40 // defer c.Close() 41 // 42 // The client will use your default application credentials. Clients should be reused instead of created as needed. 43 // The methods of Client are safe for concurrent use by multiple goroutines. 44 // The returned client must be Closed when it is done being used. 45 // 46 // # Using the Client 47 // 48 // The following is an example of making an API call with the newly created client. 49 // 50 // ctx := context.Background() 51 // // This snippet has been automatically generated and should be regarded as a code template only. 52 // // It will require modifications to work: 53 // // - It may require correct/in-range values for request initialization. 54 // // - It may require specifying regional endpoints when creating the service client as shown in: 55 // // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 56 // c, err := debugger.NewController2Client(ctx) 57 // if err != nil { 58 // // TODO: Handle error. 59 // } 60 // defer c.Close() 61 // 62 // req := &debuggerpb.RegisterDebuggeeRequest{ 63 // // TODO: Fill request struct fields. 64 // // See https://pkg.go.dev/cloud.google.com/go/debugger/apiv2/debuggerpb#RegisterDebuggeeRequest. 65 // } 66 // resp, err := c.RegisterDebuggee(ctx, req) 67 // if err != nil { 68 // // TODO: Handle error. 69 // } 70 // // TODO: Use resp. 71 // _ = resp 72 // 73 // # Use of Context 74 // 75 // The ctx passed to NewController2Client is used for authentication requests and 76 // for creating the underlying connection, but is not used for subsequent calls. 77 // Individual methods on the client use the ctx given to them. 78 // 79 // To close the open connection, use the Close() method. 80 package debugger // import "cloud.google.com/go/debugger/apiv2" 81 82 import ( 83 "context" 84 "net/http" 85 "os" 86 "strconv" 87 88 "google.golang.org/api/option" 89 "google.golang.org/grpc/metadata" 90 ) 91 92 // For more information on implementing a client constructor hook, see 93 // https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. 94 type clientHookParams struct{} 95 type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) 96 97 var versionClient string 98 99 func getVersionClient() string { 100 if versionClient == "" { 101 return "UNKNOWN" 102 } 103 return versionClient 104 } 105 106 func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { 107 out, _ := metadata.FromOutgoingContext(ctx) 108 out = out.Copy() 109 for _, md := range mds { 110 for k, v := range md { 111 out[k] = append(out[k], v...) 112 } 113 } 114 return metadata.NewOutgoingContext(ctx, out) 115 } 116 117 func checkDisableDeadlines() (bool, error) { 118 raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") 119 if !ok { 120 return false, nil 121 } 122 123 b, err := strconv.ParseBool(raw) 124 return b, err 125 } 126 127 // DefaultAuthScopes reports the default set of authentication scopes to use with this package. 128 func DefaultAuthScopes() []string { 129 return []string{ 130 "https://www.googleapis.com/auth/cloud-platform", 131 "https://www.googleapis.com/auth/cloud_debugger", 132 } 133 } 134 135 // buildHeaders extracts metadata from the outgoing context, joins it with any other 136 // given metadata, and converts them into a http.Header. 137 func buildHeaders(ctx context.Context, mds ...metadata.MD) http.Header { 138 if cmd, ok := metadata.FromOutgoingContext(ctx); ok { 139 mds = append(mds, cmd) 140 } 141 md := metadata.Join(mds...) 142 return http.Header(md) 143 } 144