This question already has an answer here:
- Format a Go string without printing? 4 answers
I am fairly new to GO and I was hoping someone would be able to point me in the right direction. I am trying to store a Print to a variable. To give some context, currently, I am retrieving the URL of a file that is in Amazon S3 and I would like to store the URL as a variable so I can send it out as say, an email or push notification.
Here is what I have at the moment:
func main() {
bucket := "bucket"
region := "eu-west-2"
// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
Region: aws.String("eu-west-2")},
)
// Create S3 service client
svc := s3.New(sess)
// Get the list of item
resp, err := svc.ListObjects(&s3.ListObjectsInput{Bucket: aws.String(bucket)})
if err != nil {
exitErrorf("Unable to list items in bucket %q, %v", bucket, err)
}
for _, item := range resp.Contents {
fmt.Printf("https://s3.%s.amazonaws.com/%s/%s", region, bucket, *item.Key)
fmt.Println("")
var url string = "https://s3.%s.amazonaws.com/%s/%s", region, bucket, *item.Key
}
}
func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"
", args...)
os.Exit(1)
}
This results in extra expression in var declaration
when attempting to compile (TBF I did not expect it to work). Would anyone know an alternative way of doing this?
Thanks!
</div>