-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 1.04 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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/jawacompu10/juice_shop/recipe_store/business"
"github.com/jawacompu10/juice_shop/recipe_store/repo"
"github.com/jawacompu10/juice_shop/recipe_store/transport/http"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("Starting recipe_store")
errorChan := make(chan error)
db, err := repo.New(repo.DBInfo{
ConnectionString: "mongodb://localhost:27017/",
DBName: "juice_shop",
CollectionName: "recipe_store",
})
if err != nil {
log.Fatalln("Could not connect to DB")
}
go handleSignals(&errorChan)
recipeStore := business.New(db)
httpTransport := http.New(recipeStore)
go func() {
errorChan <- httpTransport.Start(map[string]string{
"port": "8080",
})
}()
log.Println("Stopping recipe_store: ", <-errorChan)
}
func handleSignals(errorChan *chan error) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
*errorChan <- fmt.Errorf("Signal recieved: %s", <-signalChan)
}