-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.go
61 lines (54 loc) · 1.65 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
52
53
54
55
56
57
58
59
60
61
package main
// @@@SNIPSTART money-transfer-project-template-go-worker-cloud-import
import (
"crypto/tls"
"log"
"os"
"github.com/joho/godotenv"
// @@@SNIPEND
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
"money-transfer-project-template-go/app"
)
func main() {
// @@@SNIPSTART money-transfer-project-template-go-worker-env
err := godotenv.Load(".env")
if err != nil {
log.Fatalln("Unable to load environment variables from file", err)
}
// @@@SNIPEND
// @@@SNIPSTART money-transfer-project-template-go-worker-key-pair
clientKeyPath := os.Getenv("TEMPORAL_MTLS_TLS_KEY")
clientCertPath := os.Getenv("TEMPORAL_MTLS_TLS_CERT")
cert, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
if err != nil {
log.Fatalln("Unable to load cert and key pair.", err)
}
// @@@SNIPEND
// @@@SNIPSTART money-transfer-project-template-go-worker-options
namespace := os.Getenv("TEMPORAL_NAMESPACE")
hostPort := os.Getenv("TEMPORAL_HOST_URL")
c, err := client.Dial(client.Options{
HostPort: hostPort,
Namespace: namespace,
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{Certificates: []tls.Certificate{cert}},
},
})
// @@@SNIPEND
if err != nil {
log.Fatalln("Unable to create Temporal client.", err)
}
defer c.Close()
w := worker.New(c, app.MoneyTransferTaskQueueName, worker.Options{})
// This worker hosts both Workflow and Activity functions.
w.RegisterWorkflow(app.MoneyTransfer)
w.RegisterActivity(app.Withdraw)
w.RegisterActivity(app.Deposit)
w.RegisterActivity(app.Refund)
// Start listening to the Task Queue.
err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("unable to start Worker", err)
}
}