-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (57 loc) · 1.46 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
package main
import (
"math/rand"
"os"
"strconv"
"time"
petname "github.com/dustinkirkland/golang-petname"
"github.com/oskoss/pa-logging/consume"
"github.com/oskoss/pa-logging/publish"
"github.com/sirupsen/logrus"
)
func main() {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetFormatter(&logrus.JSONFormatter{})
projectID := os.Getenv("PROJECT_ID")
if len(projectID) == 0 {
logrus.WithFields(
logrus.Fields{
"projectID": projectID,
}).Error("PROJECT_ID must be set")
os.Exit(1)
}
rand.Seed(time.Now().UTC().UnixNano())
loggerName := getEnv("LOGGER_NAME", petname.Generate(2, "-")+"-logger")
loggerMaxQueueSize := getEnv("QUEUE_MAX_SIZE", "10")
logrus.WithFields(logrus.Fields{
"Project ID": projectID,
"Logger Name": loggerName,
"Logger Max Queue Size": loggerMaxQueueSize,
}).Print("Starting GCP Publisher...")
gcpPublisher, err := publish.NewGcpPublisher(loggerName, loggerMaxQueueSize, projectID)
if err != nil {
logrus.WithFields(
logrus.Fields{
"error": err,
}).Error("Failed to start GCP publisher")
os.Exit(1)
}
port := getEnv("PORT", "8080")
portInt, err := strconv.Atoi(port)
if err != nil {
logrus.WithFields(
logrus.Fields{
"error": err,
"PORT": port,
}).Error("Failed to parse PORT")
os.Exit(1)
}
consume.NewConsumer(gcpPublisher, portInt)
}
func getEnv(key, fallback string) string {
value, exists := os.LookupEnv(key)
if !exists {
value = fallback
}
return value
}