Skip to content

added legacy Go API connection setups #3619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions docs/develop/go/temporal-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ You can find the Namespace and Account ID, as well as the endpoint, on the Names

Now, when instantiating a Temporal `client` in your Temporal Go SDK code, provide the API key with the following `clientOptions`:

<details>
<summary><strong>v1.33.0+</strong></summary>

```go
clientOptions := client.Options{
HostPort: <endpoint>,
Expand All @@ -139,6 +142,90 @@ creds := client.NewAPIKeyDynamicCredentials(
myKey = myKeyUpdated
```

</details>

<details>
<summary><strong>v1.26.0 to v1.33.0 (exclusive)</strong></summary>

Create an initial connection:

```go
clientOptions := client.Options{
HostPort: <endpoint>,
Namespace: <namespace_id>.<account_id>,
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{},
DialOptions: []grpc.DialOption{
grpc.WithUnaryInterceptor(
func(ctx context.Context, method string, req any, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(
metadata.AppendToOutgoingContext(ctx, "temporal-namespace", <namespace_id>.<account_id>),
method,
req,
reply,
cc,
opts...,
)
},
),
},
},
Credentials: client.NewAPIKeyStaticCredentials(apiKey),
}
c, err := client.Dial(clientOptions)
if err != nil {
log.Fatalf("error creating temporal client: %v", err)
}
```

Update an API key:

```go
// Assuming client Credentials created with
var myKey string
creds := client.NewAPIKeyDynamicCredentials(
func(context.Context) (string, error) { return myKey, nil })
// Just update by replacing
myKey = myKeyUpdated
```

</details>

<details>
<summary><strong>pre v1.26.0</strong></summary>

Create an initial connection:

```go
// Create headers provider
type APIKeyProvider struct {
APIKey string
Namespace string
}

func (a *APIKeyProvider) GetHeaders(context.Context) (map[string]string, error) {
return map[string]string{"Authorization": "Bearer " + a.APIKey, "temporal-namespace": a.Namespace}, nil
}

// Use headers provider
apiKeyProvider := &APIKeyProvider{APIKey: <APIKey>, Namespace: <namespace_id>.<account_id>}
c, err := client.Dial(client.Options{
HostPort: <endpoint>,
Namespace: <namespace_id>.<account_id>,
HeadersProvider: apiKeyProvider,
ConnectionOptions: client.ConnectionOptions{TLS: &tls.Config{
}},
})
```

Update an API key:

```go
apiKeyProvider.APIKey = myKeyUpdated
```

</details>

### How to connect to Temporal Cloud using mTLS {#connect-to-temporal-cloud-tls}

When you connect to [Temporal Cloud](/cloud) with mTLS, you need to provide additional connection and client options that include the following:
Expand Down