This commit is contained in:
Ben Sarmiento
2023-11-27 21:50:00 +01:00
parent a7623de410
commit c8334ecb3b
15 changed files with 277 additions and 221 deletions

View File

@@ -17,6 +17,8 @@ import (
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
"github.com/hashicorp/golang-lru/v2/expirable"
_ "net/http/pprof"
)
func main() {
@@ -32,40 +34,47 @@ func main() {
}
// normal startup
log := logutil.NewLogger().Named("zurg")
log := logutil.NewLogger()
zurglog := log.Named("zurg")
config, configErr := config.LoadZurgConfig("./config.yml")
config, configErr := config.LoadZurgConfig("./config.yml", log.Named("config"))
if configErr != nil {
log.Errorf("Config failed to load: %v", configErr)
zurglog.Errorf("Config failed to load: %v", configErr)
os.Exit(1)
}
cache := expirable.NewLRU[string, string](1e4, nil, time.Hour)
client := zurghttp.NewHTTPClient(config.GetToken(), 5, config)
apiClient := zurghttp.NewHTTPClient(config.GetToken(), 5, 15, config, log.Named("httpclient"))
rd := realdebrid.NewRealDebrid(config.GetToken(), client, logutil.NewLogger().Named("realdebrid"))
rd := realdebrid.NewRealDebrid(apiClient, log.Named("realdebrid"))
p, err := ants.NewPool(config.GetNumOfWorkers())
if err != nil {
log.Errorf("Failed to create worker pool: %v", err)
zurglog.Errorf("Failed to create worker pool: %v", err)
os.Exit(1)
}
defer p.Release()
torrentMgr := torrent.NewTorrentManager(config, rd, p)
torrentMgr := torrent.NewTorrentManager(config, rd, p, log.Named("manager"))
getfile := universal.NewGetFile(client)
downloadClient := zurghttp.NewHTTPClient("", 5, 0, config, log.Named("dlclient"))
getfile := universal.NewGetFile(downloadClient)
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
mux := http.NewServeMux()
net.Router(mux, getfile, config, torrentMgr, cache)
net.Router(mux, getfile, config, torrentMgr, cache, log.Named("net"))
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
server := &http.Server{Addr: addr, Handler: mux}
log.Infof("Starting server on %s", addr)
zurglog.Infof("Starting server on %s", addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Errorf("Failed to start server: %v", err)
zurglog.Errorf("Failed to start server: %v", err)
os.Exit(1)
}
}