Hello,
I have code which downloads json file from github.com, but when I check the file on my local machine it shows unnecessary stuff attached to the file, I just need the original file as shown in https://raw.githubusercontent.com/f5devcentral/f5-tetration/master/scripts/Tetration_TCP_L4_ipfix.json
if I open the file on my local machine it gives something like that …at the start
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="dns-prefetch" href="https://assets-cdn.github.com">
<link rel="dns-prefetch" href="https://avatars0.githubusercontent.com">
<link rel="dns-prefetch" href="https://avatars1.githubusercontent.com">
<link rel="dns-prefetch" href="https://avatars2.githubusercontent.com">
<link rel="dns-prefetch" href="https://avatars3.githubusercontent.com">
<link rel="dns-prefetch" href="https://github-cloud.s3.amazonaws.com">
<link rel="dns-prefetch" href="https://user-images.githubusercontent.com/">
Here is the code
fileTCPexists := fileTCPexists() // returns true or false
if fileTCPexists {
fmt.Println(" TCP File exists on your local machine")
} else {
fmt.Println(" irule does not exists on local machine ..... getting from github")
downloadTCPiruleFromGithub()
}
func downloadTCPiruleFromGithub() bool {
fmt.Println(" Downloading from github ........")
fileUrl := "https://github.com/f5devcentral/f5-tetration/blob/master/scripts/Tetration_TCP_L4_ipfix.json"
err := DownloadFile("irules/Tetration_TCP_L4_ipfix.json", fileUrl)
if err != nil {
panic(err)
}
return true
}
//DownloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func DownloadFile(filepath string, url string) error {
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}
return nil
}