summaryrefslogtreecommitdiff
path: root/main.go
blob: bc8e75a4307d23de707e05b4ef42c2f6bd3820d6 (plain)
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
package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"

	"xengineering.eu/ceres/model"
	"xengineering.eu/ceres/view"
)

func main() {
	flag.Parse()

	if printVersion {
		fmt.Println(gitDescribe)
		os.Exit(0)
	}

	log.Println("Ceres recipe server started")
	defer log.Println("Ceres recipe server stopped")

	if config.Path != "" {
		config.Read()
	}

	storage := model.NewStorage(config.StorageFilePath)
	if !storage.Exists() {
		storage.Create()
	}
	log.Printf("Storage directory: %s\n", storage.Path)

	model.InitDatabase(config.StorageFilePath)
	defer model.CloseDatabase()

	model.InjectTestRecipes()

	view.Init()

	server := NewServer(config.HttpAddress)
	go server.Start()
	defer server.Stop()

	listener := make(chan os.Signal)
	signal.Notify(listener, syscall.SIGTERM)
	signal.Notify(listener, syscall.SIGINT)
	sig := <-listener
	log.Printf("Cleaning up due to OS signal '%v'\n", sig)
}