forked from ebhomengo/niki
1
0
Fork 0
niki/main.go

74 lines
1.9 KiB
Go
Raw Normal View History

2023-12-16 07:20:01 +00:00
package main
2023-12-15 08:24:06 +00:00
import (
"flag"
"fmt"
"git.gocasts.ir/ebhomengo/niki/adapter/kavenegar"
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
"git.gocasts.ir/ebhomengo/niki/config"
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
"git.gocasts.ir/ebhomengo/niki/service"
_ "github.com/go-sql-driver/mysql"
)
2024-05-15 07:38:39 +00:00
// @securityDefinitions.apikey AuthBearerBenefactor
2024-05-14 13:07:09 +00:00
// @in header
// @name Authorization
// @description Type the word 'Bearer' followed by a space and Benefactor JWT token
2024-05-15 07:38:39 +00:00
// @securityDefinitions.apikey AuthBearerAdmin
// @in header
// @name Authorization
// @description Type the word 'Bearer' followed by a space and Admin JWT token.
2023-12-16 06:09:50 +00:00
func main() {
cfg := Config()
db := MariaDB(cfg)
defer func() {
if err := db.CloseStatements(); err != nil {
fmt.Printf("Error closing statements: %v\n", err)
}
}()
rds := Redis(cfg)
kvn := Kavenegar(cfg)
svc := Service(cfg, db, rds, kvn)
httpServer := HTTPServer(cfg, svc)
httpServer.Serve()
}
func Config() config.Config {
return config.C()
}
func MariaDB(cfg config.Config) *mysql.DB {
migrate := flag.Bool("migrate", false, "perform database migration")
flag.Parse()
if *migrate {
migrator.New(migrator.Config{
MysqlConfig: cfg.Mysql,
MigrationPath: "./repository/mysql/migration",
MigrationDBName: "gorp_migrations",
}).Up()
}
return mysql.New(cfg.Mysql)
}
func Redis(cfg config.Config) *redis.Adapter {
return redis.New(cfg.Redis)
}
func Kavenegar(cfg config.Config) *kavenegar.Adapter {
return kavenegar.New(cfg.KavenegarSmsProvider)
}
func Service(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *service.Service {
return service.New(cfg, db, rds, smsAdapter)
}
func HTTPServer(cfg config.Config, svc *service.Service) *httpserver.Server {
return httpserver.New(cfg, svc)
2023-12-15 08:24:06 +00:00
}