gengitkan/cmd/server/container.go

35 lines
896 B
Go

package main
import (
"forge.cadoles.com/wpetit/gitea-kan/internal/config"
"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"
)
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))
return ctn, nil
}