kubo/namesys/proquint.go
Juan Batiz-Benet 2944360f5c New NameSystem interface
type NameSystem interface {
      Resolver
      Publisher
    }

should say it all.

cc @whyrusleeping
2014-10-08 04:14:52 -07:00

25 lines
632 B
Go

package namesys
import (
"errors"
proquint "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/bren2010/proquint"
)
type ProquintResolver struct{}
// CanResolve implements Resolver. Checks whether the name is a proquint string.
func (r *ProquintResolver) CanResolve(name string) bool {
ok, err := proquint.IsProquint(name)
return err == nil && ok
}
// Resolve implements Resolver. Decodes the proquint string.
func (r *ProquintResolver) Resolve(name string) (string, error) {
ok := r.CanResolve(name)
if !ok {
return "", errors.New("not a valid proquint string")
}
return string(proquint.Decode(name)), nil
}