Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
b5dc686f
Commit
b5dc686f
authored
Nov 22, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(main) create root context
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
b8c96b25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
cmd/ipfs/main.go
cmd/ipfs/main.go
+8
-6
No files found.
cmd/ipfs/main.go
View file @
b5dc686f
...
...
@@ -14,6 +14,7 @@ import (
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
cmds
"github.com/jbenet/go-ipfs/commands"
cmdsCli
"github.com/jbenet/go-ipfs/commands/cli"
cmdsHttp
"github.com/jbenet/go-ipfs/commands/http"
...
...
@@ -53,6 +54,7 @@ type cmdInvocation struct {
// - output the response
// - if anything fails, print error, maybe with help
func
main
()
{
ctx
:=
context
.
Background
()
var
err
error
var
invoc
cmdInvocation
defer
invoc
.
close
()
...
...
@@ -114,7 +116,7 @@ func main() {
}
// ok, finally, run the command invocation.
output
,
err
:=
invoc
.
Run
()
output
,
err
:=
invoc
.
Run
(
ctx
)
if
err
!=
nil
{
printErr
(
err
)
...
...
@@ -129,7 +131,7 @@ func main() {
io
.
Copy
(
os
.
Stdout
,
output
)
}
func
(
i
*
cmdInvocation
)
Run
()
(
output
io
.
Reader
,
err
error
)
{
func
(
i
*
cmdInvocation
)
Run
(
ctx
context
.
Context
)
(
output
io
.
Reader
,
err
error
)
{
// setup our global interrupt handler.
i
.
setupInterruptHandler
()
...
...
@@ -153,7 +155,7 @@ func (i *cmdInvocation) Run() (output io.Reader, err error) {
defer
stopProfilingFunc
()
// to be executed as late as possible
}
res
,
err
:=
callCommand
(
i
.
req
,
Root
)
res
,
err
:=
callCommand
(
ctx
,
i
.
req
,
Root
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -243,7 +245,7 @@ func (i *cmdInvocation) requestedHelp() (short bool, long bool, err error) {
return
longHelp
,
shortHelp
,
nil
}
func
callPreCommandHooks
(
details
cmdDetails
,
req
cmds
.
Request
,
root
*
cmds
.
Command
)
error
{
func
callPreCommandHooks
(
ctx
context
.
Context
,
details
cmdDetails
,
req
cmds
.
Request
,
root
*
cmds
.
Command
)
error
{
log
.
Debug
(
"Calling pre-command hooks..."
)
...
...
@@ -284,7 +286,7 @@ func callPreCommandHooks(details cmdDetails, req cmds.Request, root *cmds.Comman
return
nil
}
func
callCommand
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Response
,
error
)
{
func
callCommand
(
ctx
context
.
Context
,
req
cmds
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Response
,
error
)
{
var
res
cmds
.
Response
details
,
err
:=
commandDetails
(
req
.
Path
(),
root
)
...
...
@@ -297,7 +299,7 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
return
nil
,
err
}
err
=
callPreCommandHooks
(
*
details
,
req
,
root
)
err
=
callPreCommandHooks
(
ctx
,
*
details
,
req
,
root
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment