-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (59 loc) · 1.52 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
65
66
67
68
69
70
71
72
package main
import (
"os"
"os/signal"
"syscall"
"github.com/apm-dev/oha/src/config"
"github.com/apm-dev/oha/src/httpserver"
"github.com/apm-dev/oha/src/pkg/dbutils"
"github.com/apm-dev/oha/src/user"
userhttp "github.com/apm-dev/oha/src/user/http"
"github.com/apm-dev/oha/src/user/sql"
log "github.com/sirupsen/logrus"
)
func main() {
config := config.NewConfig()
logLevel, err := log.ParseLevel(config.App.LogLevel)
noError(err)
log.SetLevel(logLevel)
// Database
dbconfig := &dbutils.PostgresConfig{
Host: config.Database.Host,
Port: config.Database.Port,
User: config.Database.User,
Passwd: config.Database.Password,
DB: config.Database.DB,
MigrationPathURL: "file://migrations",
}
dbutils.ApplyPgsqlDatabaseMigrations(dbconfig)
db, err := dbutils.NewPgsqlConnection(dbconfig)
noError(err)
// Repository
userRepo := usersql.NewUserRepo(db)
// Service
userSvc := user.NewService(userRepo)
// HTTP Controller
userCtrl := userhttp.NewUserController(userSvc)
// HTTP Server
server := httpserver.NewServer(userCtrl)
server.Start(config.App.WebPort, config.App.HttpPathPrefix)
waitForSignal()
server.Stop()
}
func noError(err error) {
if err != nil {
panic(err)
}
}
func waitForSignal() {
var stop = make(chan struct{})
go func() {
var sig = make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sig)
<-sig
log.Info("got interrupt, shutting down...")
stop <- struct{}{}
}()
<-stop
}