-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (57 loc) · 1.54 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
package main
import (
"fmt"
"github.com/khu-dev/khumu-comment/config"
"github.com/khu-dev/khumu-comment/container"
"github.com/khu-dev/khumu-comment/infra/message"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
)
func init() {
workingDir, err := os.Getwd()
if err != nil {
log.Error(err)
}
log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
DisableQuote: true,
ForceColors: true,
// line을 깔끔하게 보여줌.
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := strings.Replace(f.File, workingDir+"/", "", -1)
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
},
FullTimestamp: false,
TimestampFormat: "2006/01/03 15:04:05",
})
}
func main() {
log.Println("Args: ", len(os.Args), os.Args)
log.Printf("Default config. %#v\n", config.Config)
termSig := make(chan os.Signal, 3)
signal.Notify(termSig, syscall.SIGINT, syscall.SIGTERM)
cont := container.Build(termSig)
go func() {
// dig container의 concurrent한 invoke를 방지하기 위해
// concurrent하게 invoke 할 경우 Provide에 전달된 메소드가 중복수행될 수 있다.
time.Sleep(3 * time.Second)
err := cont.Invoke(func(h message.MessageHandler) {
h.Listen()
})
log.Fatal(err)
}()
err := cont.Invoke(func(e *echo.Echo) {
e.Logger.Print("Started Server")
e.Logger.Fatal(e.Start(config.Config.Host + ":" + config.Config.Port))
})
if err != nil {
log.Panic(err)
}
}