25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

42 satır
1.2 KiB

  1. // Copyright 2018 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. // http://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. package pstest_test
  15. import (
  16. "cloud.google.com/go/pubsub"
  17. "cloud.google.com/go/pubsub/pstest"
  18. "golang.org/x/net/context"
  19. "google.golang.org/api/option"
  20. "google.golang.org/grpc"
  21. )
  22. func ExampleNewServer() {
  23. ctx := context.Background()
  24. // Start a fake server running locally.
  25. srv := pstest.NewServer()
  26. // Connect to the server without using TLS.
  27. conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
  28. if err != nil {
  29. // TODO: Handle error.
  30. }
  31. // Use the connection when creating a pubsub client.
  32. client, err := pubsub.NewClient(ctx, "project", option.WithGRPCConn(conn))
  33. if err != nil {
  34. // TODO: Handle error.
  35. }
  36. defer client.Close()
  37. _ = client // TODO: Use the client.
  38. }