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
0427d1ef
Commit
0427d1ef
authored
10 years ago
by
verokarhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beginnings of an http gateway/api
parent
c7af4a6f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
0 deletions
+62
-0
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+2
-0
cmd/ipfs/serve.go
cmd/ipfs/serve.go
+24
-0
http/http.go
http/http.go
+36
-0
No files found.
cmd/ipfs/ipfs.go
View file @
0427d1ef
...
...
@@ -35,6 +35,7 @@ Tool commands:
Advanced Commands:
mount Mount an ipfs read-only mountpoint.
serve Serve an http gateway into ipfs.
Use "ipfs help <command>" for more information about a command.
`
,
...
...
@@ -49,6 +50,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsCommands
,
cmdIpfsMount
,
cmdIpfsInit
,
cmdIpfsServe
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs"
,
flag
.
ExitOnError
),
}
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs/serve.go
0 → 100644
View file @
0427d1ef
package
main
import
(
"github.com/gonuts/flag"
"github.com/jbenet/commander"
h
"github.com/jbenet/go-ipfs/http"
)
var
cmdIpfsServe
=
&
commander
.
Command
{
UsageLine
:
"serve"
,
Short
:
"Serve an HTTP API"
,
Long
:
`ipfs serve - Serve an http gateway into ipfs.`
,
Run
:
serveCmd
,
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-serve"
,
flag
.
ExitOnError
),
}
func
serveCmd
(
c
*
commander
.
Command
,
_
[]
string
)
error
{
n
,
err
:=
localNode
()
if
err
!=
nil
{
return
err
}
return
h
.
Serve
(
"127.0.0.1"
,
80
,
n
)
}
This diff is collapsed.
Click to expand it.
http/http.go
0 → 100644
View file @
0427d1ef
package
http
import
(
"fmt"
"github.com/gorilla/mux"
core
"github.com/jbenet/go-ipfs/core"
"net/http"
"strconv"
)
type
ipfsHandler
struct
{
node
*
core
.
IpfsNode
}
func
(
i
*
ipfsHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
path
:=
r
.
URL
.
Path
nd
,
err
:=
i
.
node
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
fmt
.
Fprintf
(
w
,
"%s"
,
nd
.
Data
)
}
func
Serve
(
host
string
,
port
uint16
,
node
*
core
.
IpfsNode
)
error
{
r
:=
mux
.
NewRouter
()
r
.
PathPrefix
(
"/"
)
.
Handler
(
&
ipfsHandler
{
node
})
.
Methods
(
"GET"
)
http
.
Handle
(
"/"
,
r
)
address
:=
host
+
":"
+
strconv
.
FormatUint
(
uint64
(
port
),
10
)
fmt
.
Printf
(
"Serving on %s
\n
"
,
address
)
return
http
.
ListenAndServe
(
address
,
nil
)
}
This diff is collapsed.
Click to expand it.
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