コード例 #1
0
ファイル: addr.go プロジェクト: prodigeni/circuit
// SCHEME://123.3.45.0:3456/2345/R1122334455667788
func ParseAddr(s string) (*Addr, error) {
	u, err := url.Parse(s)
	if err != nil {
		return nil, err
	}
	if u.Scheme != n.Scheme {
		return nil, errors.NewError("worker address URL scheme mismatch")
	}
	// Net address
	naddr, err := ParseNetAddr(u.Host)
	if err != nil {
		return nil, err
	}
	// Parse path
	parts := strings.Split(u.Path, "/")
	if len(parts) != 3 {
		return nil, errors.NewError(fmt.Sprintf("parse path: %#v", parts))
	}
	if parts[0] != "" {
		return nil, errors.NewError("must start with slash")
	}
	// PID
	pid, err := strconv.Atoi(parts[1])
	if err != nil {
		return nil, err
	}
	// Worker ID
	id, err := n.ParseWorkerID(parts[2])
	if err != nil {
		return nil, err
	}
	return &Addr{ID: id, PID: pid, TCP: naddr.(*net.TCPAddr)}, nil
}
コード例 #2
0
ファイル: anchorfs.go プロジェクト: hanjin8307/circuit
// SanitizeDir ensures that anchor is a valid directory path in the fs
// and returns its parts and a normalized absolute path string.
func SanitizeDir(anchor string) (parts []string, full string, err error) {
	anchor = path.Clean(anchor)
	if len(anchor) == 0 || anchor[0] != '/' {
		return nil, "", ErrName
	}
	parts = strings.Split(anchor[1:], "/")
	for _, part := range parts {
		if _, err = n.ParseWorkerID(part); err == nil {
			// Directory name elements cannot look like worker IDs
			return nil, "", ErrName
		}
	}
	return parts, "/" + path.Join(parts...), nil
}