cadoles-profile/cmd/server/container.go

45 lines
1.3 KiB
Go

package main
import (
"forge.cadoles.com/Cadoles/cadoles-profile/cmd/server/config"
"forge.cadoles.com/Cadoles/cadoles-profile/ldap"
"forge.cadoles.com/wpetit/goweb/service"
"forge.cadoles.com/wpetit/goweb/service/session"
"forge.cadoles.com/wpetit/goweb/service/template"
"forge.cadoles.com/wpetit/goweb/session/gorilla"
"forge.cadoles.com/wpetit/goweb/template/html"
"github.com/gorilla/sessions"
"github.com/pkg/errors"
)
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, "error while creating session store")
}
ctn.Provide(
session.ServiceName,
gorilla.ServiceProvider("ldap-profile", cookieStore),
)
// Create and expose template service provider
ctn.Provide(template.ServiceName, html.ServiceProvider(conf.HTTP.TemplateDir))
// Create and expose ldap service provider
ctn.Provide(ldap.ServiceName, ldap.ServiceProvider(conf.LDAP.URL))
// Create and expose ldap service provider
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
return ctn, nil
}