Skip to main content

How to connect to a Temporal Cluster 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.

Set a custom Namespace name in the Namespace field on an instance of the Client Options.

Use the ConnectionOptions API to connect a Client with mTLS.

import (
// ...

"go.temporal.io/sdk/client"
)
func main() {
cert, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
if err != nil {
return err
}
client, err := client.Dial(client.Options{
HostPort: "your-custom-namespace.tmprl.cloud:7233",
Namespace: "your-custom-namespace",
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{Certificates: []tls.Certificate{cert}},
},
}
defer temporalClient.Close()
// ...
}