chore: refactor main
This commit is contained in:
@@ -382,8 +382,8 @@ footer {
|
|||||||
|
|
||||||
.project {
|
.project {
|
||||||
// background: #fcddff;
|
// background: #fcddff;
|
||||||
background: #ffa89c;
|
// background: #ffa89c;
|
||||||
// background: #a2d4f3;
|
background: #a2d4f3;
|
||||||
color: #000e;
|
color: #000e;
|
||||||
|
|
||||||
border: 3px solid #222;
|
border: 3px solid #222;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"git.phc.dm.unipi.it/phc/website/server/config"
|
"git.phc.dm.unipi.it/phc/website/server/config"
|
||||||
"git.phc.dm.unipi.it/phc/website/server/database"
|
"git.phc.dm.unipi.it/phc/website/server/database"
|
||||||
|
"git.phc.dm.unipi.it/phc/website/server/listautenti"
|
||||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,10 +24,7 @@ func init() {
|
|||||||
func main() {
|
func main() {
|
||||||
l := sl.New()
|
l := sl.New()
|
||||||
|
|
||||||
cfg := sl.InjectValue(l, config.Slot, config.Config{
|
cfg := sl.InjectValue(l, config.Slot, config.TestingDevelopmentConfig)
|
||||||
Mode: "development",
|
|
||||||
Host: ":4000",
|
|
||||||
})
|
|
||||||
|
|
||||||
sl.InjectValue[database.Database](l, database.Slot, &database.Memory{
|
sl.InjectValue[database.Database](l, database.Slot, &database.Memory{
|
||||||
Users: []model.User{
|
Users: []model.User{
|
||||||
@@ -45,7 +43,10 @@ func main() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
srv, err := server.Configure(l)
|
sl.InjectLazy(l, server.Slot, server.Configure)
|
||||||
|
sl.InjectLazy(l, listautenti.Slot, listautenti.Configure)
|
||||||
|
|
||||||
|
srv, err := sl.Use(l, server.Slot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -56,7 +57,7 @@ func main() {
|
|||||||
|
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
|
|
||||||
cmd := exec.Command("npm", "run", "dev")
|
cmd := exec.Command("pnpm", "run", "dev")
|
||||||
cmd.Stdout = w
|
cmd.Stdout = w
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
+13
-13
@@ -6,24 +6,14 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"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 {
|
type Config struct {
|
||||||
Mode string
|
Mode string
|
||||||
Host 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")
|
m, err := godotenv.Read(".env")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Config{}, err
|
return Config{}, err
|
||||||
@@ -43,3 +33,13 @@ func Load(l *sl.ServiceLocator) (Config, error) {
|
|||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var TestingProductionConfig = Config{
|
||||||
|
Mode: "production",
|
||||||
|
Host: ":4000",
|
||||||
|
}
|
||||||
|
|
||||||
|
var TestingDevelopmentConfig = Config{
|
||||||
|
Mode: "development",
|
||||||
|
Host: ":4000",
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,15 +9,19 @@ import (
|
|||||||
"git.phc.dm.unipi.it/phc/website/server/routes"
|
"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)
|
db, err := sl.Use(l, database.Slot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := sl.Use(l, routes.Root)
|
r, err := sl.Use(l, routes.Root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Get("/api/lista-utenti", func(c *fiber.Ctx) error {
|
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 c.JSON(users)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return &ListaUtenti{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -10,13 +10,15 @@ import (
|
|||||||
|
|
||||||
type Server struct{ Router *fiber.App }
|
type Server struct{ Router *fiber.App }
|
||||||
|
|
||||||
|
var Slot = sl.NewSlot[*Server]()
|
||||||
|
|
||||||
func Configure(l *sl.ServiceLocator) (*Server, error) {
|
func Configure(l *sl.ServiceLocator) (*Server, error) {
|
||||||
r := fiber.New(fiber.Config{})
|
r := fiber.New(fiber.Config{})
|
||||||
r.Static("/assets", "./out/frontend/assets")
|
r.Static("/assets", "./out/frontend/assets")
|
||||||
|
|
||||||
sl.InjectValue(l, routes.Root, fiber.Router(r))
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user