-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·48 lines (37 loc) · 1009 Bytes
/
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
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/scmn-dev/core/app"
"github.com/scmn-dev/core/config"
"github.com/scmn-dev/core/constants"
"github.com/scmn-dev/core/db"
"github.com/scmn-dev/core/router"
)
func main() {
logger := log.New(os.Stdout, "[sm-core] ", 0)
cfg, err := config.Init(constants.ConfigPath, constants.ConfigName)
if err != nil {
log.Fatal(err)
}
_db, err := db.DBConn(&cfg.Database)
if err != nil {
log.Fatal(err)
}
s := db.New(_db)
app.MigrateSystemTables(s)
srv := &http.Server{
MaxHeaderBytes: 10, // 10 MB
Addr: ":" + cfg.Server.Port,
WriteTimeout: time.Second * time.Duration(cfg.Server.Timeout),
ReadTimeout: time.Second * time.Duration(cfg.Server.Timeout),
IdleTimeout: time.Second * 60,
Handler: router.New(s),
}
logger.Printf("📡 Server listening on %s", cfg.Server.Port)
if err := srv.ListenAndServe(); err != nil {
logger.Fatal(err)
}
}