75 lines
1.8 KiB
Go
Executable File
75 lines
1.8 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/servers/web"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
|
cache "git.coopgo.io/coopgo-apps/parcoursmob/core/utils/storage"
|
|
)
|
|
|
|
func main() {
|
|
cfg, err := ReadConfig()
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("cannot read config!")
|
|
return
|
|
}
|
|
|
|
var (
|
|
dev_env = cfg.GetBool("dev_env")
|
|
webEnabled = cfg.GetBool("server.web.enabled")
|
|
)
|
|
|
|
if dev_env {
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
|
} else {
|
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
}
|
|
|
|
svc, err := services.NewServicesHandler(cfg)
|
|
if err != nil {
|
|
log.Panic().Err(err).Msg("Error creating services handler")
|
|
}
|
|
|
|
kv, err := cache.NewKVHandler(cfg)
|
|
if err != nil {
|
|
log.Panic().Err(err).Msg("Error creating KV handler")
|
|
}
|
|
filestorage, _ := cache.NewFileStorage(cfg)
|
|
|
|
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
|
if err != nil {
|
|
log.Panic().Err(err).Msg("Error creating identification provider")
|
|
}
|
|
|
|
emailing, err := renderer.NewEmailingHandler(cfg)
|
|
if err != nil {
|
|
log.Panic().Err(err).Msg("Error creating emailing handler")
|
|
}
|
|
|
|
// Create renderer for web server
|
|
templates_root := cfg.GetString("templates.root")
|
|
webRenderer := renderer.NewRenderer(cfg, templates_root, filestorage)
|
|
|
|
applicationHandler, _ := application.NewApplicationHandler(cfg, svc, kv, filestorage, emailing, idp)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
if webEnabled {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
web.Run(cfg, svc, webRenderer, applicationHandler, idp, kv, filestorage)
|
|
}()
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|