mirror of https://github.com/grpc/grpc.io.git
Update Go documentation to use NewClient instead of Dial (#1295)
This commit is contained in:
parent
571730d1c2
commit
708f7a1ce9
|
@ -96,9 +96,8 @@ As the error is on the client side, let's first click on
|
|||
TopChannels is a collection of root channels which don't have parents. In
|
||||
gRPC-Go, a top channel is a
|
||||
[ClientConn](https://godoc.org/google.golang.org/grpc#ClientConn) created by the
|
||||
user through [Dial](https://godoc.org/google.golang.org/grpc#Dial) or
|
||||
[DialContext](https://godoc.org/google.golang.org/grpc#DialContext), and used
|
||||
for making RPC calls. Top channels are of
|
||||
user through [NewClient](https://godoc.org/google.golang.org/grpc#NewClient),
|
||||
and used for making RPC calls. Top channels are of
|
||||
[Channel](https://github.com/grpc/grpc-proto/blob/9b13d199cc0d4703c7ea26c9c330ba695866eb23/grpc/channelz/v1/channelz.proto#L37)
|
||||
type in channelz, which is an abstraction of a connection that an RPC can be
|
||||
issued to.
|
||||
|
|
|
@ -15,7 +15,7 @@ code:
|
|||
)
|
||||
|
||||
altsTC := alts.NewClientCreds(alts.DefaultClientOptions())
|
||||
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(altsTC))
|
||||
conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(altsTC))
|
||||
```
|
||||
server_credentials: |
|
||||
```go
|
||||
|
@ -37,7 +37,7 @@ code:
|
|||
clientOpts := alts.DefaultClientOptions()
|
||||
clientOpts.TargetServiceAccounts = []string{expectedServerSA}
|
||||
altsTC := alts.NewClientCreds(clientOpts)
|
||||
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(altsTC))
|
||||
conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(altsTC))
|
||||
```
|
||||
client_authorization: |
|
||||
```go
|
||||
|
|
|
@ -389,12 +389,12 @@ service. You can see our complete example client code in
|
|||
|
||||
To call service methods, we first need to create a gRPC *channel* to communicate
|
||||
with the server. We create this by passing the server address and port number to
|
||||
`grpc.Dial()` as follows:
|
||||
`grpc.NewClient()` as follows:
|
||||
|
||||
```go
|
||||
var opts []grpc.DialOption
|
||||
...
|
||||
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||
conn, err := grpc.NewClient(*serverAddr, opts...)
|
||||
if err != nil {
|
||||
...
|
||||
}
|
||||
|
@ -402,8 +402,8 @@ defer conn.Close()
|
|||
```
|
||||
|
||||
You can use `DialOptions` to set the auth credentials (for example, TLS, GCE
|
||||
credentials, or JWT credentials) in `grpc.Dial` when a service requires them.
|
||||
The `RouteGuide` service doesn't require any credentials.
|
||||
credentials, or JWT credentials) in `grpc.NewClient` when a service requires
|
||||
them. The `RouteGuide` service doesn't require any credentials.
|
||||
|
||||
Once the gRPC *channel* is setup, we need a client *stub* to perform RPCs. We
|
||||
get it using the `NewRouteGuideClient` method provided by the `pb` package
|
||||
|
|
Loading…
Reference in New Issue