Temporal Client - Go SDK
A Temporal Client enables you to communicate with the Temporal Service. Communication with a Temporal Service lets you perform actions such as starting Workflow Executions, sending Signals to Workflow Executions, sending Queries to Workflow Executions, getting the results of a Workflow Execution, and providing Activity Task Tokens.
For Standalone Activities, a Temporal Client can also start and manage Standalone Activities directly, without involving a Workflow.
This page shows you how to do the following using the Go SDK with the Temporal Client:
- Connect to a local development Temporal Service
- Connect to Temporal Cloud
- Start a Workflow Execution
- Get Workflow results
A Temporal Client cannot be initialized and used inside a Workflow. However, it is acceptable and common to use a Temporal Client inside an Activity to communicate with a Temporal Service.
Connect to development Temporal Service
Use the Dial() API available in the
go.temporal.io/sdk/client package to create a
Client. The Dial() API expects connection options such as the
Temporal Server address, the Namespace to connect to, and Transport Layer Security (TLS) configuration. You can specify
these options in the function call, or specify them using environment variables or a configuration file. We recommend
you use environment variables or a configuration file to manage these connection options securely.
Environment variable and configuration file support were added in Go SDK v1.28.0.
When you are running a Temporal Service locally, such as the Temporal CLI, the connection options you must provide are minimal.
If you don't provide HostPort, the Client defaults the
address and port number to 127.0.0.1:7233, which is the port of the development Temporal Service. If you don't set a
custom Namespace name in the Namespace field, the client connects to the default Namespace.
- Configuration File
- Environment Variables
- Code
You can use a TOML configuration file to set connection options for the Temporal Client. The configuration file lets you
configure multiple profiles, each with its own set of connection options. You can then specify which profile to use when
creating the Temporal Client. You can use the environment variable TEMPORAL_CONFIG_FILE to specify the location of the
TOML file or provide the path to the file directly in code. If you don't provide the configuration file path, the SDK
looks for it at the path ~/.config/temporalio/temporal.toml. For a list of all available configuration options, refer
to Environment Configuration