gengitkan/cmd/server/container.go

59 lines
1.5 KiB
Go
Raw Normal View History

2019-11-28 11:50:51 +01:00
package main
import (
2020-04-30 10:32:12 +02:00
"forge.cadoles.com/wpetit/gengitkan/internal/config"
"forge.cadoles.com/wpetit/gengitkan/internal/repository"
stormRepo "forge.cadoles.com/wpetit/gengitkan/internal/repository/storm"
2019-12-01 22:12:13 +01:00
"github.com/asdine/storm"
2019-11-28 11:50:51 +01:00
"github.com/gorilla/sessions"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/service"
"gitlab.com/wpetit/goweb/service/session"
"gitlab.com/wpetit/goweb/session/gorilla"
2019-12-01 22:12:13 +01:00
"go.etcd.io/bbolt"
2019-11-28 11:50:51 +01:00
)
func getServiceContainer(conf *config.Config) (*service.Container, error) {
// Initialize and configure service container
ctn := service.NewContainer()
// Create and initialize HTTP session service provider
cookieStore, err := gorilla.CreateCookieSessionStore(64, 32, &sessions.Options{
Path: "/",
HttpOnly: true,
})
if err != nil {
return nil, errors.Wrap(err, "could not create cookie store")
}
ctn.Provide(
session.ServiceName,
gorilla.ServiceProvider("gitea-kan", cookieStore),
)
// Create and expose config service provider
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
2019-12-01 22:12:13 +01:00
// Load Storm database
db, err := storm.Open(conf.Data.DBPath, storm.BoltOptions(
0660,
&bbolt.Options{},
))
if err != nil {
return nil, errors.Wrap(err, "could not open database")
}
boardsRepository := stormRepo.NewBoardRepository(db)
if err := boardsRepository.Init(); err != nil {
return nil, errors.Wrap(err, "could not init boards repository")
}
ctn.Provide(repository.ServiceName, repository.ServiceProvider(
repository.NewRepository(
boardsRepository,
),
))
2019-11-28 11:50:51 +01:00
return ctn, nil
}