forked from ebhomengo/niki
Merge pull request 'refactor: remove data from cmd/order package to manage them later' (#301) from fix/order into develop
Reviewed-on: ebhomengo/niki#301
This commit is contained in:
commit
2517737cc5
|
|
@ -1,63 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
purchaseMysql "git.gocasts.ir/ebhomengo/niki/domain/purchase/repository/mysql"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/purchaseapp/service/order"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
|
||||||
)
|
|
||||||
|
|
||||||
func MariaDB() *mysql.DB {
|
|
||||||
cfg := mysql.Config{
|
|
||||||
Username: "niki",
|
|
||||||
Password: "nikiappt0lk2o20",
|
|
||||||
Port: 3306,
|
|
||||||
Host: "localhost",
|
|
||||||
DBName: "niki_db",
|
|
||||||
}
|
|
||||||
migrate := flag.Bool("migrate", false, "perform database migration")
|
|
||||||
flag.Parse()
|
|
||||||
if *migrate {
|
|
||||||
migrator.New(migrator.Config{
|
|
||||||
MysqlConfig: cfg,
|
|
||||||
MigrationPath: "./purchaseapp/repository/mysql/migration",
|
|
||||||
MigrationDBName: "gorp_migrations",
|
|
||||||
}).Up()
|
|
||||||
}
|
|
||||||
|
|
||||||
return mysql.New(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg := mysql.Config{
|
|
||||||
Username: "niki",
|
|
||||||
Password: "nikiappt0lk2o20",
|
|
||||||
Port: 3306,
|
|
||||||
Host: "localhost",
|
|
||||||
DBName: "niki_db",
|
|
||||||
}
|
|
||||||
db := mysql.New(cfg)
|
|
||||||
defer func() {
|
|
||||||
if err := db.CloseStatements(); err != nil {
|
|
||||||
fmt.Printf("Error closing statements: %v\n", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
orderRepo := purchaseMysql.New(db)
|
|
||||||
|
|
||||||
orderSvc := Service(orderRepo)
|
|
||||||
server := HTTPServer(orderSvc)
|
|
||||||
server.Serve()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HTTPServer(orderSvc order.Service) *http.Server {
|
|
||||||
return http.New(orderSvc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Service(orderRepo *purchaseMysql.DB) order.Service {
|
|
||||||
return order.New(orderRepo)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue