I've created software in Go to create a presigned URL:
package main
import (
"fmt"
"log"
"time"
"github.com/minio/minio-go"
"github.com/kelseyhightower/envconfig"
)
type AWS struct {
Endpoint string
Access_Key_Id string
Secret_Access_Key string
SSL bool
Bucket string
Bucket_Key string
Bucket_Expiry string
}
func main() {
var aws AWS
// Add configurations from environment variable
// e.g:
// AWS_ENDPOINT -> aws.Endpoint
// AWS_ACCESS_KEY_ID -> aws.Access_Key_Id
// ...
if err := envconfig.Process("aws", &aws); err != nil {
log.Fatal(err.Error())
}
svc, err := minio.New(aws.Endpoint, aws.Access_Key_Id, aws.Secret_Access_Key, aws.SSL)
if err != nil {
}
fmt.Println(aws)
url, err := svc.PresignedPutObject(aws.Bucket, aws.Bucket_Key, aws.Bucket_Expiry)
if err != nil {
log.Fatalln(err)
}
fmt.Println("Successfully generated presigned URL", url)
}
I would like to know if it is possible to avoid all the if
statements for error validations. This is my second program in Go, and I have mainly a Node.js background, so I don't know exactly how to handle errors in Go-style, and also how to make the code more idiomatic.