Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

49 řádky
1.4 KiB

  1. /*
  2. Copyright 2015 Google LLC
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package option contains common code for dealing with client options.
  14. package option
  15. import (
  16. "fmt"
  17. "os"
  18. "google.golang.org/api/option"
  19. "google.golang.org/grpc"
  20. )
  21. // DefaultClientOptions returns the default client options to use for the
  22. // client's gRPC connection.
  23. func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOption, error) {
  24. var o []option.ClientOption
  25. // Check the environment variables for the bigtable emulator.
  26. // Dial it directly and don't pass any credentials.
  27. if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
  28. conn, err := grpc.Dial(addr, grpc.WithInsecure())
  29. if err != nil {
  30. return nil, fmt.Errorf("emulator grpc.Dial: %v", err)
  31. }
  32. o = []option.ClientOption{option.WithGRPCConn(conn)}
  33. } else {
  34. o = []option.ClientOption{
  35. option.WithEndpoint(endpoint),
  36. option.WithScopes(scope),
  37. option.WithUserAgent(userAgent),
  38. }
  39. }
  40. return o, nil
  41. }