示例#1
0
文件: io.go 项目: kkellerlbl/AWE
func (io *IO) DataUrl() (dataurl string, err error) {
	if io.Url != "" {
		// parse and test url
		u, _ := url.Parse(io.Url)
		if (u.Scheme == "") || (u.Host == "") || (u.Path == "") {
			return "", errors.New("Not a valid url: " + io.Url)
		}
		// get shock info from url
		if (io.Host == "") || (io.Node == "") || (io.Node == "-") {
			trimPath := strings.Trim(u.Path, "/")
			cleanUuid := strings.Trim(strings.TrimPrefix(trimPath, "node"), "/")
			// appears to be a shock url
			if (cleanUuid != trimPath) && (uuid.Parse(cleanUuid) != nil) {
				io.Host = u.Scheme + "://" + u.Host
				io.Node = cleanUuid
			}
		}
		return io.Url, nil
	} else if (io.Host != "") && (io.Node != "") && (io.Node != "-") {
		io.Url = fmt.Sprintf("%s/node/%s?download", io.Host, io.Node)
		return io.Url, nil
	} else {
		// empty IO is valid
		return "", nil
	}
}
示例#2
0
func parseJobAclRequestTyped(cx *goweb.Context) (ids []string, err error) {
	var users []string
	query := cx.Request.URL.Query()
	params, _, err := ParseMultipartForm(cx.Request)
	if _, ok := query["users"]; ok && err != nil && err.Error() == "request Content-Type isn't multipart/form-data" {
		users = strings.Split(query.Get("users"), ",")
	} else if params["users"] != "" {
		users = strings.Split(params["users"], ",")
	} else {
		return nil, nil
	}
	for _, v := range users {
		if uuid.Parse(v) != nil {
			ids = append(ids, v)
		} else {
			u := user.User{Username: v}
			if err := u.SetMongoInfo(); err != nil {
				return nil, err
			}
			ids = append(ids, u.Uuid)
		}
	}
	return ids, nil
}