Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cc519c47
提交
cc519c47
authored
11月 09, 2014
作者:
Matt Bell
提交者:
Juan Batiz-Benet
11月 14, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd/ipfs2: Ensure process exits smoothly
上级
f3733873
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
31 行删除
+43
-31
main.go
cmd/ipfs2/main.go
+43
-31
没有找到文件。
cmd/ipfs2/main.go
浏览文件 @
cc519c47
...
...
@@ -28,19 +28,29 @@ const (
errorFormat
=
"ERROR: %v
\n\n
"
)
var
ofi
io
.
WriteCloser
func
main
()
{
args
:=
os
.
Args
[
1
:
]
req
,
root
:=
createRequest
(
args
)
handleOptions
(
req
,
root
)
res
:=
callCommand
(
req
,
root
)
outputResponse
(
res
,
root
)
// if debugging, setup profiling.
if
u
.
Debug
{
err
:=
writeHeapProfileToFile
()
var
err
error
ofi
,
err
=
os
.
Create
(
"cpu.prof"
)
if
err
!=
nil
{
log
.
Critical
(
err
)
fmt
.
Println
(
err
)
return
}
pprof
.
StartCPUProfile
(
ofi
)
}
res
:=
callCommand
(
req
,
root
)
outputResponse
(
res
,
root
)
exit
(
0
)
}
func
createRequest
(
args
[]
string
)
(
cmds
.
Request
,
*
cmds
.
Command
)
{
...
...
@@ -52,7 +62,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
options
,
err2
=
getOptions
(
req
,
root
)
if
err2
!=
nil
{
fmt
.
Println
(
err2
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
}
...
...
@@ -88,19 +98,19 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
}
else
{
fmt
.
Println
(
helpText
)
}
os
.
E
xit
(
1
)
e
xit
(
1
)
}
configPath
,
err
:=
getConfigRoot
(
options
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
conf
,
err
:=
getConfig
(
configPath
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
ctx
:=
req
.
Context
()
...
...
@@ -122,7 +132,7 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
options
,
err
:=
getOptions
(
req
,
root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
if
help
,
found
:=
options
.
Option
(
"help"
);
found
{
...
...
@@ -133,10 +143,10 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
}
else
{
fmt
.
Println
(
helpText
)
}
os
.
E
xit
(
0
)
e
xit
(
0
)
}
else
if
!
ok
{
fmt
.
Println
(
"error: expected 'help' option to be a bool"
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
}
...
...
@@ -145,21 +155,9 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
u
.
Debug
=
true
u
.
SetAllLoggers
(
logging
.
DEBUG
)
// if debugging, setup profiling.
if
u
.
Debug
{
ofi
,
err
:=
os
.
Create
(
"cpu.prof"
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
pprof
.
StartCPUProfile
(
ofi
)
defer
ofi
.
Close
()
defer
pprof
.
StopCPUProfile
()
}
}
else
if
!
ok
{
fmt
.
Println
(
"error: expected 'debug' option to be a bool"
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
}
}
...
...
@@ -174,7 +172,7 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
options
,
err
:=
getOptions
(
req
,
root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
var
found
bool
...
...
@@ -185,7 +183,7 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
localBool
,
ok
=
local
.
(
bool
)
if
!
ok
{
fmt
.
Println
(
"error: expected 'local' option to be a bool"
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
}
...
...
@@ -193,13 +191,13 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
addr
,
err
:=
ma
.
NewMultiaddr
(
req
.
Context
()
.
Config
.
Addresses
.
API
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
client
:=
cmdsHttp
.
NewClient
(
host
)
...
...
@@ -207,14 +205,14 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
res
,
err
=
client
.
Send
(
req
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
}
else
{
node
,
err
:=
core
.
NewIpfsNode
(
req
.
Context
()
.
Config
,
false
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
E
xit
(
1
)
e
xit
(
1
)
}
defer
node
.
Close
()
req
.
Context
()
.
Node
=
node
...
...
@@ -239,7 +237,7 @@ func outputResponse(res cmds.Response, root *cmds.Command) {
}
}
os
.
E
xit
(
1
)
e
xit
(
1
)
}
out
,
err
:=
res
.
Reader
()
...
...
@@ -300,3 +298,17 @@ func writeHeapProfileToFile() error {
defer
mprof
.
Close
()
return
pprof
.
WriteHeapProfile
(
mprof
)
}
func
exit
(
code
int
)
{
if
u
.
Debug
{
pprof
.
StopCPUProfile
()
ofi
.
Close
()
err
:=
writeHeapProfileToFile
()
if
err
!=
nil
{
log
.
Critical
(
err
)
}
}
os
.
Exit
(
code
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论