-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (63 loc) · 1.5 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
73
74
75
76
77
package main
import (
"database/sql"
"io/ioutil"
"log"
"os"
"github.com/ramadani/adminarea-cli/src/migration"
_ "github.com/go-sql-driver/mysql"
"github.com/ramadani/adminarea-cli/command"
"github.com/ramadani/adminarea-cli/src/repository"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
)
type dbConfig struct {
Driver string `yaml:"driver"`
Dsn string `yaml:"dsn"`
}
type config struct {
DB dbConfig `yaml:"db"`
}
func (cog *config) readFromFile(filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal(file, cog)
if err != nil {
log.Fatal(err)
}
}
func main() {
cog := new(config)
cog.readFromFile("adminarea_config.yml")
db, err := sql.Open(cog.DB.Driver, cog.DB.Dsn)
if err != nil {
log.Fatal(err)
}
defer db.Close()
migrate := migration.NewMySQLMigration(db)
repo := repository.NewMySQLRepository(db)
setupCommand := command.NewSetupCommand(migrate)
countryCommand := command.NewCountryCommand(repo)
provinceCommand := command.NewProvinceCommand(repo)
cityCommand := command.NewCityCommand(repo)
districtCommand := command.NewDistrictCommand(repo)
villageCommand := command.NewVillageCommand(repo)
app := cli.NewApp()
app.Name = "adminarea-cli"
app.Usage = "Administrative Area Command Line Tool"
app.Version = "0.1.0"
app.Commands = []cli.Command{
setupCommand,
countryCommand,
provinceCommand,
cityCommand,
districtCommand,
villageCommand,
}
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}