session

package
v1.1.35-0...-ce9b3bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package session provides a way to create service clients with shared configuration and handlers.

Generally this package should be used instead of the `defaults` package.

A session should be used to share configurations and request handlers between multiple service clients. When service clients need specific configuration aws.Config can be used to provide additional configuration directly to the service client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session struct {
	Config   *aws.Config
	Handlers request.Handlers
}

A Session provides a central location to create service clients from and store configurations and request handlers for those services.

Sessions are safe to create service clients concurrently, but it is not safe to mutate the session concurrently.

func New

func New(cfgs ...*aws.Config) *Session

New creates a new instance of the handlers merging in the provided Configs on top of the SDK's default configurations. Once the session is created it can be mutated to modify Configs or Handlers. The session is safe to be read concurrently, but it should not be written to concurrently.

Example:

// Create a session with the default config and request handlers.
sess := session.New()

// Create a session with a custom region
sess := session.New(&aws.Config{Region: aws.String("us-east-1")})

// Create a session, and add additional handlers for all service
// clients created with the session to inherit. Adds logging handler.
sess := session.New()
sess.Handlers.Send.PushFront(func(r *request.Request) {
     // Log every request made and its payload
     logger.Println("Request: %s/%s, Payload: %s", r.ClientInfo.ServiceName, r.Operation, r.Params)
})

// Create a S3 client instance from a session
sess := session.New()
svc := s3.New(sess)

func (*Session) ClientConfig

func (s *Session) ClientConfig(serviceName string, cfgs ...*aws.Config) client.Config

ClientConfig satisfies the client.ConfigProvider interface and is used to configure the service client instances. Passing the Session to the service client's constructor (New) will use this method to configure the client.

Example:

sess := session.New()
s3.New(sess)

func (*Session) Copy

func (s *Session) Copy(cfgs ...*aws.Config) *Session

Copy creates and returns a copy of the current session, coping the config and handlers. If any additional configs are provided they will be merged on top of the session's copied config.

Example:

// Create a copy of the current session, configured for the us-west-2 region.
sess.Copy(&aws.Config{Region: aws.String("us-west-2")})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL