(repository string)
| 87 | } |
| 88 | |
| 89 | func GetLatestVersion(repository string) (string, error) { |
| 90 | client := &http.Client{ |
| 91 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 92 | return http.ErrUseLastResponse |
| 93 | }, |
| 94 | } |
| 95 | |
| 96 | resp, err := client.Get(repository + "/releases/latest") |
| 97 | if err != nil { |
| 98 | return "", err |
| 99 | } |
| 100 | |
| 101 | redirect := resp.Header.Get("location") |
| 102 | if redirect == "" { |
| 103 | return "", fmt.Errorf("redirect URL not found") |
| 104 | } |
| 105 | |
| 106 | matches := LatestTagRegEx.FindStringSubmatch(redirect) |
| 107 | if len(matches) != 2 { |
| 108 | return "", errors.Errorf("Couldn't find latest release version") |
| 109 | } |
| 110 | |
| 111 | return matches[1], nil |
| 112 | } |
no test coverage detected