-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
150 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package images | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// parseChecksumLine extracts checksum information from a line | ||
func parseChecksumLine(line string, versionRegex *regexp.Regexp) (*DownloadInfo, error) { | ||
parts := strings.Fields(line) | ||
if len(parts) < 2 { | ||
return nil, fmt.Errorf("invalid checksum line format: %s", line) | ||
} | ||
|
||
checksum := parts[0] | ||
filename := parts[len(parts)-1] | ||
|
||
return &DownloadInfo{ | ||
Checksum: checksum, | ||
Version: versionRegex.FindString(filename), | ||
Filename: filename, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Package network provides HTTP client functionality. | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// GetResponse performs an HTTP GET request and returns the response with proper error handling | ||
func GetResponse(url string) (*http.Response, error) { | ||
resp, err := http.Get(url) //#nosec G107 | ||
if err != nil { | ||
return nil, err | ||
} | ||
if resp == nil { | ||
return nil, fmt.Errorf("nil HTTP response from %s", url) | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
err = resp.Body.Close() | ||
if err != nil { | ||
log.Warnf("failed to close response body: %v", err) | ||
} | ||
|
||
return nil, fmt.Errorf("bad HTTP status code (%s)", resp.Status) | ||
} | ||
|
||
return resp, nil | ||
} |