refactor: improved init flow in main

This commit is contained in:
yusing
2025-03-28 06:00:08 +08:00
parent fd223c7542
commit 1e39d0b186
3 changed files with 58 additions and 49 deletions

View File

@@ -28,18 +28,21 @@ import (
var rawLogger = log.New(os.Stdout, "", 0)
func init() {
var out io.Writer = os.Stderr
if common.EnableLogStreaming {
out = zerolog.MultiLevelWriter(out, v1.GetMemLogger())
func parallel(fns ...func()) {
var wg sync.WaitGroup
for _, fn := range fns {
wg.Add(1)
go func() {
defer wg.Done()
fn()
}()
}
logging.InitLogger(out)
// logging.AddHook(v1.GetMemLogger())
wg.Wait()
}
func main() {
initProfiling()
args := common.GetArgs()
args := pkg.GetArgs(common.MainServerCommandValidator{})
switch args.Command {
case common.CommandReload:
@@ -76,7 +79,11 @@ func main() {
if args.Command == common.CommandStart {
logging.Info().Msgf("GoDoxy version %s", pkg.GetVersion())
logging.Trace().Msg("trace enabled")
// logging.AddHook(notif.GetDispatcher())
parallel(
internal.InitIconListCache,
homepage.InitOverridesConfig,
favicon.InitIconCache,
)
} else {
logging.DiscardLogger()
}
@@ -121,10 +128,6 @@ func main() {
return
}
go internal.InitIconListCache()
go homepage.InitOverridesConfig()
go favicon.InitIconCache()
cfg.Start(&config.StartServersOptions{
Proxy: true,
})