chore: refactor main

This commit is contained in:
2023-06-13 23:35:49 +02:00
parent e34f91fce6
commit e36fddb2b3
5 changed files with 33 additions and 26 deletions
+13 -13
View File
@@ -6,24 +6,14 @@ import (
"github.com/joho/godotenv"
)
var Slot = sl.NewSlot[Config]()
var TestingProductionConfig = Config{
Mode: "production",
Host: ":4000",
}
var TestingDevelopmentConfig = Config{
Mode: "development",
Host: ":4000",
}
type Config struct {
Mode string
Host string
}
func Load(l *sl.ServiceLocator) (Config, error) {
var Slot = sl.NewSlot[Config]()
func Configure(l *sl.ServiceLocator) (Config, error) {
m, err := godotenv.Read(".env")
if err != nil {
return Config{}, err
@@ -43,3 +33,13 @@ func Load(l *sl.ServiceLocator) (Config, error) {
return cfg, nil
}
var TestingProductionConfig = Config{
Mode: "production",
Host: ":4000",
}
var TestingDevelopmentConfig = Config{
Mode: "development",
Host: ":4000",
}
+8 -4
View File
@@ -9,15 +9,19 @@ import (
"git.phc.dm.unipi.it/phc/website/server/routes"
)
func Configure(l *sl.ServiceLocator) error {
type ListaUtenti struct{}
var Slot = sl.NewSlot[*ListaUtenti]()
func Configure(l *sl.ServiceLocator) (*ListaUtenti, error) {
db, err := sl.Use(l, database.Slot)
if err != nil {
return err
return nil, err
}
r, err := sl.Use(l, routes.Root)
if err != nil {
return err
return nil, err
}
r.Get("/api/lista-utenti", func(c *fiber.Ctx) error {
@@ -30,5 +34,5 @@ func Configure(l *sl.ServiceLocator) error {
return c.JSON(users)
})
return nil
return &ListaUtenti{}, nil
}
+3 -1
View File
@@ -10,13 +10,15 @@ import (
type Server struct{ Router *fiber.App }
var Slot = sl.NewSlot[*Server]()
func Configure(l *sl.ServiceLocator) (*Server, error) {
r := fiber.New(fiber.Config{})
r.Static("/assets", "./out/frontend/assets")
sl.InjectValue(l, routes.Root, fiber.Router(r))
if err := listautenti.Configure(l); err != nil {
if err := sl.Invoke(l, listautenti.Slot); err != nil {
return nil, err
}