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

100 lines
4.7 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 (
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
kavenegarotp "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/otp"
"git.gocasts.ir/ebhomengo/niki/config"
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
mysqladdress "git.gocasts.ir/ebhomengo/niki/repository/mysql/address"
mysqladmin "git.gocasts.ir/ebhomengo/niki/repository/mysql/admin"
mysqlbenefactor "git.gocasts.ir/ebhomengo/niki/repository/mysql/benefactor"
mysqlkindbox "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box"
mysqlkindboxreq "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box_req"
redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/redis_otp"
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
adminauthservice "git.gocasts.ir/ebhomengo/niki/service/auth/admin"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth/benefactor"
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
_ "github.com/go-sql-driver/mysql"
)
2023-12-16 06:09:50 +00:00
func main() {
cfg := config.C()
// TODO - add command for migrations
mgr := migrator.New(cfg.Mysql)
mgr.Up()
2024-01-25 16:54:42 +00:00
authSvc,
benefactorSvc,
benefactorVld,
benefactorKindBoxReqSvc,
benefactorKindBoxReqVld,
benefactorAddressSvc,
benefactorAddressVld,
adminSvc,
adminVld,
adminAuthSvc,
adminKindBoxReqSvc,
adminKindBoxReqVld := setupServices(cfg)
server := httpserver.New(cfg, benefactorSvc, benefactorVld, authSvc, benefactorKindBoxReqSvc, benefactorKindBoxReqVld,
2024-01-25 16:54:42 +00:00
benefactorAddressSvc, benefactorAddressVld, adminSvc, adminVld, adminAuthSvc, adminKindBoxReqSvc, adminKindBoxReqVld)
server.Serve()
}
2024-01-17 20:17:06 +00:00
//nolint:nakedret,gocritic // we are sure of this
func setupServices(cfg config.Config) (
authSvc authservice.Service, benefactorSvc benefactorservice.Service, benefactorVld benefactorvalidator.Validator,
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service, benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator,
benefactorAddressSvc benefactoraddressservice.Service,
benefactorAddressVld benefactoraddressvalidator.Validator,
2024-01-25 16:54:42 +00:00
adminSvc adminservice.Service, adminVld adminvalidator.Validator,
adminAuthSvc adminauthservice.Service,
adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxreqvalidator.Validator,
2024-01-25 16:54:42 +00:00
) {
authSvc = authservice.New(cfg.Auth)
MysqlRepo := mysql.New(cfg.Mysql)
redisAdapter := redis.New(cfg.Redis)
RedisOtp := redisotp.New(redisAdapter)
benefactorMysql := mysqlbenefactor.New(MysqlRepo)
kavenegarSmsProvider := smsprovider.New(cfg.KavenegarSmsProvider)
otpSmsProvider := kavenegarotp.New(kavenegarSmsProvider)
authGenerator := authservice.New(cfg.Auth)
benefactorSvc = benefactorservice.New(cfg.BenefactorSvc, RedisOtp, otpSmsProvider, authGenerator, benefactorMysql)
benefactorAddressMysql := mysqladdress.New(MysqlRepo)
2024-01-17 20:17:06 +00:00
benefactorAddressSvc = benefactoraddressservice.New(benefactorAddressMysql)
benefactorAddressVld = benefactoraddressvalidator.New(benefactorSvc, benefactorAddressMysql)
benefactorVld = benefactorvalidator.New()
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)
mysqlkindboxRepo := mysqlkindbox.New(MysqlRepo)
adminkindboxsvc := adminkindboxservice.New(mysqlkindboxRepo)
adminKindBoxReqSvc = adminkindboxreqservice.New(benefactorKindBoxReqMysql, adminkindboxsvc)
adminKindBoxReqVld = adminkindboxreqvalidator.New(benefactorKindBoxReqMysql)
adminAuthSvc = adminauthservice.New(cfg.AdminAuth)
adminMysql := mysqladmin.New(MysqlRepo)
adminVld = adminvalidator.New(adminMysql)
adminSvc = adminservice.New(adminMysql, adminAuthSvc)
return
2023-12-15 08:24:06 +00:00
}