-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (39 loc) · 898 Bytes
/
main.go
File metadata and controls
49 lines (39 loc) · 898 Bytes
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
package main
import (
"fmt"
"log"
"github.com/ptaas-tool/base-api/cmd"
"github.com/ptaas-tool/base-api/internal/config"
"github.com/ptaas-tool/base-api/internal/storage/sql"
"github.com/spf13/cobra"
)
func main() {
// load configs
cfg := config.Load("config.yml")
// database connection
db, err := sql.NewConnection(cfg.MySQL)
if err != nil {
log.Fatal(fmt.Errorf("[main] failed in connecting to mysql server error=%w", err))
}
// perform migrations if needed
if cfg.MySQL.Migrate {
migrateInstance := cmd.Migrate{
Cfg: cfg.Migrate,
Db: db,
}
migrateInstance.Do()
}
// create root command
root := cobra.Command{}
// add sub commands to root
root.AddCommand(
cmd.Core{
Cfg: cfg,
Db: db,
}.Command(),
)
// execute root command
if er := root.Execute(); er != nil {
log.Fatal(fmt.Errorf("[main] failed to execute command error=%w", er))
}
}