提交 908e4498 作者: Brian Tiger Chow

refactor(gatewayserver)

上级 35a5fa6f
......@@ -66,6 +66,24 @@ func run() error {
defer node.Close()
if *performGC {
if err := runGarbageCollectorWorker(ctx, node); err != nil {
return err
}
}
if *assetsPath != "" {
if err := runFileServerWorker(ctx, node); err != nil {
return err
}
}
opts := []corehttp.ServeOption{
corehttp.GatewayOption(*writable),
}
return corehttp.ListenAndServe(node, *host, opts...)
}
func runGarbageCollectorWorker(ctx context.Context, node *core.IpfsNode) error {
go func() {
for _ = range time.Tick(*garbageCollectInterval) {
if err := corerepo.GarbageCollect(node, ctx); err != nil {
......@@ -73,9 +91,10 @@ func run() error {
}
}
}()
}
return nil
}
if *assetsPath != "" {
func runFileServerWorker(ctx context.Context, node *core.IpfsNode) error {
fi, err := os.Stat(*assetsPath)
if err != nil {
return err
......@@ -91,13 +110,5 @@ func run() error {
}
}
}()
}
opts := []corehttp.ServeOption{
corehttp.GatewayOption(*writable),
}
if err := corehttp.ListenAndServe(node, *host, opts...); err != nil {
return err
}
return nil
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论