github.com/aavshr/aws-sdk-go@v1.41.3/example/service/ecr/deleteRepository/deleteRepository.go (about) 1 //go:build example 2 // +build example 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 10 "github.com/aavshr/aws-sdk-go/aws" 11 "github.com/aavshr/aws-sdk-go/aws/session" 12 "github.com/aavshr/aws-sdk-go/service/ecr" 13 ) 14 15 const DEFAULT_AWS_REGION = "us-east-1" 16 17 // This example deletes an ECR Repository 18 // 19 // Usage: 20 // AWS_REGION=us-east-1 go run -tags example deleteECRRepository.go <repo_name> 21 func main() { 22 23 config := &aws.Config{Region: aws.String(getAwsRegion())} 24 svc := ecr.New(session.New(), config) 25 26 repoName := getRepoNameArg() 27 if repoName == "" { 28 printUsageAndExit1() 29 } 30 input := &ecr.DeleteRepositoryInput{ 31 Force: aws.Bool(false), 32 RepositoryName: aws.String(repoName), 33 } 34 35 output, err := svc.DeleteRepository(input) 36 if err != nil { 37 fmt.Printf("\nError deleting the repo %v in region %v\n%v\n", repoName, aws.StringValue(config.Region), err.Error()) 38 os.Exit(1) 39 } 40 41 fmt.Printf("\nECR Repository \"%v\" deleted successfully!\n\nAWS Output:\n%v", repoName, output) 42 } 43 44 // Print correct usage and exit the program with code 1 45 func printUsageAndExit1() { 46 fmt.Println("\nUsage: AWS_REGION=us-east-1 go run -tags example deleteECRRepository.go <repo_name>") 47 os.Exit(1) 48 } 49 50 // Try get the repo name from the first argument 51 func getRepoNameArg() string { 52 if len(os.Args) < 2 { 53 return "" 54 } 55 firstArg := os.Args[1] 56 return firstArg 57 } 58 59 // Returns the aws region from env var or default region defined in DEFAULT_AWS_REGION constant 60 func getAwsRegion() string { 61 awsRegion := os.Getenv("AWS_REGION") 62 if awsRegion != "" { 63 return awsRegion 64 } 65 return DEFAULT_AWS_REGION 66 }