1
0
Fork 1
mirror of https://github.com/0x2E/fusion.git synced 2025-06-08 05:27:15 +09:00
fusion/cmd/server/server.go
Yuan bc8109fe39
refactor: replace zap log with slog (#150)
* refactor: replace zap log with slog

* fix
2025-04-25 17:18:25 +08:00

53 lines
1.1 KiB
Go

package main
import (
"net/http"
_ "net/http/pprof"
"os"
"log/slog"
"github.com/0x2e/fusion/api"
"github.com/0x2e/fusion/conf"
"github.com/0x2e/fusion/repo"
"github.com/0x2e/fusion/service/pull"
)
func main() {
l := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
slog.SetDefault(l)
if conf.Debug {
l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
slog.SetDefault(l)
go func() {
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
slog.Error("pprof server", "error", err)
return
}
}()
}
config, err := conf.Load()
if err != nil {
slog.Error("failed to load configuration", "error", err)
return
}
repo.Init(config.DB)
go pull.NewPuller(repo.NewFeed(repo.DB), repo.NewItem(repo.DB)).Run()
api.Run(api.Params{
Host: config.Host,
Port: config.Port,
PasswordHash: config.PasswordHash,
UseSecureCookie: config.SecureCookie,
TLSCert: config.TLSCert,
TLSKey: config.TLSKey,
})
}