forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proquint.go
30 lines (24 loc) · 904 Bytes
/
proquint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package namesys
import (
"errors"
context "context"
path "github.com/ipfs/go-ipfs/path"
proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
)
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
}