chore: refactor main

next-astro
Francesco Minnocci 1 year ago
parent e34f91fce6
commit e36fddb2b3
Signed by: BachoSeven
GPG Key ID: 2BE4AB7FDAD828A4

@ -382,8 +382,8 @@ footer {
.project {
// background: #fcddff;
background: #ffa89c;
// background: #a2d4f3;
// background: #ffa89c;
background: #a2d4f3;
color: #000e;
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/database"
"git.phc.dm.unipi.it/phc/website/server/listautenti"
"git.phc.dm.unipi.it/phc/website/server/model"
)
@ -23,10 +24,7 @@ func init() {
func main() {
l := sl.New()
cfg := sl.InjectValue(l, config.Slot, config.Config{
Mode: "development",
Host: ":4000",
})
cfg := sl.InjectValue(l, config.Slot, config.TestingDevelopmentConfig)
sl.InjectValue[database.Database](l, database.Slot, &database.Memory{
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 {
log.Fatal(err)
}
@ -56,7 +57,7 @@ func main() {
r, w := io.Pipe()
cmd := exec.Command("npm", "run", "dev")
cmd := exec.Command("pnpm", "run", "dev")
cmd.Stdout = w
go func() {

@ -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",
}

@ -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
}

@ -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
}

Loading…
Cancel
Save