-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (43 loc) · 1.12 KB
/
Copy pathmain.go
File metadata and controls
51 lines (43 loc) · 1.12 KB
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
package main
import (
"flag"
"github.com/RezaOptic/gin-project-structure/config"
"github.com/RezaOptic/gin-project-structure/repository"
grpcEngine "github.com/RezaOptic/gin-project-structure/router/grpc"
httpEngine "github.com/RezaOptic/gin-project-structure/router/http"
"github.com/RezaOptic/gin-project-structure/service"
"os"
"os/signal"
"sync"
"syscall"
)
func main() {
configFlag := flag.String("config", "dev", "config flag can be dev for develop or prod for production")
prodConfigPath := flag.String("config-path", "", "config-path production config file path")
// init service configs
config.Init(configFlag, prodConfigPath)
// init repositories
repository.Init()
service.NatsInit()
// run http and grpc servers
wg := sync.WaitGroup{}
wg.Add(2)
go httpEngine.Run(config.Configs.Service.HttpPort)
go grpcEngine.Run(config.Configs.Service.GrpcPort)
// handle os signals
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
select {
case <-sigc:
// wg.Done()
// TODO...
os.Exit(1)
}
}()
wg.Wait()
}