// Check fetches last version information from its source
// and compares with target and return result (CheckResponse).
Check fetches last version information from its source
and compares with target and return result (CheckResponse).
// Check fetches last version information from its source // and compares with target and return result ( CheckResponse ) .
func Check(s Source, target string, timeout time.Duration) (*CheckResponse, error) {
	if os.Getenv(EnvGoLatestDisable) != "" {
		return &CheckResponse{}, nil
	}
	targetV, err := version.NewVersion(target)
	if err != nil {
		return nil, fmt.Errorf("failed to parse %s, %s", target, err.Error())
	}
	if err = s.Validate(); err != nil {
		return nil, err
	}
	fr, err := s.Fetch(timeout)
	if err != nil {
		return nil, err
	}
	versions := fr.Versions
	if len(fr.Versions) == 0 {
		return nil, fmt.Errorf("no version to compare")
	}
	sort.Sort(version.Collection(versions))
	currentV := versions[len(versions)-1]
	var outdated, latest, new bool
	if targetV.LessThan(currentV) {
		outdated = true
	}
	if targetV.Equal(currentV) {
		latest = true
	}
	if targetV.GreaterThan(currentV) {
		latest, new = true, true
	}
	return &CheckResponse{
		Current:    currentV.String(),
		Outdated:   outdated,
		Latest:     latest,
		New:        new,
		Malformeds: fr.Malformeds,
		Meta:       fr.Meta,
	}, nil
}
func Check ( s Source , target string , timeout time . Duration ) ( * CheckResponse , error ) { if os . Getenv ( EnvGoLatestDisable ) != " " { return & CheckResponse { } , nil } targetV , err := version . NewVersion ( target ) if err != nil { return nil , fmt . Errorf ( " " , target , err . Error ( ) ) } if err = s . Validate ( ) ; err != nil { return nil , err } fr , err := s . Fetch ( timeout ) if err != nil { return nil , err } versions := fr . Versions if len ( fr . Versions ) == 0 { return nil , fmt . Errorf ( " " ) } sort . Sort ( version . Collection ( versions ) ) currentV := versions [ len ( versions ) - 1 ] var outdated , latest , new bool if targetV . LessThan ( currentV ) { outdated = true } if targetV . Equal ( currentV ) { latest = true } if targetV . GreaterThan ( currentV ) { latest , new = true , true } return & CheckResponse { Current : currentV . String ( ) , Outdated : outdated , Latest : latest , New : new , Malformeds : fr . Malformeds , Meta : fr . Meta , } , nil }
Check fetches last version information from its source
and compares with target and return result (CheckResponse).
Check fetches last version information from its source and compares with target and return result ( CheckResponse ) .
// Convert target to *version.Version // Validate source // Source must has at leaset one version information // If target = current, target is `latest` // If target > current, target is `latest` and `new`