2023-12-16 07:20:01 +00:00
|
|
|
package main
|
2023-12-15 08:24:06 +00:00
|
|
|
|
2024-01-14 15:53:37 +00:00
|
|
|
import (
|
|
|
|
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
|
2024-01-17 10:04:50 +00:00
|
|
|
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
|
|
|
|
kavenegarotp "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/otp"
|
2024-01-14 15:53:37 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/config"
|
|
|
|
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
|
2024-01-16 16:13:06 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
|
2024-01-14 15:53:37 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
2024-01-16 16:13:06 +00:00
|
|
|
mysqladdress "git.gocasts.ir/ebhomengo/niki/repository/mysql/address"
|
2024-01-19 16:56:11 +00:00
|
|
|
mysqladmin "git.gocasts.ir/ebhomengo/niki/repository/mysql/admin"
|
2024-01-14 15:53:37 +00:00
|
|
|
mysqlbenefactor "git.gocasts.ir/ebhomengo/niki/repository/mysql/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
mysqlkindboxreq "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box_req"
|
2024-01-14 15:53:37 +00:00
|
|
|
redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/redis_otp"
|
2024-01-19 16:56:11 +00:00
|
|
|
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
|
|
|
|
adminauthservice "git.gocasts.ir/ebhomengo/niki/service/auth/admin"
|
2024-01-14 15:53:37 +00:00
|
|
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
|
2024-01-19 16:56:11 +00:00
|
|
|
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
|
2024-01-15 10:33:24 +00:00
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2024-01-14 15:53:37 +00:00
|
|
|
)
|
|
|
|
|
2023-12-16 06:09:50 +00:00
|
|
|
func main() {
|
2024-01-14 15:53:37 +00:00
|
|
|
cfg := config.C()
|
|
|
|
// TODO - add command for migrations
|
2024-01-16 16:13:06 +00:00
|
|
|
mgr := migrator.New(cfg.Mysql)
|
|
|
|
mgr.Up()
|
2024-01-14 15:53:37 +00:00
|
|
|
|
2024-01-19 16:56:11 +00:00
|
|
|
authSvc, benefactorSvc, benefactorVld, benefactorKindBoxReqSvc, benefactorKindBoxReqVld, benefactorAddressSvc,
|
|
|
|
adminSvc, adminVld, adminAuthSvc := setupServices(cfg)
|
|
|
|
server := httpserver.New(cfg, benefactorSvc, benefactorVld, authSvc, benefactorKindBoxReqSvc, benefactorKindBoxReqVld,
|
|
|
|
benefactorAddressSvc, adminSvc, adminVld, adminAuthSvc)
|
2024-01-14 15:53:37 +00:00
|
|
|
server.Serve()
|
|
|
|
}
|
|
|
|
|
2024-01-17 20:17:06 +00:00
|
|
|
//nolint:nakedret,gocritic // we are sure of this
|
2024-01-14 15:53:37 +00:00
|
|
|
func setupServices(cfg config.Config) (
|
2024-01-15 10:33:24 +00:00
|
|
|
authSvc authservice.Service, benefactorSvc benefactorservice.Service, benefactorVld benefactorvalidator.Validator,
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service, benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator,
|
2024-01-19 16:56:11 +00:00
|
|
|
benefactorAddressSvc benefactoraddressservice.Service, adminSvc adminservice.Service, adminVld adminvalidator.Validator, adminAuthSvc adminauthservice.Service,
|
2024-01-14 15:53:37 +00:00
|
|
|
) {
|
2024-01-15 10:33:24 +00:00
|
|
|
authSvc = authservice.New(cfg.Auth)
|
2024-01-14 15:53:37 +00:00
|
|
|
|
|
|
|
MysqlRepo := mysql.New(cfg.Mysql)
|
|
|
|
|
|
|
|
redisAdapter := redis.New(cfg.Redis)
|
|
|
|
RedisOtp := redisotp.New(redisAdapter)
|
|
|
|
benefactorMysql := mysqlbenefactor.New(MysqlRepo)
|
2024-01-17 10:04:50 +00:00
|
|
|
kavenegarSmsProvider := smsprovider.New(cfg.KavenegarSmsProvider)
|
|
|
|
otpSmsProvider := kavenegarotp.New(kavenegarSmsProvider)
|
2024-01-14 15:53:37 +00:00
|
|
|
authGenerator := authservice.New(cfg.Auth)
|
|
|
|
|
2024-01-17 10:04:50 +00:00
|
|
|
benefactorSvc = benefactorservice.New(cfg.BenefactorSvc, RedisOtp, otpSmsProvider, authGenerator, benefactorMysql)
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorAddressMysql := mysqladdress.New(MysqlRepo)
|
2024-01-17 20:17:06 +00:00
|
|
|
benefactorAddressSvc = benefactoraddressservice.New(benefactorAddressMysql)
|
2024-01-19 16:37:15 +00:00
|
|
|
benefactorVld = benefactorvalidator.New(benefactorSvc, benefactorAddressSvc)
|
2024-01-16 16:13:06 +00:00
|
|
|
|
2024-01-19 16:37:15 +00:00
|
|
|
benefactorKindBoxReqMysql := mysqlkindboxreq.New(MysqlRepo)
|
|
|
|
benefactorKindBoxReqSvc = benefactorkindboxreqservice.New(benefactorKindBoxReqMysql)
|
2024-01-17 20:17:06 +00:00
|
|
|
benefactorKindBoxReqVld = benefactorkindboxreqvalidator.New(benefactorKindBoxReqMysql, benefactorSvc, benefactorAddressSvc)
|
2024-01-16 16:13:06 +00:00
|
|
|
|
2024-01-19 16:56:11 +00:00
|
|
|
adminAuthSvc = adminauthservice.New(cfg.AdminAuth)
|
|
|
|
adminMysql := mysqladmin.New(MysqlRepo)
|
|
|
|
adminVld = adminvalidator.New(adminMysql)
|
|
|
|
adminSvc = adminservice.New(adminMysql, adminAuthSvc)
|
|
|
|
|
2024-01-16 16:13:06 +00:00
|
|
|
return
|
2023-12-15 08:24:06 +00:00
|
|
|
}
|