recipes2/internal/app/app.go

32 lines
785 B
Go

package app
import (
"context"
"log/slog"
httpsrv "recipes/internal/app/httpSrv"
"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)
}
// 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
httpsrv := httpsrv.New(log, &cfg.HTTPServerConfig, storage, mstorage)
// return
return &App{HTTPSrv: httpsrv}
}