Skip to content

Commit

Permalink
check latest versions follows latest github release page (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoyamachi committed Apr 23, 2021
1 parent ed895e7 commit 6f1457a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/utils/fetch.go
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -13,7 +14,7 @@ import (
var versionPattern = regexp.MustCompile(`v[0-9]+\.[0-9]+\.[0-9]+`)

// Dockle just want to check latest version string. No need to readall.
const enoughLength = 8000
const enoughLength = 14000

func fetchURL(ctx context.Context, url string, cookie *http.Cookie, dataLen int) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
Expand Down Expand Up @@ -47,6 +48,8 @@ func FetchLatestVersion(ctx context.Context) (version string, err error) {
if err != nil {
return "", err
}
versionMatched := versionPattern.FindString(string(body))
return versionMatched, nil
if versionMatched := versionPattern.FindString(string(body)); versionMatched != "" {
return versionMatched, nil
}
return "", errors.New("not found version patterns")
}

0 comments on commit 6f1457a

Please sign in to comment.