func NewAsyncTransport(token string, endpoint string, buffer int) *AsyncTransport {
	transport := &AsyncTransport{
		baseTransport: baseTransport{
			Token:               token,
			Endpoint:            endpoint,
			RetryAttempts:       DefaultRetryAttempts,
			PrintPayloadOnError: true,
			ItemsPerMinute:      0,
		},
		bodyChannel: make(chan payload, buffer),
		Buffer:      buffer,
	}
	go func() {
		for p := range transport.bodyChannel {
			elapsedTime := time.Now().Sub(transport.startTime).Seconds()
			if elapsedTime < 0 || elapsedTime >= 60 {
				transport.startTime = time.Now()
				transport.perMinCounter = 0
			}
			if transport.shouldSend() {
				canRetry, err := transport.post(p.body)
				if err != nil {
					if canRetry && p.retriesLeft > 0 {
						p.retriesLeft -= 1
						select {
						case transport.bodyChannel <- p:
						default:
							if transport.PrintPayloadOnError {
								writePayloadToStderr(transport.Logger, p.body)
							}
							transport.waitGroup.Done()
						}
					} else {
						if transport.PrintPayloadOnError {
							writePayloadToStderr(transport.Logger, p.body)
						}
						transport.waitGroup.Done()
					}
				} else {
					transport.waitGroup.Done()
					transport.perMinCounter++
				}
			} else {
				transport.waitGroup.Done()
			}
		}
	}()
	return transport
}
NewAsyncTransport builds an asynchronous transport which sends data to the Rollbar API at the
specified endpoint using the given access token. The channel is limited to the size of the input
buffer argument.
package rollbar
import (
	"sync"
	"time"
)
type AsyncTransport struct {
	baseTransport
	Buffer      int
	bodyChannel chan payload
	waitGroup   sync.WaitGroup
}
type payload struct {
	body        map[string]interface{}
	retriesLeft int
}