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
fadede6c
Commit
fadede6c
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate concerns
parent
fadedf9e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
38 deletions
+67
-38
core/corehttp/commands.go
core/corehttp/commands.go
+25
-0
core/corehttp/corehttp.go
core/corehttp/corehttp.go
+1
-38
core/corehttp/gateway.go
core/corehttp/gateway.go
+16
-0
core/corehttp/webui.go
core/corehttp/webui.go
+25
-0
No files found.
core/corehttp/commands.go
0 → 100644
View file @
fadede6c
package
corehttp
import
(
"net/http"
"os"
commands
"github.com/jbenet/go-ipfs/commands"
cmdsHttp
"github.com/jbenet/go-ipfs/commands/http"
core
"github.com/jbenet/go-ipfs/core"
corecommands
"github.com/jbenet/go-ipfs/core/commands"
)
const
(
// TODO rename
originEnvKey
=
"API_ORIGIN"
)
func
CommandsOption
(
cctx
commands
.
Context
)
ServeOption
{
return
func
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
origin
:=
os
.
Getenv
(
originEnvKey
)
cmdHandler
:=
cmdsHttp
.
NewHandler
(
cctx
,
corecommands
.
Root
,
origin
)
mux
.
Handle
(
cmdsHttp
.
ApiPath
+
"/"
,
cmdHandler
)
return
nil
}
}
This diff is collapsed.
Click to expand it.
core/corehttp/corehttp.go
View file @
fadede6c
...
...
@@ -3,24 +3,18 @@ package corehttp
import
(
"fmt"
"net/http"
"os"
manners
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
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"
commands
"github.com/jbenet/go-ipfs/commands"
cmdsHttp
"github.com/jbenet/go-ipfs/commands/http"
core
"github.com/jbenet/go-ipfs/core"
corecommands
"github.com/jbenet/go-ipfs/core/commands"
eventlog
"github.com/jbenet/go-ipfs/thirdparty/eventlog"
)
var
log
=
eventlog
.
Logger
(
"core/server"
)
const
(
// TODO rename
originEnvKey
=
"API_ORIGIN"
webuiPath
=
"/ipfs/QmTWvqK9dYvqjAMAcCeUun8b45Fwu7wPhEN9B9TsGbkXfJ"
// TODO rename
)
type
ServeOption
func
(
*
core
.
IpfsNode
,
*
http
.
ServeMux
)
error
...
...
@@ -35,29 +29,6 @@ func ListenAndServe(n *core.IpfsNode, addr ma.Multiaddr, options ...ServeOption)
return
listenAndServe
(
"API"
,
n
,
addr
,
mux
)
}
func
CommandsOption
(
cctx
commands
.
Context
)
ServeOption
{
return
func
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
origin
:=
os
.
Getenv
(
originEnvKey
)
cmdHandler
:=
cmdsHttp
.
NewHandler
(
cctx
,
corecommands
.
Root
,
origin
)
mux
.
Handle
(
cmdsHttp
.
ApiPath
+
"/"
,
cmdHandler
)
return
nil
}
}
func
GatewayOption
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
gateway
,
err
:=
newGatewayHandler
(
n
)
if
err
!=
nil
{
return
err
}
mux
.
Handle
(
"/ipfs/"
,
gateway
)
return
nil
}
func
WebUIOption
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
mux
.
Handle
(
"/webui/"
,
&
redirectHandler
{
webuiPath
})
return
nil
}
func
listenAndServe
(
name
string
,
node
*
core
.
IpfsNode
,
addr
ma
.
Multiaddr
,
mux
*
http
.
ServeMux
)
error
{
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
...
...
@@ -90,11 +61,3 @@ func listenAndServe(name string, node *core.IpfsNode, addr ma.Multiaddr, mux *ht
log
.
Infof
(
"server at %s terminated"
,
addr
)
return
serverError
}
type
redirectHandler
struct
{
path
string
}
func
(
i
*
redirectHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Redirect
(
w
,
r
,
i
.
path
,
302
)
}
This diff is collapsed.
Click to expand it.
core/corehttp/gateway.go
0 → 100644
View file @
fadede6c
package
corehttp
import
(
"net/http"
core
"github.com/jbenet/go-ipfs/core"
)
func
GatewayOption
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
gateway
,
err
:=
newGatewayHandler
(
n
)
if
err
!=
nil
{
return
err
}
mux
.
Handle
(
"/ipfs/"
,
gateway
)
return
nil
}
This diff is collapsed.
Click to expand it.
core/corehttp/webui.go
0 → 100644
View file @
fadede6c
package
corehttp
import
(
"net/http"
core
"github.com/jbenet/go-ipfs/core"
)
const
(
// TODO rename
webuiPath
=
"/ipfs/QmTWvqK9dYvqjAMAcCeUun8b45Fwu7wPhEN9B9TsGbkXfJ"
)
func
WebUIOption
(
n
*
core
.
IpfsNode
,
mux
*
http
.
ServeMux
)
error
{
mux
.
Handle
(
"/webui/"
,
&
redirectHandler
{
webuiPath
})
return
nil
}
type
redirectHandler
struct
{
path
string
}
func
(
i
*
redirectHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Redirect
(
w
,
r
,
i
.
path
,
302
)
}
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