kubo/namesys/proquint.go
Steven Allen ec9fac7379 gx: update go-ipld-cbor
(might as well do this at the same time)

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2018-11-02 13:17:44 -07:00

34 lines
1017 B
Go

package namesys
import (
"context"
"errors"
path "gx/ipfs/QmUB3RFRDctDp1k73mDJydzWiKdiuNHfyuoRPQeU52rWWT/go-path"
proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
opts "github.com/ipfs/go-ipfs/namesys/opts"
)
type ProquintResolver struct{}
// Resolve implements Resolver.
func (r *ProquintResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
return resolve(ctx, r, name, opts.ProcessOpts(options))
}
// resolveOnce implements resolver. Decodes the proquint string.
func (r *ProquintResolver) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult {
out := make(chan onceResult, 1)
defer close(out)
ok, err := proquint.IsProquint(name)
if err != nil || !ok {
out <- onceResult{err: errors.New("not a valid proquint string")}
return out
}
// Return a 0 TTL as caching this result is pointless.
out <- onceResult{value: path.FromString(string(proquint.Decode(name)))}
return out
}