1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00

Refactored main

This commit is contained in:
マリウス 2022-12-29 14:34:51 -05:00
parent 4433ba3476
commit fdf4be2bc2
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -2,20 +2,32 @@ package main
import ( import (
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/config"
"github.com/mrusme/gobbs/system" "github.com/mrusme/gobbs/system"
"github.com/mrusme/gobbs/ui" "github.com/mrusme/gobbs/ui"
"github.com/mrusme/gobbs/ui/ctx" "github.com/mrusme/gobbs/ui/ctx"
"go.uber.org/zap"
) )
func main() { func main() {
c := ctx.New() var logger *zap.Logger
var sugar *zap.SugaredLogger
discourse, err := system.New("discourse", nil) cfg, err := config.Load()
if err != nil { if err != nil {
panic(err) panic(err)
} }
c.AddSystem(&discourse) if cfg.Debug == "true" {
logger, _ = zap.NewDevelopment()
} else {
logger, _ = zap.NewProduction()
}
defer logger.Sync()
sugar = logger.Sugar()
c := ctx.New(&cfg, sugar)
_ = loadSystems(&c) // TODO: Handle errs
tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen()) tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
err = tui.Start() err = tui.Start()
@ -23,3 +35,19 @@ func main() {
panic(err) panic(err)
} }
} }
func loadSystems(c *ctx.Ctx) []error {
var errs []error
for _, sysCfg := range c.Config.Systems {
sys, err := system.New(sysCfg.Type, &sysCfg.Config)
if err != nil {
c.Logger.Errorf("error loading system: %s", err)
errs = append(errs, err)
}
c.AddSystem(&sys)
}
return errs
}