Пример #1
0
func validateUrl(uri string, allowEmpty bool, idName string, errors map[string][]os.Error) (newUri string, err os.Error) {
	newUri = strings.TrimSpace(uri)
	if newUri == "" {
		if !allowEmpty {
			err = ERR_REQUIRED_FIELD
		}
	} else {
		if _, err = url.ParseWithReference(newUri); err != nil {
			err = ERR_INVALID_FORMAT
		}
	}
	if err != nil && errors != nil {
		errors[idName] = []os.Error{err}
	}
	return
}
Пример #2
0
func PrimeUrl(u Url) os.Error {
	var (
		err   os.Error
		found bool = false
	)
	if *verbose {
		log.Printf("Get (weight %d) %s\n", int(u.Priority*100), u.Loc)
	}
	if *localDir != "" {
		parsed, err := url.ParseWithReference(u.Loc)
		joined := path.Join(*localDir, parsed.Path, *localSuffix)
		if _, err = os.Lstat(joined); err == nil {
			found = true
		}
	}
	if !found {
		_, err = client.Get(u.Loc)
	}
	wg.Done()
	<-sem
	return err
}
Пример #3
0
func PrimeUrl(u Url) os.Error {
	var (
		err    os.Error
		found  = false
		weight = int(u.Priority * 100)
	)
	if *localDir != "" {
		parsed, err := url.ParseWithReference(u.Loc)
		joined := path.Join(*localDir, parsed.Path, *localSuffix)
		if _, err = os.Lstat(joined); err == nil {
			found = true
			if *verbose {
				log.Printf("Exists (weight %d) %s\n", weight, u.Loc)
			}
		}
	}
	if !found {
		if *verbose {
			log.Printf("Get (weight %d) %s\n", weight, u.Loc)
		}
		res, err := Get(u.Loc)
		if (err != nil || res.Status != "200 OK") && !*nowarn {
			var errmsg string
			if err != nil {
				errmsg = err.String()
			} else {
				errmsg = res.Status
			}
			log.Printf("Error priming %s: %s\n", u.Loc, errmsg)
		}
		if *max > 0 {
			one <- true
		}
	}
	wg.Done()
	<-sem
	return err
}