github.com/aavshr/aws-sdk-go@v1.41.3/aws/endpoints/example_test.go (about)

     1  package endpoints_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/aavshr/aws-sdk-go/aws"
     7  	"github.com/aavshr/aws-sdk-go/aws/endpoints"
     8  	"github.com/aavshr/aws-sdk-go/aws/session"
     9  	"github.com/aavshr/aws-sdk-go/service/s3"
    10  	"github.com/aavshr/aws-sdk-go/service/sqs"
    11  )
    12  
    13  func ExampleEnumPartitions() {
    14  	resolver := endpoints.DefaultResolver()
    15  	partitions := resolver.(endpoints.EnumPartitions).Partitions()
    16  
    17  	for _, p := range partitions {
    18  		fmt.Println("Regions for", p.ID())
    19  		for id := range p.Regions() {
    20  			fmt.Println("*", id)
    21  		}
    22  
    23  		fmt.Println("Services for", p.ID())
    24  		for id := range p.Services() {
    25  			fmt.Println("*", id)
    26  		}
    27  	}
    28  }
    29  
    30  func ExampleResolverFunc() {
    31  	myCustomResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
    32  		if service == endpoints.S3ServiceID {
    33  			return endpoints.ResolvedEndpoint{
    34  				URL:           "s3.custom.endpoint.com",
    35  				SigningRegion: "custom-signing-region",
    36  			}, nil
    37  		}
    38  
    39  		return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
    40  	}
    41  
    42  	sess := session.Must(session.NewSession(&aws.Config{
    43  		Region:           aws.String("us-west-2"),
    44  		EndpointResolver: endpoints.ResolverFunc(myCustomResolver),
    45  	}))
    46  
    47  	// Create the S3 service client with the shared session. This will
    48  	// automatically use the S3 custom endpoint configured in the custom
    49  	// endpoint resolver wrapping the default endpoint resolver.
    50  	s3Svc := s3.New(sess)
    51  	// Operation calls will be made to the custom endpoint.
    52  	s3Svc.GetObject(&s3.GetObjectInput{
    53  		Bucket: aws.String("myBucket"),
    54  		Key:    aws.String("myObjectKey"),
    55  	})
    56  
    57  	// Create the SQS service client with the shared session. This will
    58  	// fallback to the default endpoint resolver because the customization
    59  	// passes any non S3 service endpoint resolve to the default resolver.
    60  	sqsSvc := sqs.New(sess)
    61  	// Operation calls will be made to the default endpoint for SQS for the
    62  	// region configured.
    63  	sqsSvc.ReceiveMessage(&sqs.ReceiveMessageInput{
    64  		QueueUrl: aws.String("my-queue-url"),
    65  	})
    66  }