2024-01-25 14:35:04 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log/slog"
|
|
|
|
httpsrv "recipes/internal/app/httpSrv"
|
2024-01-27 20:42:23 +02:00
|
|
|
"recipes/internal/cache_provider/redis"
|
2024-01-25 14:35:04 +02:00
|
|
|
"recipes/internal/config"
|
|
|
|
"recipes/internal/media_storage/minio"
|
|
|
|
"recipes/internal/storage/postgresql"
|
|
|
|
)
|
|
|
|
|
|
|
|
type App struct {
|
|
|
|
HTTPSrv *httpsrv.App
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(log *slog.Logger, cfg *config.Config) *App {
|
|
|
|
// init storage
|
|
|
|
storage, err := postgresql.New(context.Background(), cfg.Postgresql.User, cfg.Postgresql.Password, cfg.Postgresql.Address, cfg.Postgresql.DBName)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-01-27 20:42:23 +02:00
|
|
|
// init cache
|
|
|
|
cache := redis.New(cfg.Redis.Address, cfg.Redis.Password, storage)
|
2024-01-25 14:35:04 +02:00
|
|
|
// init media storage
|
|
|
|
mstorage, err := minio.New(context.Background(), cfg.Minio.Address, cfg.Minio.User, cfg.Minio.Password)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
// init http server
|
2024-01-27 20:42:23 +02:00
|
|
|
httpsrv := httpsrv.New(log, &cfg.HTTPServerConfig, cache, mstorage)
|
2024-01-25 14:35:04 +02:00
|
|
|
// return
|
|
|
|
return &App{HTTPSrv: httpsrv}
|
|
|
|
}
|