mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 23:08:07 +08:00
31 lines
977 B
Go
31 lines
977 B
Go
package namesys
|
|
|
|
import (
|
|
"errors"
|
|
|
|
proquint "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/bren2010/proquint"
|
|
path "github.com/ipfs/go-ipfs/path"
|
|
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
|
)
|
|
|
|
type ProquintResolver struct{}
|
|
|
|
// Resolve implements Resolver.
|
|
func (r *ProquintResolver) Resolve(ctx context.Context, name string) (path.Path, error) {
|
|
return r.ResolveN(ctx, name, DefaultDepthLimit)
|
|
}
|
|
|
|
// ResolveN implements Resolver.
|
|
func (r *ProquintResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error) {
|
|
return resolve(ctx, r, name, depth, "/ipns/")
|
|
}
|
|
|
|
// resolveOnce implements resolver. Decodes the proquint string.
|
|
func (r *ProquintResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
|
|
ok, err := proquint.IsProquint(name)
|
|
if err != nil || !ok {
|
|
return "", errors.New("not a valid proquint string")
|
|
}
|
|
return path.FromString(string(proquint.Decode(name))), nil
|
|
}
|