tools/version-tracker/pkg/util/file/file.go (40 lines of code) (raw):

package file import ( "io" "net/http" "os" "strings" ) func ReadContentsTrimmed(filePath string) (string, error) { contents, err := os.ReadFile(filePath) if err != nil { return "", err } return strings.TrimSpace(string(contents)), nil } // Download downloads a file from the given URL to the destination filepath. func Download(url, filepath string) error { resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() out, err := os.Create(filepath) if err != nil { return err } defer out.Close() _, err = io.Copy(out, resp.Body) return err } func ReadURL(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil { return nil, err } defer resp.Body.Close() data, err := io.ReadAll(resp.Body) if err != nil { return nil, err } return data, nil }