| 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 solar |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"log/slog" |
| 23 |
"math" |
| 24 |
"net/http" |
| 25 |
"net/url" |
| 26 |
"time" |
| 27 |
|
| 28 |
solarpb "cloud.google.com/go/maps/solar/apiv1/solarpb" |
| 29 |
gax "github.com/googleapis/gax-go/v2" |
| 30 |
"google.golang.org/api/option" |
| 31 |
"google.golang.org/api/option/internaloption" |
| 32 |
gtransport "google.golang.org/api/transport/grpc" |
| 33 |
httptransport "google.golang.org/api/transport/http" |
| 34 |
httpbodypb "google.golang.org/genproto/googleapis/api/httpbody" |
| 35 |
"google.golang.org/grpc" |
| 36 |
"google.golang.org/grpc/codes" |
| 37 |
"google.golang.org/protobuf/encoding/protojson" |
| 38 |
) |
| 39 |
|
| 40 |
var newClientHook clientHook |
| 41 |
|
| 42 |
// CallOptions contains the retry settings for each method of Client. |
| 43 |
type CallOptions struct { |
| 44 |
FindClosestBuildingInsights []gax.CallOption |
| 45 |
GetDataLayers []gax.CallOption |
| 46 |
GetGeoTiff []gax.CallOption |
| 47 |
} |
| 48 |
|
| 49 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 50 |
return []option.ClientOption{ |
| 51 |
internaloption.WithDefaultEndpoint("solar.googleapis.com:443"), |
| 52 |
internaloption.WithDefaultEndpointTemplate("solar.UNIVERSE_DOMAIN:443"), |
| 53 |
internaloption.WithDefaultMTLSEndpoint("solar.mtls.googleapis.com:443"), |
| 54 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 55 |
internaloption.WithDefaultAudience("https://solar.googleapis.com/"), |
| 56 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 57 |
internaloption.EnableJwtWithScope(), |
| 58 |
internaloption.EnableNewAuthLibrary(), |
| 59 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 60 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
func defaultCallOptions() *CallOptions { |
| 65 |
return &CallOptions{ |
| 66 |
FindClosestBuildingInsights: []gax.CallOption{ |
| 67 |
gax.WithTimeout(60000 * time.Millisecond), |
| 68 |
gax.WithRetry(func() gax.Retryer { |
| 69 |
return gax.OnCodes([]codes.Code{ |
| 70 |
codes.Unavailable, |
| 71 |
}, gax.Backoff{ |
| 72 |
Initial: 1000 * time.Millisecond, |
| 73 |
Max: 10000 * time.Millisecond, |
| 74 |
Multiplier: 1.30, |
| 75 |
}) |
| 76 |
}), |
| 77 |
}, |
| 78 |
GetDataLayers: []gax.CallOption{ |
| 79 |
gax.WithTimeout(60000 * time.Millisecond), |
| 80 |
gax.WithRetry(func() gax.Retryer { |
| 81 |
return gax.OnCodes([]codes.Code{ |
| 82 |
codes.Unavailable, |
| 83 |
}, gax.Backoff{ |
| 84 |
Initial: 1000 * time.Millisecond, |
| 85 |
Max: 10000 * time.Millisecond, |
| 86 |
Multiplier: 1.30, |
| 87 |
}) |
| 88 |
}), |
| 89 |
}, |
| 90 |
GetGeoTiff: []gax.CallOption{ |
| 91 |
gax.WithTimeout(60000 * time.Millisecond), |
| 92 |
gax.WithRetry(func() gax.Retryer { |
| 93 |
return gax.OnCodes([]codes.Code{ |
| 94 |
codes.Unavailable, |
| 95 |
}, gax.Backoff{ |
| 96 |
Initial: 1000 * time.Millisecond, |
| 97 |
Max: 10000 * time.Millisecond, |
| 98 |
Multiplier: 1.30, |
| 99 |
}) |
| 100 |
}), |
| 101 |
}, |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
func defaultRESTCallOptions() *CallOptions { |
| 106 |
return &CallOptions{ |
| 107 |
FindClosestBuildingInsights: []gax.CallOption{ |
| 108 |
gax.WithTimeout(60000 * time.Millisecond), |
| 109 |
gax.WithRetry(func() gax.Retryer { |
| 110 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 111 |
Initial: 1000 * time.Millisecond, |
| 112 |
Max: 10000 * time.Millisecond, |
| 113 |
Multiplier: 1.30, |
| 114 |
}, |
| 115 |
http.StatusServiceUnavailable) |
| 116 |
}), |
| 117 |
}, |
| 118 |
GetDataLayers: []gax.CallOption{ |
| 119 |
gax.WithTimeout(60000 * time.Millisecond), |
| 120 |
gax.WithRetry(func() gax.Retryer { |
| 121 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 122 |
Initial: 1000 * time.Millisecond, |
| 123 |
Max: 10000 * time.Millisecond, |
| 124 |
Multiplier: 1.30, |
| 125 |
}, |
| 126 |
http.StatusServiceUnavailable) |
| 127 |
}), |
| 128 |
}, |
| 129 |
GetGeoTiff: []gax.CallOption{ |
| 130 |
gax.WithTimeout(60000 * time.Millisecond), |
| 131 |
gax.WithRetry(func() gax.Retryer { |
| 132 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 133 |
Initial: 1000 * time.Millisecond, |
| 134 |
Max: 10000 * time.Millisecond, |
| 135 |
Multiplier: 1.30, |
| 136 |
}, |
| 137 |
http.StatusServiceUnavailable) |
| 138 |
}), |
| 139 |
}, |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
// internalClient is an interface that defines the methods available from Solar API. |
| 144 |
type internalClient interface { |
| 145 |
Close() error |
| 146 |
setGoogleClientInfo(...string) |
| 147 |
Connection() *grpc.ClientConn |
| 148 |
FindClosestBuildingInsights(context.Context, *solarpb.FindClosestBuildingInsightsRequest, ...gax.CallOption) (*solarpb.BuildingInsights, error) |
| 149 |
GetDataLayers(context.Context, *solarpb.GetDataLayersRequest, ...gax.CallOption) (*solarpb.DataLayers, error) |
| 150 |
GetGeoTiff(context.Context, *solarpb.GetGeoTiffRequest, ...gax.CallOption) (*httpbodypb.HttpBody, error) |
| 151 |
} |
| 152 |
|
| 153 |
// Client is a client for interacting with Solar API. |
| 154 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 155 |
// |
| 156 |
// Service definition for the Solar API. |
| 157 |
type Client struct { |
| 158 |
// The internal transport-dependent client. |
| 159 |
internalClient internalClient |
| 160 |
|
| 161 |
// The call options for this service. |
| 162 |
CallOptions *CallOptions |
| 163 |
} |
| 164 |
|
| 165 |
// Wrapper methods routed to the internal client. |
| 166 |
|
| 167 |
// Close closes the connection to the API service. The user should invoke this when |
| 168 |
// the client is no longer required. |
| 169 |
func (c *Client) Close() error { |
| 170 |
return c.internalClient.Close() |
| 171 |
} |
| 172 |
|
| 173 |
// setGoogleClientInfo sets the name and version of the application in |
| 174 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 175 |
// use by Google-written clients. |
| 176 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 177 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 178 |
} |
| 179 |
|
| 180 |
// Connection returns a connection to the API service. |
| 181 |
// |
| 182 |
// Deprecated: Connections are now pooled so this method does not always |
| 183 |
// return the same resource. |
| 184 |
func (c *Client) Connection() *grpc.ClientConn { |
| 185 |
return c.internalClient.Connection() |
| 186 |
} |
| 187 |
|
| 188 |
// FindClosestBuildingInsights locates the building whose centroid is closest to a query point. Returns an |
| 189 |
// error with code NOT_FOUND if there are no buildings within approximately |
| 190 |
// 50m of the query point. |
| 191 |
func (c *Client) FindClosestBuildingInsights(ctx context.Context, req *solarpb.FindClosestBuildingInsightsRequest, opts ...gax.CallOption) (*solarpb.BuildingInsights, error) { |
| 192 |
return c.internalClient.FindClosestBuildingInsights(ctx, req, opts...) |
| 193 |
} |
| 194 |
|
| 195 |
// GetDataLayers gets solar information for a region surrounding a location. |
| 196 |
// Returns an error with code NOT_FOUND if the location is outside |
| 197 |
// the coverage area. |
| 198 |
func (c *Client) GetDataLayers(ctx context.Context, req *solarpb.GetDataLayersRequest, opts ...gax.CallOption) (*solarpb.DataLayers, error) { |
| 199 |
return c.internalClient.GetDataLayers(ctx, req, opts...) |
| 200 |
} |
| 201 |
|
| 202 |
// GetGeoTiff returns an image by its ID. |
| 203 |
func (c *Client) GetGeoTiff(ctx context.Context, req *solarpb.GetGeoTiffRequest, opts ...gax.CallOption) (*httpbodypb.HttpBody, error) { |
| 204 |
return c.internalClient.GetGeoTiff(ctx, req, opts...) |
| 205 |
} |
| 206 |
|
| 207 |
// gRPCClient is a client for interacting with Solar API over gRPC transport. |
| 208 |
// |
| 209 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 210 |
type gRPCClient struct { |
| 211 |
// Connection pool of gRPC connections to the service. |
| 212 |
connPool gtransport.ConnPool |
| 213 |
|
| 214 |
// Points back to the CallOptions field of the containing Client |
| 215 |
CallOptions **CallOptions |
| 216 |
|
| 217 |
// The gRPC API client. |
| 218 |
client solarpb.SolarClient |
| 219 |
|
| 220 |
// The x-goog-* metadata to be sent with each request. |
| 221 |
xGoogHeaders []string |
| 222 |
|
| 223 |
logger *slog.Logger |
| 224 |
} |
| 225 |
|
| 226 |
// NewClient creates a new solar client based on gRPC. |
| 227 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 228 |
// |
| 229 |
// Service definition for the Solar API. |
| 230 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 231 |
clientOpts := defaultGRPCClientOptions() |
| 232 |
if newClientHook != nil { |
| 233 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 234 |
if err != nil { |
| 235 |
return nil, err |
| 236 |
} |
| 237 |
clientOpts = append(clientOpts, hookOpts...) |
| 238 |
} |
| 239 |
|
| 240 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 241 |
if err != nil { |
| 242 |
return nil, err |
| 243 |
} |
| 244 |
client := Client{CallOptions: defaultCallOptions()} |
| 245 |
|
| 246 |
c := &gRPCClient{ |
| 247 |
connPool: connPool, |
| 248 |
client: solarpb.NewSolarClient(connPool), |
| 249 |
CallOptions: &client.CallOptions, |
| 250 |
logger: internaloption.GetLogger(opts), |
| 251 |
} |
| 252 |
c.setGoogleClientInfo() |
| 253 |
|
| 254 |
client.internalClient = c |
| 255 |
|
| 256 |
return &client, nil |
| 257 |
} |
| 258 |
|
| 259 |
// Connection returns a connection to the API service. |
| 260 |
// |
| 261 |
// Deprecated: Connections are now pooled so this method does not always |
| 262 |
// return the same resource. |
| 263 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 264 |
return c.connPool.Conn() |
| 265 |
} |
| 266 |
|
| 267 |
// setGoogleClientInfo sets the name and version of the application in |
| 268 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 269 |
// use by Google-written clients. |
| 270 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 271 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 272 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 273 |
c.xGoogHeaders = []string{ |
| 274 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
// Close closes the connection to the API service. The user should invoke this when |
| 279 |
// the client is no longer required. |
| 280 |
func (c *gRPCClient) Close() error { |
| 281 |
return c.connPool.Close() |
| 282 |
} |
| 283 |
|
| 284 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 285 |
type restClient struct { |
| 286 |
// The http endpoint to connect to. |
| 287 |
endpoint string |
| 288 |
|
| 289 |
// The http client. |
| 290 |
httpClient *http.Client |
| 291 |
|
| 292 |
// The x-goog-* headers to be sent with each request. |
| 293 |
xGoogHeaders []string |
| 294 |
|
| 295 |
// Points back to the CallOptions field of the containing Client |
| 296 |
CallOptions **CallOptions |
| 297 |
|
| 298 |
logger *slog.Logger |
| 299 |
} |
| 300 |
|
| 301 |
// NewRESTClient creates a new solar rest client. |
| 302 |
// |
| 303 |
// Service definition for the Solar API. |
| 304 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 305 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 306 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 307 |
if err != nil { |
| 308 |
return nil, err |
| 309 |
} |
| 310 |
|
| 311 |
callOpts := defaultRESTCallOptions() |
| 312 |
c := &restClient{ |
| 313 |
endpoint: endpoint, |
| 314 |
httpClient: httpClient, |
| 315 |
CallOptions: &callOpts, |
| 316 |
logger: internaloption.GetLogger(opts), |
| 317 |
} |
| 318 |
c.setGoogleClientInfo() |
| 319 |
|
| 320 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 321 |
} |
| 322 |
|
| 323 |
func defaultRESTClientOptions() []option.ClientOption { |
| 324 |
return []option.ClientOption{ |
| 325 |
internaloption.WithDefaultEndpoint("https://solar.googleapis.com"), |
| 326 |
internaloption.WithDefaultEndpointTemplate("https://solar.UNIVERSE_DOMAIN"), |
| 327 |
internaloption.WithDefaultMTLSEndpoint("https://solar.mtls.googleapis.com"), |
| 328 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 329 |
internaloption.WithDefaultAudience("https://solar.googleapis.com/"), |
| 330 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 331 |
internaloption.EnableNewAuthLibrary(), |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
// setGoogleClientInfo sets the name and version of the application in |
| 336 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 337 |
// use by Google-written clients. |
| 338 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 339 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 340 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 341 |
c.xGoogHeaders = []string{ |
| 342 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
// Close closes the connection to the API service. The user should invoke this when |
| 347 |
// the client is no longer required. |
| 348 |
func (c *restClient) Close() error { |
| 349 |
// Replace httpClient with nil to force cleanup. |
| 350 |
c.httpClient = nil |
| 351 |
return nil |
| 352 |
} |
| 353 |
|
| 354 |
// Connection returns a connection to the API service. |
| 355 |
// |
| 356 |
// Deprecated: This method always returns nil. |
| 357 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 358 |
return nil |
| 359 |
} |
| 360 |
func (c *gRPCClient) FindClosestBuildingInsights(ctx context.Context, req *solarpb.FindClosestBuildingInsightsRequest, opts ...gax.CallOption) (*solarpb.BuildingInsights, error) { |
| 361 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 362 |
opts = append((*c.CallOptions).FindClosestBuildingInsights[0:len((*c.CallOptions).FindClosestBuildingInsights):len((*c.CallOptions).FindClosestBuildingInsights)], opts...) |
| 363 |
var resp *solarpb.BuildingInsights |
| 364 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 365 |
var err error |
| 366 |
resp, err = executeRPC(ctx, c.client.FindClosestBuildingInsights, req, settings.GRPC, c.logger, "FindClosestBuildingInsights") |
| 367 |
return err |
| 368 |
}, opts...) |
| 369 |
if err != nil { |
| 370 |
return nil, err |
| 371 |
} |
| 372 |
return resp, nil |
| 373 |
} |
| 374 |
|
| 375 |
func (c *gRPCClient) GetDataLayers(ctx context.Context, req *solarpb.GetDataLayersRequest, opts ...gax.CallOption) (*solarpb.DataLayers, error) { |
| 376 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 377 |
opts = append((*c.CallOptions).GetDataLayers[0:len((*c.CallOptions).GetDataLayers):len((*c.CallOptions).GetDataLayers)], opts...) |
| 378 |
var resp *solarpb.DataLayers |
| 379 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 380 |
var err error |
| 381 |
resp, err = executeRPC(ctx, c.client.GetDataLayers, req, settings.GRPC, c.logger, "GetDataLayers") |
| 382 |
return err |
| 383 |
}, opts...) |
| 384 |
if err != nil { |
| 385 |
return nil, err |
| 386 |
} |
| 387 |
return resp, nil |
| 388 |
} |
| 389 |
|
| 390 |
func (c *gRPCClient) GetGeoTiff(ctx context.Context, req *solarpb.GetGeoTiffRequest, opts ...gax.CallOption) (*httpbodypb.HttpBody, error) { |
| 391 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 392 |
opts = append((*c.CallOptions).GetGeoTiff[0:len((*c.CallOptions).GetGeoTiff):len((*c.CallOptions).GetGeoTiff)], opts...) |
| 393 |
var resp *httpbodypb.HttpBody |
| 394 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 395 |
var err error |
| 396 |
resp, err = executeRPC(ctx, c.client.GetGeoTiff, req, settings.GRPC, c.logger, "GetGeoTiff") |
| 397 |
return err |
| 398 |
}, opts...) |
| 399 |
if err != nil { |
| 400 |
return nil, err |
| 401 |
} |
| 402 |
return resp, nil |
| 403 |
} |
| 404 |
|
| 405 |
// FindClosestBuildingInsights locates the building whose centroid is closest to a query point. Returns an |
| 406 |
// error with code NOT_FOUND if there are no buildings within approximately |
| 407 |
// 50m of the query point. |
| 408 |
func (c *restClient) FindClosestBuildingInsights(ctx context.Context, req *solarpb.FindClosestBuildingInsightsRequest, opts ...gax.CallOption) (*solarpb.BuildingInsights, error) { |
| 409 |
baseUrl, err := url.Parse(c.endpoint) |
| 410 |
if err != nil { |
| 411 |
return nil, err |
| 412 |
} |
| 413 |
baseUrl.Path += fmt.Sprintf("/v1/buildingInsights:findClosest") |
| 414 |
|
| 415 |
params := url.Values{} |
| 416 |
params.Add("$alt", "json;enum-encoding=int") |
| 417 |
if req.GetExactQualityRequired() { |
| 418 |
params.Add("exactQualityRequired", fmt.Sprintf("%v", req.GetExactQualityRequired())) |
| 419 |
} |
| 420 |
if items := req.GetExperiments(); len(items) > 0 { |
| 421 |
for _, item := range items { |
| 422 |
params.Add("experiments", fmt.Sprintf("%v", item)) |
| 423 |
} |
| 424 |
} |
| 425 |
if req.GetLocation().GetLatitude() != 0 { |
| 426 |
params.Add("location.latitude", fmt.Sprintf("%v", req.GetLocation().GetLatitude())) |
| 427 |
} |
| 428 |
if req.GetLocation().GetLongitude() != 0 { |
| 429 |
params.Add("location.longitude", fmt.Sprintf("%v", req.GetLocation().GetLongitude())) |
| 430 |
} |
| 431 |
if req.GetRequiredQuality() != 0 { |
| 432 |
params.Add("requiredQuality", fmt.Sprintf("%v", req.GetRequiredQuality())) |
| 433 |
} |
| 434 |
|
| 435 |
baseUrl.RawQuery = params.Encode() |
| 436 |
|
| 437 |
// Build HTTP headers from client and context metadata. |
| 438 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 439 |
headers := gax.BuildHeaders(ctx, hds...) |
| 440 |
opts = append((*c.CallOptions).FindClosestBuildingInsights[0:len((*c.CallOptions).FindClosestBuildingInsights):len((*c.CallOptions).FindClosestBuildingInsights)], opts...) |
| 441 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 442 |
resp := &solarpb.BuildingInsights{} |
| 443 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 444 |
if settings.Path != "" { |
| 445 |
baseUrl.Path = settings.Path |
| 446 |
} |
| 447 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 448 |
if err != nil { |
| 449 |
return err |
| 450 |
} |
| 451 |
httpReq = httpReq.WithContext(ctx) |
| 452 |
httpReq.Header = headers |
| 453 |
|
| 454 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "FindClosestBuildingInsights") |
| 455 |
if err != nil { |
| 456 |
return err |
| 457 |
} |
| 458 |
|
| 459 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 460 |
return err |
| 461 |
} |
| 462 |
|
| 463 |
return nil |
| 464 |
}, opts...) |
| 465 |
if e != nil { |
| 466 |
return nil, e |
| 467 |
} |
| 468 |
return resp, nil |
| 469 |
} |
| 470 |
|
| 471 |
// GetDataLayers gets solar information for a region surrounding a location. |
| 472 |
// Returns an error with code NOT_FOUND if the location is outside |
| 473 |
// the coverage area. |
| 474 |
func (c *restClient) GetDataLayers(ctx context.Context, req *solarpb.GetDataLayersRequest, opts ...gax.CallOption) (*solarpb.DataLayers, error) { |
| 475 |
baseUrl, err := url.Parse(c.endpoint) |
| 476 |
if err != nil { |
| 477 |
return nil, err |
| 478 |
} |
| 479 |
baseUrl.Path += fmt.Sprintf("/v1/dataLayers:get") |
| 480 |
|
| 481 |
params := url.Values{} |
| 482 |
params.Add("$alt", "json;enum-encoding=int") |
| 483 |
if req.GetExactQualityRequired() { |
| 484 |
params.Add("exactQualityRequired", fmt.Sprintf("%v", req.GetExactQualityRequired())) |
| 485 |
} |
| 486 |
if items := req.GetExperiments(); len(items) > 0 { |
| 487 |
for _, item := range items { |
| 488 |
params.Add("experiments", fmt.Sprintf("%v", item)) |
| 489 |
} |
| 490 |
} |
| 491 |
if req.GetLocation().GetLatitude() != 0 { |
| 492 |
params.Add("location.latitude", fmt.Sprintf("%v", req.GetLocation().GetLatitude())) |
| 493 |
} |
| 494 |
if req.GetLocation().GetLongitude() != 0 { |
| 495 |
params.Add("location.longitude", fmt.Sprintf("%v", req.GetLocation().GetLongitude())) |
| 496 |
} |
| 497 |
if req.GetPixelSizeMeters() != 0 { |
| 498 |
params.Add("pixelSizeMeters", fmt.Sprintf("%v", req.GetPixelSizeMeters())) |
| 499 |
} |
| 500 |
params.Add("radiusMeters", fmt.Sprintf("%v", req.GetRadiusMeters())) |
| 501 |
if req.GetRequiredQuality() != 0 { |
| 502 |
params.Add("requiredQuality", fmt.Sprintf("%v", req.GetRequiredQuality())) |
| 503 |
} |
| 504 |
if req.GetView() != 0 { |
| 505 |
params.Add("view", fmt.Sprintf("%v", req.GetView())) |
| 506 |
} |
| 507 |
|
| 508 |
baseUrl.RawQuery = params.Encode() |
| 509 |
|
| 510 |
// Build HTTP headers from client and context metadata. |
| 511 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 512 |
headers := gax.BuildHeaders(ctx, hds...) |
| 513 |
opts = append((*c.CallOptions).GetDataLayers[0:len((*c.CallOptions).GetDataLayers):len((*c.CallOptions).GetDataLayers)], opts...) |
| 514 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 515 |
resp := &solarpb.DataLayers{} |
| 516 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 517 |
if settings.Path != "" { |
| 518 |
baseUrl.Path = settings.Path |
| 519 |
} |
| 520 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 521 |
if err != nil { |
| 522 |
return err |
| 523 |
} |
| 524 |
httpReq = httpReq.WithContext(ctx) |
| 525 |
httpReq.Header = headers |
| 526 |
|
| 527 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDataLayers") |
| 528 |
if err != nil { |
| 529 |
return err |
| 530 |
} |
| 531 |
|
| 532 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 533 |
return err |
| 534 |
} |
| 535 |
|
| 536 |
return nil |
| 537 |
}, opts...) |
| 538 |
if e != nil { |
| 539 |
return nil, e |
| 540 |
} |
| 541 |
return resp, nil |
| 542 |
} |
| 543 |
|
| 544 |
// GetGeoTiff returns an image by its ID. |
| 545 |
func (c *restClient) GetGeoTiff(ctx context.Context, req *solarpb.GetGeoTiffRequest, opts ...gax.CallOption) (*httpbodypb.HttpBody, error) { |
| 546 |
baseUrl, err := url.Parse(c.endpoint) |
| 547 |
if err != nil { |
| 548 |
return nil, err |
| 549 |
} |
| 550 |
baseUrl.Path += fmt.Sprintf("/v1/geoTiff:get") |
| 551 |
|
| 552 |
params := url.Values{} |
| 553 |
params.Add("$alt", "json;enum-encoding=int") |
| 554 |
params.Add("id", fmt.Sprintf("%v", req.GetId())) |
| 555 |
|
| 556 |
baseUrl.RawQuery = params.Encode() |
| 557 |
|
| 558 |
// Build HTTP headers from client and context metadata. |
| 559 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 560 |
headers := gax.BuildHeaders(ctx, hds...) |
| 561 |
opts = append((*c.CallOptions).GetGeoTiff[0:len((*c.CallOptions).GetGeoTiff):len((*c.CallOptions).GetGeoTiff)], opts...) |
| 562 |
resp := &httpbodypb.HttpBody{} |
| 563 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 564 |
if settings.Path != "" { |
| 565 |
baseUrl.Path = settings.Path |
| 566 |
} |
| 567 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 568 |
if err != nil { |
| 569 |
return err |
| 570 |
} |
| 571 |
httpReq = httpReq.WithContext(ctx) |
| 572 |
httpReq.Header = headers |
| 573 |
|
| 574 |
buf, httpRsp, err := executeHTTPRequestWithResponse(ctx, c.httpClient, httpReq, c.logger, nil, "GetGeoTiff") |
| 575 |
if err != nil { |
| 576 |
return err |
| 577 |
} |
| 578 |
|
| 579 |
resp.Data = buf |
| 580 |
if headers := httpRsp.Header; len(headers["Content-Type"]) > 0 { |
| 581 |
resp.ContentType = headers["Content-Type"][0] |
| 582 |
} |
| 583 |
|
| 584 |
return nil |
| 585 |
}, opts...) |
| 586 |
if e != nil { |
| 587 |
return nil, e |
| 588 |
} |
| 589 |
return resp, nil |
| 590 |
} |