@cryptotaxi247 / kubo / commits / e4eb964f6

core/corehttp: Use consts for path prefixes

Matt Bell committed Jan 27, 2015 at 01:01 UTC e4eb964f6949bb1ef44ce292abaa06e9b1b676b0
1 file changed +9 -4
core/corehttp/gateway_handler.go
+9 -4
@@ -20,6 +20,11 @@ import (
20 u "github.com/jbenet/go-ipfs/util"
21 )
22
23 +const (
24 + IpfsPathPrefix = "/ipfs/"
25 + IpnsPathPrefix = "/ipns/"
26 +)
27 +
28 type gateway interface {
29 ResolvePath(string) (*dag.Node, error)
30 NewDagFromReader(io.Reader) (*dag.Node, error)
@@ -68,8 +73,8 @@ func (i *gatewayHandler) loadTemplate() error {
73 func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node, string, error) {
74 p = path.Clean(p)
75
71 - if strings.HasPrefix(p, "/ipns/") {
72 - elements := strings.Split(p[6:], "/")
76 + if strings.HasPrefix(p, IpnsPathPrefix) {
77 + elements := strings.Split(p[len(IpnsPathPrefix):], "/")
78 hash := elements[0]
79 k, err := i.node.Namesys.Resolve(ctx, hash)
80 if err != nil {
@@ -79,8 +84,8 @@ func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node,
84 elements[0] = k.Pretty()
85 p = path.Join(elements...)
86 }
82 - if !strings.HasPrefix(p, "/ipfs/") {
83 - p = path.Join("/ipfs/", p)
87 + if !strings.HasPrefix(p, IpfsPathPrefix) {
88 + p = path.Join(IpfsPathPrefix, p)
89 }
90
91 node, err := i.node.Resolver.ResolvePath(p)