-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (29 loc) · 834 Bytes
/
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
package main
import (
"os"
"os/signal"
"sync"
"syscall"
"github.com/hamedblue1381/vending-machine/api"
"github.com/hamedblue1381/vending-machine/cli"
"github.com/hamedblue1381/vending-machine/state"
)
var (
vendingMachines []state.VendingMachine
mutex sync.Mutex
cliiEnabled string = os.Getenv("CLI_ENABLED")
)
func main() {
updateChan := make(chan []state.VendingMachine)
v := state.NewVendingMachine(20)
h := api.NewVendingMachineHandler(v, vendingMachines, updateChan, &mutex)
apiService := api.NewApiService()
if cliiEnabled != "" && cliiEnabled == "true" {
cliService := cli.NewCliService(v, vendingMachines, &mutex, updateChan)
go cliService.Start()
}
go apiService.Start(h)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
<-interrupt
}