package container import ( "context" "fmt" "github.com/go-redis/redis/v8" "github.com/labstack/echo/v4" "goweb/config" ) type Container struct { Web *echo.Echo Config *config.Config Cache *redis.Client // DB } func NewContainer() *Container { var c Container // Web c.Web = echo.New() // Configuration cfg, err := config.GetConfig() if err != nil { c.Web.Logger.Error(err) c.Web.Logger.Fatal("Failed to load configuration") } c.Config = &cfg // Cache c.Cache = redis.NewClient(&redis.Options{ Addr: fmt.Sprintf("%s:%d", c.Config.Cache.Hostname, c.Config.Cache.Port), Password: c.Config.Cache.Password, }) if _, err = c.Cache.Ping(context.Background()).Result(); err != nil { c.Web.Logger.Error(err) c.Web.Logger.Fatal("Failed to connect to cache server") } return &c }