-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (61 loc) · 2.09 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
package main
import (
"flag"
"github.com/tnolet/tatanka/api"
"github.com/tnolet/tatanka/control"
"github.com/tnolet/tatanka/helpers"
"github.com/tnolet/tatanka/mail"
"github.com/tnolet/tatanka/store"
"log"
"os"
"runtime"
"strconv"
)
const Version = "0.1.0"
var (
HomeRegion = flag.String("homeRegion", "eu-west-1", "Home region")
HomeBucket = flag.String("homeBucket", "tnolet-tatanka", "S3 Bucket")
HomeKey = flag.String("homeKey", "conf/config_example.json", "S3 Key")
localConfig = flag.String("localConfig", "", "Override S3 path for local testing")
HomeEmail = flag.String("homeEmail", "tim@unumotors.com", "Email address")
Port = flag.Int("port", 1980, "Tatanka's API port")
Noop = flag.Bool("noop", false, "Start in noop mode")
NumCPU int
)
func init() {
log.SetFlags(log.LstdFlags)
NumCPU = runtime.NumCPU()
runtime.GOMAXPROCS(NumCPU)
}
func main() {
flag.Parse()
helpers.SetValueFromEnv(&HomeRegion, "TATANKA_HOME_REGION")
helpers.SetValueFromEnv(&HomeBucket, "TATANKA_HOME_BUCKET")
helpers.SetValueFromEnv(&HomeKey, "TATANKA_HOME_KEY")
helpers.SetValueFromEnv(&localConfig, "TATANKA_LOCAL_CONFIG")
helpers.SetValueFromEnv(&Port, "TATANKA_API_PORT")
helpers.SetValueFromEnv(&Noop, "TATANKA_NOOP")
log.Println("Starting Tatanka...")
mailChan := make(chan string, 100)
mailer := mail.New(*HomeEmail, *HomeRegion, mailChan)
mailer.Start()
stateChan := make(chan (store.State))
if len(*HomeBucket) > 0 || len(*HomeKey) > 0 || len(*localConfig) > 0 {
Store := store.New(*HomeRegion, *HomeBucket, *HomeKey, *localConfig, stateChan)
Store.Start()
} else {
log.Fatal("Please provide a Home location")
mailChan <- control.FatalErrorMail("No or invalid home location")
os.Exit(1)
}
controlChan := make(chan (control.Message), 10)
controller := control.New(mailChan, controlChan, stateChan, *Noop)
controller.Start()
controlChan <- &control.Init{}
controlChan <- &control.StartDeathWatch{}
if Api, err := api.New(Version, controller); err != nil {
panic("failed to create REST Api")
} else {
Api.Run("0.0.0.0:" + strconv.Itoa(*Port))
}
}