Skip to content

Commit

Permalink
Yank gateway out to a separate repo
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>

Remove gateway assets from go-ipfs/assets & update go-log hash

License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
  • Loading branch information
rht committed Dec 16, 2015
1 parent 5bf3a59 commit f29f26a
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 771 deletions.
11 changes: 1 addition & 10 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go-bindata -pkg=assets init-doc ../vendor/dir-index-html-v1.0.0
//go:generate go-bindata -pkg=assets init-doc
//go:generate gofmt -w bindata.go

package assets
Expand Down Expand Up @@ -29,15 +29,6 @@ func SeedInitDocs(nd *core.IpfsNode) (*key.Key, error) {
return addAssetList(nd, initDocPaths)
}

var initDirIndex = []string{
filepath.Join("..", "vendor", "dir-index-html-v1.0.0", "knownIcons.txt"),
filepath.Join("..", "vendor", "dir-index-html-v1.0.0", "dir-index.html"),
}

func SeedInitDirIndex(nd *core.IpfsNode) (*key.Key, error) {
return addAssetList(nd, initDirIndex)
}

func addAssetList(nd *core.IpfsNode, l []string) (*key.Key, error) {
dirb := uio.NewDirectory(nd.DAG)

Expand Down
168 changes: 12 additions & 156 deletions assets/bindata.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
peer "github.com/ipfs/go-ipfs/p2p/peer"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
util "github.com/ipfs/go-ipfs/util"
gateway "github.com/ipfs/go-ipfs/vendor/QmXvNwFNR7CQJ1J5oJnjS4oAFv2ai6v9JZBkTBbJp6wRQf/go-ipfs-gateway"
)

const (
Expand Down Expand Up @@ -331,9 +332,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
}

apiGw := corehttp.NewGateway(corehttp.GatewayConfig{
apiGw := gateway.NewGateway(gateway.GatewayConfig{
Writable: true,
BlockList: &corehttp.BlockList{
BlockList: &gateway.BlockList{
Decider: func(s string) bool {
if unrestricted {
return true
Expand All @@ -353,7 +354,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
corehttp.CommandsOption(*req.InvocContext()),
corehttp.WebUIOption,
apiGw.ServeOption(),
corehttp.VersionOption(),
gateway.VersionOption(),
defaultMux("/debug/vars"),
defaultMux("/debug/pprof/"),
corehttp.LogOption(),
Expand Down Expand Up @@ -430,9 +431,9 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
var opts = []corehttp.ServeOption{
corehttp.PrometheusCollectorOption("gateway"),
corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(),
gateway.VersionOption(),
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption(writable),
gateway.GatewayOption(writable),
}

if len(cfg.Gateway.RootRedirect) > 0 {
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "go-ipfs",
"version": "0.3.8",
"version": "0.4.0",
"gxDependencies": [
{
"name": "go-log",
"hash": "QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b",
"name": "go-ipfs-gateway",
"hash": "Qmc2aJFKUyJMUCsEHugka6oCKm88kSQrV678YKTFb4mc1U",
"version": "1.0.0"
},
{
"name": "dir-index-html",
"hash": "QmdDfkqDWheE4gsCXNrhixwTwSHnZMPT2cGLcNbiBNcMyU",
"version": "1.0.0",
"linkname": "dir-index-html-v1.0.0"
"name": "go-log",
"hash": "QmaywEmHiYfhcv1gj8gTNq6jwcN7Cs1EJkkE9kksT1255V",
"version": "1.0.0"
}
],
"language": "go"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# go-ipfs-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:generate go-bindata -pkg=assets ../vendor/dir-index-html-v1.0.0/...
//go:generate gofmt -w bindata.go

package assets

import (
"fmt"
"path/filepath"
)

var initDirIndex = []string{
filepath.Join("..", "vendor", "dir-index-html-v1.0.0", "knownIcons.txt"),
filepath.Join("..", "vendor", "dir-index-html-v1.0.0", "dir-index.html"),
}

func seedInitDirIndex() error {
for _, p := range initDirIndex {
_, err := Asset(p)
if err != nil {
return fmt.Errorf("assets: could load Asset '%s': %s", p, err)
}
}
return nil
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corehttp
package gateway

import (
"fmt"
Expand All @@ -7,6 +7,7 @@ import (
"sync"

core "github.com/ipfs/go-ipfs/core"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
)

Expand All @@ -27,7 +28,23 @@ func NewGateway(conf GatewayConfig) *Gateway {
}
}

func (g *Gateway) ServeOption() ServeOption {
// extracted from github.com/ipfs/go-ipfs/core/corehttp/corehttp.go
// makeHandler turns a list of ServeOptions into a http.Handler that implements
// all of the given options, in order.
func makeHandler(n *core.IpfsNode, l net.Listener, options ...corehttp.ServeOption) (http.Handler, error) {
topMux := http.NewServeMux()
mux := topMux
for _, option := range options {
var err error
mux, err = option(n, l, mux)
if err != nil {
return nil, err
}
}
return topMux, nil
}

func (g *Gateway) ServeOption() corehttp.ServeOption {
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
// pass user's HTTP headers
cfg, err := n.Repo.Config()
Expand All @@ -47,15 +64,15 @@ func (g *Gateway) ServeOption() ServeOption {
}
}

func GatewayOption(writable bool) ServeOption {
func GatewayOption(writable bool) corehttp.ServeOption {
g := NewGateway(GatewayConfig{
Writable: writable,
BlockList: &BlockList{},
})
return g.ServeOption()
}

func VersionOption() ServeOption {
func VersionOption() corehttp.ServeOption {
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corehttp
package gateway

import (
"errors"
Expand All @@ -21,13 +21,17 @@ import (
path "github.com/ipfs/go-ipfs/path"
"github.com/ipfs/go-ipfs/routing"
uio "github.com/ipfs/go-ipfs/unixfs/io"

logging "github.com/rht/go-ipfs-gateway/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
)

const (
ipfsPathPrefix = "/ipfs/"
ipnsPathPrefix = "/ipns/"
)

var log = logging.Logger("core/gateway")

// gatewayHandler is a HTTP handler that serves IPFS objects (accessible by default at /ipfs/<path>)
// (it serves requests like GET /ipfs/QmVRzPKPzNtSrEzBFm2UZfxmPAgnaLke4DMcerbsGGSaFe/link)
type gatewayHandler struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corehttp
package gateway

import (
"html/template"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corehttp
package gateway

import (
"errors"
Expand All @@ -11,6 +11,7 @@ import (

context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
core "github.com/ipfs/go-ipfs/core"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
namesys "github.com/ipfs/go-ipfs/namesys"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
Expand Down Expand Up @@ -95,7 +96,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core

dh.Handler, err = makeHandler(n,
ts.Listener,
IPNSHostnameOption(),
corehttp.IPNSHostnameOption(),
GatewayOption(false),
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "go-ipfs-gateway",
"version": "1.0.0",
"gxDependencies": [
{
"name": "go-log",
"hash": "QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b",
"version": "1.0.0"
},
{
"name": "dir-index-html",
"hash": "QmdDfkqDWheE4gsCXNrhixwTwSHnZMPT2cGLcNbiBNcMyU",
"version": "1.0.0",
"linkname": "dir-index-html-v1.0.0"
}
],
"language": "go"
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f29f26a

Please sign in to comment.