-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
58 lines (48 loc) · 1.1 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/ottemo/commerce/app"
// using standard set of packages
_ "github.com/ottemo/commerce/basebuild"
"github.com/ottemo/commerce/env"
)
func init() {
// time.Unix() should be in UTC (as it could be not by default)
time.Local = time.UTC
}
// executable file start point
func main() {
defer func() {
if err := app.End(); err != nil { // application close event
fmt.Println(err.Error())
}
}()
// we should intercept os signals to application as we should call app.End() before
signalChain := make(chan os.Signal, 1)
signal.Notify(signalChain, os.Interrupt, syscall.SIGTERM)
go func() {
for _ = range signalChain {
err := app.End()
if err != nil {
_ = env.ErrorDispatch(err)
fmt.Println(err.Error())
}
os.Exit(0)
}
}()
// application start event
if err := app.Start(); err != nil {
_ = env.ErrorDispatch(err)
fmt.Println(err.Error())
os.Exit(0)
}
fmt.Println("Ottemo " + app.GetVerboseVersion())
// starting HTTP server
if err := app.Serve(); err != nil {
fmt.Println(err.Error())
}
}