github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/namesys/proquint.go (about)

     1  package namesys
     2  
     3  import (
     4  	"errors"
     5  
     6  	proquint "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/bren2010/proquint"
     7  	context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
     8  	path "github.com/ipfs/go-ipfs/path"
     9  )
    10  
    11  type ProquintResolver struct{}
    12  
    13  // Resolve implements Resolver.
    14  func (r *ProquintResolver) Resolve(ctx context.Context, name string) (path.Path, error) {
    15  	return r.ResolveN(ctx, name, DefaultDepthLimit)
    16  }
    17  
    18  // ResolveN implements Resolver.
    19  func (r *ProquintResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error) {
    20  	return resolve(ctx, r, name, depth, "/ipns/")
    21  }
    22  
    23  // resolveOnce implements resolver. Decodes the proquint string.
    24  func (r *ProquintResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
    25  	ok, err := proquint.IsProquint(name)
    26  	if err != nil || !ok {
    27  		return "", errors.New("not a valid proquint string")
    28  	}
    29  	return path.FromString(string(proquint.Decode(name))), nil
    30  }