package main

import (
	"fmt"
	"log"
	"os"

	cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"

	"git.ego.freeddns.org/egommerce/identity-service/internal/app"
	"git.ego.freeddns.org/egommerce/identity-service/internal/server"
)

func main() {
	if cnf.ErrLoadingEnvs != nil {
		log.Panicln(cnf.ErrLoadingEnvs)
	}

	c := server.NewConfig("identity-svc")
	cArr := c.GetArray()

	doer := server.New(c)
	a := app.NewApp(doer)
	a.RegisterPlugin(app.LoggerPlugin(cArr))
	a.RegisterPlugin(app.CachePlugin(cArr))
	a.RegisterPlugin(app.DatabasePlugin(cArr))

	while := make(chan struct{})
	err := a.Start(while)
	<-while

	if err != nil {
		log.Fatalf("Failed to start server. Reason: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("Gone")
	os.Exit(0)
}
