-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (43 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"crypto/tls"
"log"
"os"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
"rotation-demo/app"
)
func main() {
// get env values; validation and error handling omitted for brevity
hostPort := os.Getenv("TEMPORAL_ADDRESS")
namespace := os.Getenv("TEMPORAL_NAMESPACE")
clientCertPath := os.Getenv("TEMPORAL_TLS_CERT")
clientKeyPath := os.Getenv("TEMPORAL_TLS_KEY")
// Load the cert via the GetClientCertificate function in the ConnectionOptions of the Client
temporalClient, err := client.Dial(client.Options{
HostPort: hostPort,
Namespace: namespace,
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{
GetClientCertificate: func(info *tls.CertificateRequestInfo) (*tls.Certificate, error) {
log.Println("GetClientCertificate: loading X509 client cert and key")
cert, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
if err != nil {
return nil, err
}
return &cert, nil
},
},
},
})
if err != nil {
log.Fatalln("Unable to connect to Temporal Cloud.", err)
}
defer temporalClient.Close()
w := worker.New(temporalClient, "greeting-tasks", worker.Options{})
w.RegisterWorkflow(app.GreetSomeone)
err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}