I have a json file on AWS s3. I want to download them into a struct, not into a file. is this possible? or a way to delete the file after i put the data into a struct? i dont want extra files generated in my application.
I see the go example AWS s3 provides here
and reading the go aws s3 docs on the download func it writes to io.WriterAt is "io.writerAt" only can be a file type?
my problem is when i read S3 json files, and load my data into a struct, but it also ends up creating files in the application due to what i think io.writerAt must be a file type.
heres my code that reads in the AWS s3 json file, creates a file(which i dont want), and loads it into struct to pass along the rest of the code.
sess, _ := session.NewSession(&aws.Config{
Region: aws.String(c.AwsLocation),
})
downloader := s3manager.NewDownloader(sess)
doc := "myfile.json"
file, err := os.Create(doc) //PROBLEM creates file.
//todo err
defer file.Close()
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: aws.String(c.AwsBucket),
Key: aws.String(doc),
})
//todo err
fmt.Println("Downloaded", file.Name(), numBytes, "bytes")
//take data, and put in struct
byteValue, _ := ioutil.ReadAll(file)
var output myStruct
json.Unmarshal(byteValue, &output)
return output