-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.go
78 lines (64 loc) · 2.34 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) Simon Pelczer 2021. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
package main
import (
"context"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/Templum/rabbitmq-connector/pkg/config"
"github.com/Templum/rabbitmq-connector/pkg/connector"
"github.com/Templum/rabbitmq-connector/pkg/openfaas"
"github.com/Templum/rabbitmq-connector/pkg/rabbitmq"
"github.com/Templum/rabbitmq-connector/pkg/types"
"github.com/Templum/rabbitmq-connector/pkg/version"
"github.com/spf13/afero"
_ "go.uber.org/automaxprocs"
)
func main() {
commit, tag := version.GetReleaseInfo()
log.Printf("OpenFaaS RabbitMQ Connector [Version: %s Commit: %s]", tag, commit)
if rawValue, ok := os.LookupEnv("basic_auth"); ok {
active, _ := strconv.ParseBool(rawValue)
if path, ok := os.LookupEnv("secret_mount_path"); ok && active {
log.Printf("Will read basic64 secret from path %s which was set via 'secret_mount_path'", path)
}
}
// Building our Config from envs
conf, validationErr := config.NewConfig(afero.NewOsFs())
if validationErr != nil {
log.Fatalf("During Config validation %s occurred.", validationErr)
}
// Setup Application Context to ensure gracefully shutdowns
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
httpClient := types.MakeHTTPClient(conf.InsecureSkipVerify, conf.MaxClientsPerHost, 60*time.Second)
// Setup OpenFaaS Controller which is used for querying and more
ofSDK := openfaas.NewController(conf, openfaas.NewClient(httpClient, conf.BasicAuth, conf.GatewayURL), openfaas.NewTopicFunctionCache())
go ofSDK.Start(ctx)
log.Printf("Started Cache Task which populates the topic map")
c := connector.New(rabbitmq.NewConnectionManager(rabbitmq.NewBroker(), conf.TLSConfig), rabbitmq.NewFactory(), ofSDK, conf)
err := c.Run()
if err != nil {
log.Fatalf("Received %s during Connector starting", err)
}
signalChannel := make(chan os.Signal, 2)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
sig := <-signalChannel
switch sig {
case os.Interrupt:
log.Printf("Received SIGINT preparing for shutdown")
c.Shutdown()
cancel()
case syscall.SIGTERM:
log.Printf("Received SIGTERM shutting down")
c.Shutdown()
cancel()
}
}