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 (
|
2024-04-28 10:39:21 +00:00
|
|
|
"flag"
|
2024-07-24 23:45:04 +00:00
|
|
|
"fmt"
|
2024-07-30 14:20:49 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/adapter/kavenegar"
|
2024-01-14 15:53:37 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
|
|
|
|
"git.gocasts.ir/ebhomengo/niki/config"
|
2024-08-01 10:20:18 +00:00
|
|
|
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
|
2024-01-14 15:53:37 +00:00
|
|
|
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-08-01 10:20:18 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/service"
|
2024-01-15 10:33:24 +00:00
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2024-01-14 15:53:37 +00:00
|
|
|
)
|
|
|
|
|
2024-05-15 07:38:39 +00:00
|
|
|
// @securityDefinitions.apikey AuthBearerBenefactor
|
2024-05-14 13:07:09 +00:00
|
|
|
// @in header
|
2024-05-17 20:16:28 +00:00
|
|
|
// @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
|
2024-05-17 20:16:28 +00:00
|
|
|
// @name Authorization
|
2024-07-24 23:45:04 +00:00
|
|
|
// @description Type the word 'Bearer' followed by a space and Admin JWT token.
|
2023-12-16 06:09:50 +00:00
|
|
|
func main() {
|
2024-08-01 10:20:18 +00:00
|
|
|
cfg := Config()
|
|
|
|
db := MariaDB(cfg)
|
2024-07-24 23:45:04 +00:00
|
|
|
defer func() {
|
|
|
|
if err := db.CloseStatements(); err != nil {
|
|
|
|
fmt.Printf("Error closing statements: %v\n", err)
|
|
|
|
}
|
|
|
|
}()
|
2024-08-01 10:20:18 +00:00
|
|
|
rds := Redis(cfg)
|
|
|
|
kvn := Kavenegar(cfg)
|
|
|
|
svc := Service(cfg, db, rds, kvn)
|
|
|
|
httpServer := HTTPServer(cfg, svc)
|
|
|
|
httpServer.Serve()
|
2024-01-14 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func Config() config.Config {
|
|
|
|
return config.C()
|
2024-01-28 21:39:32 +00:00
|
|
|
}
|
2024-01-14 15:53:37 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func MariaDB(cfg config.Config) *mysql.DB {
|
|
|
|
migrate := flag.Bool("migrate", false, "perform database migration")
|
|
|
|
flag.Parse()
|
|
|
|
if *migrate {
|
2024-08-06 11:49:46 +00:00
|
|
|
migrator.New(migrator.Config{
|
|
|
|
MysqlConfig: cfg.Mysql,
|
|
|
|
MigrationPath: "./repository/mysql/migration",
|
|
|
|
MigrationDBName: "gorp_migrations",
|
|
|
|
}).Up()
|
2024-08-01 10:20:18 +00:00
|
|
|
}
|
2024-01-14 15:53:37 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
return mysql.New(cfg.Mysql)
|
2024-01-28 21:39:32 +00:00
|
|
|
}
|
2024-01-25 11:43:39 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func Redis(cfg config.Config) *redis.Adapter {
|
|
|
|
return redis.New(cfg.Redis)
|
|
|
|
}
|
2024-01-16 16:13:06 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func Kavenegar(cfg config.Config) *kavenegar.Adapter {
|
|
|
|
return kavenegar.New(cfg.KavenegarSmsProvider)
|
2024-01-28 21:39:32 +00:00
|
|
|
}
|
2024-01-22 08:14:57 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func Service(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *service.Service {
|
|
|
|
return service.New(cfg, db, rds, smsAdapter)
|
2024-01-28 21:39:32 +00:00
|
|
|
}
|
2024-01-19 16:56:11 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func HTTPServer(cfg config.Config, svc *service.Service) *httpserver.Server {
|
|
|
|
return httpserver.New(cfg, svc)
|
2023-12-15 08:24:06 +00:00
|
|
|
}
|