How to create a Temporal Client in Go
Use the Dial()
API available in the go.temporal.io/sdk/client
package to create a new Client
.
If you don't provide HostPort
, the Client defaults the address and port number to 127.0.0.1:7233
.
import (
// ...
"go.temporal.io/sdk/client"
)
func main() {
temporalClient, err := client.Dial(client.Options{})
if err != nil {
// ...
}
defer temporalClient.Close()
// ...
}
To connect to your Cluster, specify HostPort
followed by your Cluster address.
import (
// ...
"go.temporal.io/sdk/client"
)
func main() {
temporalClient, err := client.Dial(client.Options{
HostPort: "web.<Namespace_ID>.tmprl.cloud.",
})
if err != nil {
// ...
}
defer temporalClient.Close()
// ...
}