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-unixfs
Commits
a6eb3961
Commit
a6eb3961
authored
Jan 22, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use --http flag to run expose IPFS HTTP API
parent
038ec6a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
9 deletions
+41
-9
cmd/ipfswatch/main.go
cmd/ipfswatch/main.go
+41
-9
No files found.
cmd/ipfswatch/main.go
View file @
a6eb3961
...
...
@@ -6,17 +6,19 @@ import (
"os"
"path/filepath"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
import
(
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/coreunix"
"github.com/jbenet/go-ipfs/repo/config"
"github.com/jbenet/go-ipfs/repo/fsrepo"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
homedir
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
fsnotify
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/fsnotify.v1"
commands
"github.com/jbenet/go-ipfs/commands"
core
"github.com/jbenet/go-ipfs/core"
corehttp
"github.com/jbenet/go-ipfs/core/corehttp"
coreunix
"github.com/jbenet/go-ipfs/core/coreunix"
config
"github.com/jbenet/go-ipfs/repo/config"
fsrepo
"github.com/jbenet/go-ipfs/repo/fsrepo"
)
var
http
=
flag
.
Bool
(
"http"
,
false
,
"expose IPFS HTTP API"
)
var
repoPath
=
flag
.
String
(
"repo"
,
os
.
Getenv
(
"IPFS_PATH"
),
"IPFS_PATH to use"
)
var
watchPath
=
flag
.
String
(
"path"
,
"."
,
"the path to watch"
)
...
...
@@ -66,6 +68,21 @@ func run(ipfsPath, watchPath string) error {
}
defer
node
.
Close
()
if
*
http
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/5001"
)
if
err
!=
nil
{
return
err
}
var
opts
=
[]
corehttp
.
ServeOption
{
corehttp
.
GatewayOption
,
corehttp
.
WebUIOption
,
corehttp
.
CommandsOption
(
cmdCtx
(
node
,
ipfsPath
)),
}
if
err
:=
corehttp
.
ListenAndServe
(
node
,
maddr
,
opts
...
);
err
!=
nil
{
return
nil
}
}
for
{
select
{
case
e
:=
<-
watcher
.
Events
:
...
...
@@ -152,3 +169,18 @@ func IsHidden(path string) bool {
}
return
false
}
func
cmdCtx
(
node
*
core
.
IpfsNode
,
repoPath
string
)
commands
.
Context
{
return
commands
.
Context
{
// TODO deprecate this shit
Context
:
context
.
Background
(),
Online
:
true
,
ConfigRoot
:
repoPath
,
LoadConfig
:
func
(
path
string
)
(
*
config
.
Config
,
error
)
{
return
node
.
Repo
.
Config
(),
nil
},
ConstructNode
:
func
()
(
*
core
.
IpfsNode
,
error
)
{
return
node
,
nil
},
}
}
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