├── .circleci └── config.yml ├── Dockerfile ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── Makefile ├── README.md ├── docker-compose.yml ├── example_graceful_shutdown_test.go ├── example_router_test.go ├── example_test.go ├── integration_test.go ├── message.go ├── mq.go ├── pkg ├── handlers │ └── opentracing │ │ ├── opentracing.go │ │ └── opentracing_test.go └── memsqs │ ├── memsqs.go │ └── memsqs_test.go ├── processors.go ├── processors_test.go ├── publisher.go ├── publisher_test.go ├── retry.go ├── retry_test.go ├── router.go ├── router_test.go ├── server.go ├── server_test.go └── vendor ├── github.com ├── aws │ └── aws-sdk-go │ │ ├── LICENSE.txt │ │ ├── NOTICE.txt │ │ ├── aws │ │ ├── awserr │ │ │ ├── error.go │ │ │ └── types.go │ │ ├── awsutil │ │ │ ├── copy.go │ │ │ ├── equal.go │ │ │ ├── path_value.go │ │ │ ├── prettify.go │ │ │ └── string_value.go │ │ ├── client │ │ │ ├── client.go │ │ │ ├── default_retryer.go │ │ │ ├── logger.go │ │ │ └── metadata │ │ │ │ └── client_info.go │ │ ├── config.go │ │ ├── context.go │ │ ├── context_1_6.go │ │ ├── context_1_7.go │ │ ├── convert_types.go │ │ ├── corehandlers │ │ │ ├── handlers.go │ │ │ ├── param_validator.go │ │ │ └── user_agent.go │ │ ├── credentials │ │ │ ├── chain_provider.go │ │ │ ├── credentials.go │ │ │ ├── ec2rolecreds │ │ │ │ └── ec2_role_provider.go │ │ │ ├── endpointcreds │ │ │ │ └── provider.go │ │ │ ├── env_provider.go │ │ │ ├── example.ini │ │ │ ├── shared_credentials_provider.go │ │ │ ├── static_provider.go │ │ │ └── stscreds │ │ │ │ └── assume_role_provider.go │ │ ├── defaults │ │ │ ├── defaults.go │ │ │ └── shared_config.go │ │ ├── doc.go │ │ ├── ec2metadata │ │ │ ├── api.go │ │ │ └── service.go │ │ ├── endpoints │ │ │ ├── decode.go │ │ │ ├── defaults.go │ │ │ ├── doc.go │ │ │ ├── endpoints.go │ │ │ ├── v3model.go │ │ │ └── v3model_codegen.go │ │ ├── errors.go │ │ ├── jsonvalue.go │ │ ├── logger.go │ │ ├── request │ │ │ ├── connection_reset_error.go │ │ │ ├── connection_reset_error_other.go │ │ │ ├── handlers.go │ │ │ ├── http_request.go │ │ │ ├── offset_reader.go │ │ │ ├── request.go │ │ │ ├── request_1_7.go │ │ │ ├── request_1_8.go │ │ │ ├── request_context.go │ │ │ ├── request_context_1_6.go │ │ │ ├── request_pagination.go │ │ │ ├── retryer.go │ │ │ ├── timeout_read_closer.go │ │ │ ├── validation.go │ │ │ └── waiter.go │ │ ├── session │ │ │ ├── doc.go │ │ │ ├── env_config.go │ │ │ ├── session.go │ │ │ └── shared_config.go │ │ ├── signer │ │ │ └── v4 │ │ │ │ ├── header_rules.go │ │ │ │ ├── options.go │ │ │ │ ├── uri_path.go │ │ │ │ └── v4.go │ │ ├── types.go │ │ ├── url.go │ │ ├── url_1_7.go │ │ └── version.go │ │ ├── internal │ │ ├── sdkio │ │ │ ├── io_go1.6.go │ │ │ └── io_go1.7.go │ │ ├── sdkrand │ │ │ └── locked_source.go │ │ └── shareddefaults │ │ │ └── shared_config.go │ │ ├── private │ │ └── protocol │ │ │ ├── idempotency.go │ │ │ ├── jsonvalue.go │ │ │ ├── query │ │ │ ├── build.go │ │ │ ├── queryutil │ │ │ │ └── queryutil.go │ │ │ ├── unmarshal.go │ │ │ └── unmarshal_error.go │ │ │ ├── rest │ │ │ ├── build.go │ │ │ ├── payload.go │ │ │ └── unmarshal.go │ │ │ ├── unmarshal.go │ │ │ └── xml │ │ │ └── xmlutil │ │ │ ├── build.go │ │ │ ├── unmarshal.go │ │ │ └── xml_to_struct.go │ │ └── service │ │ ├── sqs │ │ ├── api.go │ │ ├── checksums.go │ │ ├── customizations.go │ │ ├── doc.go │ │ ├── errors.go │ │ ├── service.go │ │ └── sqsiface │ │ │ └── interface.go │ │ └── sts │ │ ├── api.go │ │ ├── customizations.go │ │ ├── doc.go │ │ ├── errors.go │ │ └── service.go ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── go-ini │ └── ini │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── error.go │ │ ├── file.go │ │ ├── ini.go │ │ ├── key.go │ │ ├── parser.go │ │ ├── section.go │ │ └── struct.go ├── google │ └── uuid │ │ ├── .travis.yml │ │ ├── CONTRIBUTING.md │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── README.md │ │ ├── dce.go │ │ ├── doc.go │ │ ├── hash.go │ │ ├── marshal.go │ │ ├── node.go │ │ ├── sql.go │ │ ├── time.go │ │ ├── util.go │ │ ├── uuid.go │ │ ├── version1.go │ │ └── version4.go ├── jmespath │ └── go-jmespath │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── api.go │ │ ├── astnodetype_string.go │ │ ├── functions.go │ │ ├── interpreter.go │ │ ├── lexer.go │ │ ├── parser.go │ │ ├── toktype_string.go │ │ └── util.go ├── opentracing │ └── opentracing-go │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── ext │ │ └── tags.go │ │ ├── globaltracer.go │ │ ├── gocontext.go │ │ ├── log │ │ ├── field.go │ │ └── util.go │ │ ├── mocktracer │ │ ├── mocklogrecord.go │ │ ├── mockspan.go │ │ ├── mocktracer.go │ │ └── propagation.go │ │ ├── noop.go │ │ ├── propagation.go │ │ ├── span.go │ │ └── tracer.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go └── stretchr │ └── testify │ ├── LICENSE │ ├── assert │ ├── assertion_format.go │ ├── assertion_format.go.tmpl │ ├── assertion_forward.go │ ├── assertion_forward.go.tmpl │ ├── assertions.go │ ├── doc.go │ ├── errors.go │ ├── forward_assertions.go │ └── http_assertions.go │ └── require │ ├── doc.go │ ├── forward_requirements.go │ ├── require.go │ ├── require.go.tmpl │ ├── require_forward.go │ ├── require_forward.go.tmpl │ └── requirements.go └── golang.org └── x └── net ├── AUTHORS ├── CONTRIBUTORS ├── LICENSE ├── PATENTS └── context ├── context.go ├── go17.go ├── go19.go ├── pre_go17.go └── pre_go19.go /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Golang CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-go/ for more details 4 | version: 2 5 | jobs: 6 | build: 7 | docker: 8 | - image: circleci/golang:1.10 9 | working_directory: /go/src/github.com/remind101/mq-go 10 | steps: 11 | - checkout 12 | - run: go get -v -t -d ./... 13 | - run: go test -v ./... -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.10 2 | RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 3 | COPY . /go/src/github.com/remind101/mq-go 4 | WORKDIR /go/src/github.com/remind101/mq-go 5 | RUN dep ensure 6 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/aws/aws-sdk-go" 6 | packages = [ 7 | "aws", 8 | "aws/awserr", 9 | "aws/awsutil", 10 | "aws/client", 11 | "aws/client/metadata", 12 | "aws/corehandlers", 13 | "aws/credentials", 14 | "aws/credentials/ec2rolecreds", 15 | "aws/credentials/endpointcreds", 16 | "aws/credentials/stscreds", 17 | "aws/defaults", 18 | "aws/ec2metadata", 19 | "aws/endpoints", 20 | "aws/request", 21 | "aws/session", 22 | "aws/signer/v4", 23 | "internal/sdkio", 24 | "internal/sdkrand", 25 | "internal/shareddefaults", 26 | "private/protocol", 27 | "private/protocol/query", 28 | "private/protocol/query/queryutil", 29 | "private/protocol/rest", 30 | "private/protocol/xml/xmlutil", 31 | "service/sqs", 32 | "service/sqs/sqsiface", 33 | "service/sts" 34 | ] 35 | revision = "9b0098a71f6d4d473a26ec8ad3c2feaac6eb1da6" 36 | version = "v1.13.32" 37 | 38 | [[projects]] 39 | name = "github.com/davecgh/go-spew" 40 | packages = ["spew"] 41 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 42 | version = "v1.1.0" 43 | 44 | [[projects]] 45 | name = "github.com/go-ini/ini" 46 | packages = ["."] 47 | revision = "ace140f73450505f33e8b8418216792275ae82a7" 48 | version = "v1.35.0" 49 | 50 | [[projects]] 51 | name = "github.com/google/uuid" 52 | packages = ["."] 53 | revision = "064e2069ce9c359c118179501254f67d7d37ba24" 54 | version = "0.2" 55 | 56 | [[projects]] 57 | name = "github.com/jmespath/go-jmespath" 58 | packages = ["."] 59 | revision = "0b12d6b5" 60 | 61 | [[projects]] 62 | name = "github.com/opentracing/opentracing-go" 63 | packages = [ 64 | ".", 65 | "ext", 66 | "log", 67 | "mocktracer" 68 | ] 69 | revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" 70 | version = "v1.0.2" 71 | 72 | [[projects]] 73 | name = "github.com/pmezard/go-difflib" 74 | packages = ["difflib"] 75 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 76 | version = "v1.0.0" 77 | 78 | [[projects]] 79 | name = "github.com/stretchr/testify" 80 | packages = [ 81 | "assert", 82 | "require" 83 | ] 84 | revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" 85 | version = "v1.2.1" 86 | 87 | [[projects]] 88 | branch = "master" 89 | name = "golang.org/x/net" 90 | packages = ["context"] 91 | revision = "5f9ae10d9af5b1c89ae6904293b14b064d4ada23" 92 | 93 | [solve-meta] 94 | analyzer-name = "dep" 95 | analyzer-version = 1 96 | inputs-digest = "64cdd47a54c8680245eb7867639eca95994fe4d8498eb9ea31b111f991dbc251" 97 | solver-name = "gps-cdcl" 98 | solver-version = 1 99 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/aws/aws-sdk-go" 30 | version = "1.13.32" 31 | 32 | [[constraint]] 33 | name = "github.com/stretchr/testify" 34 | version = "1.2.1" 35 | 36 | [prune] 37 | go-tests = true 38 | unused-packages = true 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Remind101, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test-unit: 2 | go test ./... 3 | 4 | test-integration: 5 | go test -tags=integration ./... 6 | 7 | test-all: test-unit test-integration 8 | 9 | test: 10 | docker-compose run --rm test -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MQ - A package for consuming SQS message queues 2 | 3 | The goal of this project is to provide tooling to utilize SQS effectively in Go. 4 | 5 | ## Features 6 | 7 | * Familiar `net/http` Handler interface. 8 | * Retry with expontial backoff via visibility timeouts and dead letter queues. 9 | * Router Handler for multiplexing messages over a single queue. 10 | * Server with configurable concurrency and graceful shutdown. 11 | * Automatic batch fetching and deletion. 12 | * Publisher for batch sending. 13 | * Opentracing support 14 | 15 | ## Documentation 16 | 17 | https://godoc.org/github.com/remind101/mq-go 18 | 19 | ## QuickStart 20 | 21 | ``` golang 22 | func main() { 23 | queueURL := "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue" 24 | 25 | h := mq.HandlerFunc(func(m *mq.Message) error { 26 | fmt.Printf("Received message: %s", aws.StringValue(m.SQSMessage.Body)) 27 | 28 | // Returning no error signifies the message was processed successfully. 29 | // The Server will queue the message for deletion. 30 | return nil 31 | }) 32 | 33 | // Configure mq.Server 34 | s := mq.NewServer(queueURL, h) 35 | 36 | // Start a loop to receive SQS messages and pass them to the Handler. 37 | s.Start() 38 | defer s.Shutdown(context.Background()) 39 | 40 | // Start a publisher 41 | p := mq.NewPublisher(queueURL) 42 | p.Start() 43 | defer p.Shutdown(context.Background()) 44 | 45 | // Publish messages (will be batched). 46 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 47 | MessageBody: aws.String("Hello"), 48 | }) 49 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 50 | MessageBody: aws.String("World!"), 51 | }) 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | test: 5 | build: . 6 | command: make test-all 7 | environment: 8 | ELASTICMQ_URL: http://localstack:4576 9 | volumes: 10 | - .:/go/src/github.com/remind101/mq-go # mount source directory 11 | depends_on: 12 | - localstack 13 | localstack: 14 | image: localstack/localstack 15 | ports: 16 | - "4567-4583:4567-4583" 17 | - "8080:8080" 18 | environment: 19 | - SERVICES=sqs 20 | - DOCKER_HOST=unix:///var/run/docker.sock 21 | -------------------------------------------------------------------------------- /example_graceful_shutdown_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "os/signal" 8 | "syscall" 9 | "time" 10 | 11 | "github.com/aws/aws-sdk-go/aws" 12 | mq "github.com/remind101/mq-go" 13 | ) 14 | 15 | func Example_gracefulShutdown() { 16 | queueURL := "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue" 17 | 18 | h := mq.HandlerFunc(func(m *mq.Message) error { 19 | fmt.Printf("Received message: %s", aws.StringValue(m.SQSMessage.Body)) 20 | 21 | // Returning no error signifies the message was processed successfully. 22 | // The Server will queue the message for deletion. 23 | return nil 24 | }) 25 | 26 | // Configure mq.Server 27 | s := mq.NewServer(queueURL, h) 28 | 29 | // Handle SIGINT and SIGTERM gracefully. 30 | go func() { 31 | sigCh := make(chan os.Signal, 1) 32 | signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) 33 | <-sigCh 34 | 35 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 36 | defer cancel() 37 | 38 | // We received an interrupt signal, shut down gracefully. 39 | if err := s.Shutdown(ctx); err != nil { 40 | fmt.Printf("SQS server shutdown: %v\n", err) 41 | } 42 | }() 43 | 44 | // Start a loop to receive SQS messages and pass them to the Handler. 45 | s.Start() 46 | } 47 | -------------------------------------------------------------------------------- /example_router_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go/service/sqs" 7 | "github.com/aws/aws-sdk-go/service/sqs/sqsiface" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | mq "github.com/remind101/mq-go" 11 | ) 12 | 13 | func Example_router() { 14 | queueURL := "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue" 15 | 16 | r := mq.NewRouter() 17 | r.Handle("foo-jobs", mq.HandlerFunc(func(m *mq.Message) error { 18 | fmt.Printf("Received foo message: %s", aws.StringValue(m.SQSMessage.Body)) 19 | return nil 20 | })) 21 | 22 | r.Handle("bar-jobs", mq.HandlerFunc(func(m *mq.Message) error { 23 | fmt.Printf("Received bar message: %s", aws.StringValue(m.SQSMessage.Body)) 24 | return nil 25 | })) 26 | 27 | // Configure mq.Server 28 | s := mq.NewServer(queueURL, r) 29 | 30 | // Start a loop to receive SQS messages and pass them to the Handler. 31 | go s.Start() 32 | 33 | // Publish a foo message 34 | publish(s.Client, queueURL, "foo-jobs", "this will route to foo-jobs handler func") 35 | 36 | // Publish a bar message 37 | publish(s.Client, queueURL, "bar-jobs", "this will route to bar-jobs handler func") 38 | } 39 | 40 | func publish(client sqsiface.SQSAPI, queueURL, route, message string) error { 41 | input := &sqs.SendMessageInput{ 42 | QueueUrl: aws.String(queueURL), 43 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 44 | mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{ 45 | DataType: aws.String("String"), 46 | StringValue: aws.String(route), 47 | }, 48 | }, 49 | MessageBody: aws.String(message), 50 | } 51 | 52 | _, err := client.SendMessage(input) 53 | return err 54 | } 55 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/aws/aws-sdk-go/aws" 8 | "github.com/aws/aws-sdk-go/service/sqs" 9 | mq "github.com/remind101/mq-go" 10 | ) 11 | 12 | func Example() { 13 | queueURL := "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue" 14 | 15 | h := mq.HandlerFunc(func(m *mq.Message) error { 16 | fmt.Printf("Received message: %s", aws.StringValue(m.SQSMessage.Body)) 17 | 18 | // Returning no error signifies the message was processed successfully. 19 | // The Server will queue the message for deletion. 20 | return nil 21 | }) 22 | 23 | // Configure mq.Server 24 | s := mq.NewServer(queueURL, h) 25 | 26 | // Start a loop to receive SQS messages and pass them to the Handler. 27 | s.Start() 28 | defer s.Shutdown(context.Background()) 29 | 30 | // Start a publisher 31 | p := mq.NewPublisher(queueURL) 32 | p.Start() 33 | defer p.Shutdown(context.Background()) 34 | 35 | // Publish messages (will be batched). 36 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 37 | MessageBody: aws.String("Hello"), 38 | }) 39 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 40 | MessageBody: aws.String("World!"), 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /integration_test.go: -------------------------------------------------------------------------------- 1 | // +build integration 2 | 3 | package mq_test 4 | 5 | import ( 6 | "context" 7 | "os" 8 | "testing" 9 | 10 | "github.com/aws/aws-sdk-go/service/sqs/sqsiface" 11 | mq "github.com/remind101/mq-go" 12 | "github.com/stretchr/testify/assert" 13 | "github.com/stretchr/testify/require" 14 | 15 | "github.com/aws/aws-sdk-go/aws" 16 | "github.com/aws/aws-sdk-go/aws/credentials" 17 | "github.com/aws/aws-sdk-go/aws/session" 18 | "github.com/aws/aws-sdk-go/service/sqs" 19 | ) 20 | 21 | func TestRouterIntegration(t *testing.T) { 22 | c := newClient() 23 | 24 | // Create a new queue. 25 | queueURL := createQueue(t, c, "jobs") 26 | 27 | // Send a message. 28 | sendMessage(t, c, queueURL, aws.String("worker.1"), aws.String("do some work")) 29 | 30 | done := make(chan struct{}) 31 | 32 | // Init handler. 33 | r := mq.NewRouter() 34 | 35 | // Route certain messages to a specific handler. 36 | r.Handle("worker.1", mq.HandlerFunc(func(m *mq.Message) (err error) { 37 | defer func() { 38 | err = m.Delete() 39 | assert.NoError(t, err) 40 | }() 41 | assert.Equal(t, "do some work", aws.StringValue(m.SQSMessage.Body)) 42 | close(done) 43 | return 44 | })) 45 | 46 | // Run server until message is received. 47 | s := mq.NewServer(*queueURL, r, mq.WithClient(c)) 48 | s.Start() 49 | defer s.Shutdown(context.Background()) 50 | 51 | <-done 52 | } 53 | 54 | func newClient() sqsiface.SQSAPI { 55 | config := aws.NewConfig() 56 | config = config.WithEndpoint(os.Getenv("ELASTICMQ_URL")) 57 | config = config.WithRegion("local") 58 | config = config.WithCredentials(credentials.NewStaticCredentials("id", "secret", "token")) 59 | return sqs.New(session.New(config)) 60 | } 61 | 62 | func createQueue(t *testing.T, c sqsiface.SQSAPI, name string) *string { 63 | out, err := c.CreateQueue(&sqs.CreateQueueInput{ 64 | QueueName: aws.String(name), 65 | }) 66 | require.NoError(t, err) 67 | 68 | _, err = c.PurgeQueue(&sqs.PurgeQueueInput{QueueUrl: out.QueueUrl}) 69 | require.NoError(t, err) 70 | 71 | return out.QueueUrl 72 | } 73 | 74 | func sendMessage(t *testing.T, c sqsiface.SQSAPI, qURL, route, body *string) { 75 | _, err := c.SendMessage(&sqs.SendMessageInput{ 76 | QueueUrl: qURL, 77 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 78 | mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{ 79 | DataType: aws.String("String"), 80 | StringValue: route, 81 | }, 82 | }, 83 | MessageBody: body, 84 | }) 85 | require.NoError(t, err) 86 | } 87 | -------------------------------------------------------------------------------- /message.go: -------------------------------------------------------------------------------- 1 | package mq 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/service/sqs" 8 | "github.com/aws/aws-sdk-go/service/sqs/sqsiface" 9 | ) 10 | 11 | // Message wraps an sqs.Message. 12 | type Message struct { 13 | QueueURL string 14 | SQSMessage *sqs.Message 15 | RetryPolicy RetryPolicy 16 | 17 | client sqsiface.SQSAPI 18 | ctx context.Context 19 | } 20 | 21 | // NewMessage returns a fully initialized Message. 22 | func NewMessage(queueURL string, sqsMessage *sqs.Message, client sqsiface.SQSAPI) *Message { 23 | return &Message{ 24 | QueueURL: queueURL, 25 | SQSMessage: sqsMessage, 26 | RetryPolicy: DefaultRetryPolicy, 27 | client: client, 28 | ctx: context.Background(), 29 | } 30 | } 31 | 32 | // Delete removes the message from the queue. Use is discouraged however, since 33 | // the Server will handle message deletion more efficiently. 34 | func (m *Message) Delete() error { 35 | return deleteMessage(mustClient(m.client), m) 36 | } 37 | 38 | // ChangeVisibility changes the VisibilityTimeout to timeout seconds. 39 | func (m *Message) ChangeVisibility(timeout *int64) error { 40 | return changeMessageVisibility(mustClient(m.client), m, timeout) 41 | } 42 | 43 | // Context returns the message context. 44 | func (m *Message) Context() context.Context { 45 | return m.ctx 46 | } 47 | 48 | // WithContext returns a shallow copy of the message its context changed to ctx. 49 | func (m *Message) WithContext(ctx context.Context) *Message { 50 | if ctx == nil { 51 | panic("nil context") 52 | } 53 | m2 := new(Message) 54 | *m2 = *m 55 | m2.ctx = ctx 56 | 57 | return m2 58 | } 59 | 60 | func deleteMessage(c sqsiface.SQSAPI, m *Message) error { 61 | _, err := c.DeleteMessage(&sqs.DeleteMessageInput{ 62 | QueueUrl: aws.String(m.QueueURL), 63 | ReceiptHandle: m.SQSMessage.ReceiptHandle, 64 | }) 65 | return err 66 | } 67 | 68 | func changeMessageVisibility(c sqsiface.SQSAPI, m *Message, timeout *int64) error { 69 | _, err := c.ChangeMessageVisibility(&sqs.ChangeMessageVisibilityInput{ 70 | QueueUrl: aws.String(m.QueueURL), 71 | ReceiptHandle: m.SQSMessage.ReceiptHandle, 72 | VisibilityTimeout: timeout, 73 | }) 74 | 75 | return err 76 | } 77 | 78 | func mustClient(c sqsiface.SQSAPI) sqsiface.SQSAPI { 79 | if c == nil { 80 | panic("client is nil") 81 | } 82 | return c 83 | } 84 | -------------------------------------------------------------------------------- /mq.go: -------------------------------------------------------------------------------- 1 | // Package mq provides primitives for consuming SQS queues. 2 | package mq // import "github.com/remind101/mq-go" 3 | 4 | // A Handler processes a Message. 5 | type Handler interface { 6 | HandleMessage(*Message) error 7 | } 8 | 9 | // HandlerFunc is an adaptor to allow the use of ordinary functions as message Handlers. 10 | type HandlerFunc func(*Message) error 11 | 12 | // HandleMessage satisfies the Handler interface. 13 | func (h HandlerFunc) HandleMessage(m *Message) error { 14 | return h(m) 15 | } 16 | -------------------------------------------------------------------------------- /pkg/handlers/opentracing/opentracing.go: -------------------------------------------------------------------------------- 1 | package opentracing 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws" 5 | "github.com/aws/aws-sdk-go/service/sqs" 6 | opentracing "github.com/opentracing/opentracing-go" 7 | "github.com/opentracing/opentracing-go/ext" 8 | mq "github.com/remind101/mq-go" 9 | ) 10 | 11 | var DefaultSpanName = "sqs.message" 12 | var DefaultTagger = func(span opentracing.Span, m *mq.Message, err error) { 13 | if err != nil { 14 | span.SetTag("error.error", err) 15 | } 16 | } 17 | 18 | type Middleware struct { 19 | Handler mq.Handler 20 | SpanName string 21 | Tagger func(opentracing.Span, *mq.Message, error) 22 | } 23 | 24 | func (m *Middleware) HandleMessage(msg *mq.Message) error { 25 | tagger := DefaultTagger 26 | if m.Tagger != nil { 27 | tagger = m.Tagger 28 | } 29 | 30 | spanName := DefaultSpanName 31 | if m.SpanName != "" { 32 | spanName = m.SpanName 33 | } 34 | 35 | span := SpanFromMessage(spanName, msg.SQSMessage) 36 | defer span.Finish() 37 | 38 | ctx := opentracing.ContextWithSpan(msg.Context(), span) 39 | msg = msg.WithContext(ctx) 40 | err := m.Handler.HandleMessage(msg) 41 | tagger(span, msg, err) 42 | 43 | return err 44 | } 45 | 46 | type SQSMessageAttributeCarrier map[string]*sqs.MessageAttributeValue 47 | 48 | func (c SQSMessageAttributeCarrier) Set(key, val string) { 49 | c[key] = &sqs.MessageAttributeValue{ 50 | DataType: aws.String("String"), 51 | StringValue: aws.String(val), 52 | } 53 | } 54 | 55 | func (c SQSMessageAttributeCarrier) ForeachKey(handler func(key, val string) error) error { 56 | for k, v := range c { 57 | if aws.StringValue(v.DataType) == "String" { 58 | if err := handler(k, aws.StringValue(v.StringValue)); err != nil { 59 | return err 60 | } 61 | } 62 | } 63 | return nil 64 | } 65 | 66 | func InjectSpan(span opentracing.Span, m *sqs.Message) error { 67 | return opentracing.GlobalTracer().Inject( 68 | span.Context(), 69 | opentracing.TextMap, 70 | SQSMessageAttributeCarrier(m.MessageAttributes), 71 | ) 72 | } 73 | 74 | func SpanFromMessage(spanName string, m *sqs.Message) opentracing.Span { 75 | span := opentracing.StartSpan(spanName) 76 | if m.MessageAttributes != nil { 77 | spanContext, err := opentracing.GlobalTracer().Extract( 78 | opentracing.TextMap, 79 | SQSMessageAttributeCarrier(m.MessageAttributes), 80 | ) 81 | if err == nil { 82 | span = opentracing.StartSpan(spanName, ext.RPCServerOption(spanContext)) 83 | } 84 | } 85 | return span 86 | } 87 | -------------------------------------------------------------------------------- /pkg/handlers/opentracing/opentracing_test.go: -------------------------------------------------------------------------------- 1 | package opentracing_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/service/sqs" 11 | opentracing "github.com/opentracing/opentracing-go" 12 | "github.com/opentracing/opentracing-go/ext" 13 | "github.com/opentracing/opentracing-go/mocktracer" 14 | mq "github.com/remind101/mq-go" 15 | mq_opentracing "github.com/remind101/mq-go/pkg/handlers/opentracing" 16 | ) 17 | 18 | func TestCarrier(t *testing.T) { 19 | tracer := mocktracer.New() 20 | opentracing.SetGlobalTracer(tracer) 21 | 22 | span := opentracing.StartSpan("root") 23 | m := &sqs.Message{ 24 | MessageAttributes: map[string]*sqs.MessageAttributeValue{}, 25 | } 26 | 27 | // Inject span into message 28 | err := opentracing.GlobalTracer().Inject( 29 | span.Context(), 30 | opentracing.TextMap, 31 | mq_opentracing.SQSMessageAttributeCarrier(m.MessageAttributes), 32 | ) 33 | require.NoError(t, err) 34 | 35 | // Extract span out of message 36 | wireContext, err := opentracing.GlobalTracer().Extract( 37 | opentracing.TextMap, 38 | mq_opentracing.SQSMessageAttributeCarrier(m.MessageAttributes), 39 | ) 40 | require.NoError(t, err) 41 | 42 | childSpan := opentracing.StartSpan("child-span", ext.RPCServerOption(wireContext)) 43 | childSpanParentID := childSpan.(*mocktracer.MockSpan).ParentID 44 | rootSpanID := span.(*mocktracer.MockSpan).SpanContext.SpanID 45 | require.Equal(t, rootSpanID, childSpanParentID) 46 | } 47 | 48 | func TestHandler(t *testing.T) { 49 | tracer := mocktracer.New() 50 | opentracing.SetGlobalTracer(tracer) 51 | 52 | span := opentracing.StartSpan("root") 53 | 54 | m := mq.NewMessage("http://sqs.example.com/myqueue", &sqs.Message{ 55 | MessageAttributes: map[string]*sqs.MessageAttributeValue{}, 56 | Body: aws.String("hello"), 57 | }, nil) 58 | 59 | err := mq_opentracing.InjectSpan(span, m.SQSMessage) 60 | require.NoError(t, err) 61 | 62 | h := mq_opentracing.Middleware{ 63 | Handler: mq.HandlerFunc(func(*mq.Message) error { 64 | return nil 65 | }), 66 | Tagger: func(span opentracing.Span, m *mq.Message, err error) { 67 | mq_opentracing.DefaultTagger(span, m, err) 68 | span.SetTag("foo", "bar") 69 | }, 70 | } 71 | 72 | require.NoError(t, h.HandleMessage(m)) 73 | require.Equal(t, 1, len(tracer.FinishedSpans())) 74 | 75 | handlerSpan := tracer.FinishedSpans()[0] 76 | assert.Equal(t, "sqs.message", handlerSpan.OperationName) 77 | assert.Equal(t, "bar", handlerSpan.Tags()["foo"].(string)) 78 | 79 | assert.Equal(t, span.(*mocktracer.MockSpan).SpanContext.SpanID, handlerSpan.ParentID) 80 | } 81 | -------------------------------------------------------------------------------- /pkg/memsqs/memsqs_test.go: -------------------------------------------------------------------------------- 1 | package memsqs_test 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/aws/aws-sdk-go/aws" 8 | "github.com/aws/aws-sdk-go/service/sqs" 9 | "github.com/remind101/mq-go/pkg/memsqs" 10 | "github.com/stretchr/testify/assert" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func TestSendMessage(t *testing.T) { 15 | c := memsqs.New() 16 | _, err := c.SendMessage(&sqs.SendMessageInput{ 17 | QueueUrl: aws.String("jobs"), 18 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 19 | "group": &sqs.MessageAttributeValue{ 20 | DataType: aws.String("String"), 21 | StringValue: aws.String("/jobs/priority"), 22 | }, 23 | }, 24 | MessageBody: aws.String("hello"), 25 | }) 26 | require.NoError(t, err) 27 | require.Equal(t, 1, len(c.Queue("jobs"))) 28 | assert.Equal(t, "hello", aws.StringValue(c.Queue("jobs")[0].SQSMessage.Body)) 29 | } 30 | 31 | func TestReceiveMessage(t *testing.T) { 32 | c := memsqs.New() 33 | 34 | // Send a message. 35 | _, err := c.SendMessage(&sqs.SendMessageInput{ 36 | QueueUrl: aws.String("jobs"), 37 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 38 | "group": &sqs.MessageAttributeValue{ 39 | DataType: aws.String("String"), 40 | StringValue: aws.String("/jobs/priority"), 41 | }, 42 | }, 43 | MessageBody: aws.String("job1"), 44 | }) 45 | require.NoError(t, err) 46 | 47 | // Receive message. 48 | out, err := c.ReceiveMessage(&sqs.ReceiveMessageInput{ 49 | MaxNumberOfMessages: aws.Int64(1), 50 | QueueUrl: aws.String("jobs"), 51 | VisibilityTimeout: aws.Int64(1), 52 | }) 53 | 54 | // Assert message no longer visible. 55 | require.Equal(t, 1, len(out.Messages)) 56 | require.Equal(t, 1, len(c.Queue("jobs"))) 57 | require.Equal(t, 0, len(c.VisibleQueue("jobs"))) 58 | 59 | assert.Equal(t, "job1", aws.StringValue(out.Messages[0].Body)) 60 | receiveCount, ok := out.Messages[0].MessageAttributes[sqs.MessageSystemAttributeNameApproximateReceiveCount] 61 | require.True(t, ok) 62 | assert.Equal(t, "1", aws.StringValue(receiveCount.StringValue)) 63 | 64 | time.Sleep(1 * time.Second) 65 | time.Sleep(1 * time.Millisecond) 66 | 67 | // Assert message is visible again. 68 | require.Equal(t, 1, len(c.VisibleQueue("jobs"))) 69 | 70 | // Assert receive count increments. 71 | out, err = c.ReceiveMessage(&sqs.ReceiveMessageInput{ 72 | MaxNumberOfMessages: aws.Int64(1), 73 | QueueUrl: aws.String("jobs"), 74 | VisibilityTimeout: aws.Int64(1), 75 | }) 76 | receiveCount, ok = out.Messages[0].MessageAttributes[sqs.MessageSystemAttributeNameApproximateReceiveCount] 77 | require.True(t, ok) 78 | assert.Equal(t, "2", aws.StringValue(receiveCount.StringValue)) 79 | 80 | // Delete message. 81 | _, err = c.DeleteMessage(&sqs.DeleteMessageInput{ 82 | QueueUrl: aws.String("jobs"), 83 | ReceiptHandle: out.Messages[0].ReceiptHandle, 84 | }) 85 | require.NoError(t, err) 86 | 87 | // Assert message no longer exists. 88 | require.Equal(t, 0, len(c.VisibleQueue("jobs"))) 89 | require.Equal(t, 0, len(c.Queue("jobs"))) 90 | } 91 | -------------------------------------------------------------------------------- /processors_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/service/sqs" 11 | mq "github.com/remind101/mq-go" 12 | "github.com/remind101/mq-go/pkg/memsqs" 13 | ) 14 | 15 | func TestPartitionedProcessor(t *testing.T) { 16 | qURL := "jobs" 17 | done := make(chan struct{}) 18 | c := memsqs.New() 19 | numMessages := 10 20 | messageBodies := make([]string, numMessages) 21 | 22 | // Push enough messages into the queue to trigger a batch delete call. 23 | for i := 0; i < numMessages; i++ { 24 | body := fmt.Sprintf("message %d", i) 25 | messageBodies[i] = body 26 | 27 | c.SendMessage(&sqs.SendMessageInput{ 28 | QueueUrl: aws.String(qURL), 29 | MessageBody: aws.String(body), 30 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 31 | mq.MessageAttributeNamePartitionKey: &sqs.MessageAttributeValue{ 32 | StringValue: aws.String("partition 1"), 33 | DataType: aws.String("String"), 34 | }, 35 | }, 36 | }) 37 | } 38 | 39 | messagesReceived := 0 40 | messageBodiesReceived := []string{} 41 | 42 | h := mq.HandlerFunc(func(m *mq.Message) error { 43 | messagesReceived++ 44 | messageBodiesReceived = append(messageBodiesReceived, aws.StringValue(m.SQSMessage.Body)) 45 | if messagesReceived >= numMessages { 46 | close(done) 47 | } 48 | return nil 49 | }) 50 | 51 | sp := newServer(t, qURL, h, c, mq.WithConcurrency(numMessages), mq.WithPartitionedProcessor) 52 | sp.Start() 53 | defer closeServer(t, sp) 54 | 55 | // Wait for server to receive all messages, batch deletion should 56 | // trigger immediately at this point. 57 | <-done 58 | 59 | assert.Equal(t, messageBodies, messageBodiesReceived) 60 | } 61 | -------------------------------------------------------------------------------- /publisher_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "testing" 9 | "time" 10 | 11 | "github.com/aws/aws-sdk-go/aws" 12 | "github.com/aws/aws-sdk-go/service/sqs/sqsiface" 13 | 14 | "github.com/aws/aws-sdk-go/service/sqs" 15 | mq "github.com/remind101/mq-go" 16 | "github.com/remind101/mq-go/pkg/memsqs" 17 | "github.com/stretchr/testify/assert" 18 | ) 19 | 20 | func TestPublisherFlushesOnShutdown(t *testing.T) { 21 | qURL := "jobs" 22 | c := memsqs.New() 23 | 24 | p := newPublisher(t, qURL, c) 25 | p.Start() 26 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 27 | MessageBody: aws.String("job1"), 28 | }) 29 | shutdownPublisher(t, p) // Wait for server to shutdown 30 | assert.Equal(t, 1, len(c.Queue(qURL))) 31 | } 32 | 33 | func TestPublisherSendsWhenBatchMaxReached(t *testing.T) { 34 | qURL := "jobs" 35 | c := memsqs.New() 36 | 37 | p := newPublisher(t, qURL, c) 38 | p.Start() 39 | defer shutdownPublisher(t, p) 40 | 41 | // Push enough messages into the queue to trigger a batch send call. 42 | for i := 0; i < mq.DefaultMaxNumberOfMessages; i++ { 43 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 44 | MessageBody: aws.String(fmt.Sprintf("job%d", i)), 45 | }) 46 | } 47 | 48 | // Assert queue receives messages before mq.DefaultPublishInterval is reached. 49 | eventually(t, 500*time.Millisecond, func() bool { 50 | return len(c.Queue(qURL)) == mq.DefaultMaxNumberOfMessages 51 | }, "expected messages to be batch sent") 52 | } 53 | 54 | func TestPublisherSendsWhenIntervalIsReached(t *testing.T) { 55 | qURL := "jobs" 56 | c := memsqs.New() 57 | 58 | p := newPublisher(t, qURL, c) 59 | p.PublishInterval = 10 * time.Millisecond 60 | p.Start() 61 | defer shutdownPublisher(t, p) 62 | 63 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 64 | MessageBody: aws.String("job1"), 65 | }) 66 | 67 | p.Publish(&sqs.SendMessageBatchRequestEntry{ 68 | MessageBody: aws.String("job1"), 69 | }) 70 | 71 | // Assert message is in queue after at least 2 intervals. 72 | eventually(t, 20*time.Millisecond, func() bool { 73 | return len(c.Queue(qURL)) == 2 74 | }, "expected messages to be batch sent after the PublishInterval") 75 | } 76 | 77 | func newPublisher(t *testing.T, qURL string, c sqsiface.SQSAPI) *mq.Publisher { 78 | return mq.NewPublisher(qURL, func(p *mq.Publisher) { 79 | p.Client = c 80 | p.OutputHandler = func(out *sqs.SendMessageBatchOutput, err error) { 81 | if err != nil { 82 | t.Fatal(err) 83 | } 84 | } 85 | if os.Getenv("DEBUG") == "true" { 86 | p.Logger = log.New(os.Stderr, "publisher - ", 0) 87 | } 88 | }) 89 | } 90 | 91 | func shutdownPublisher(t *testing.T, s *mq.Publisher) { 92 | t.Helper() 93 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) 94 | defer cancel() 95 | assert.NoError(t, s.Shutdown(ctx)) 96 | } 97 | -------------------------------------------------------------------------------- /retry.go: -------------------------------------------------------------------------------- 1 | package mq 2 | 3 | import ( 4 | "math" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | ) 8 | 9 | // MaxVisibilityTimeout is the maximum allowed VisibilityTimeout by SQS. 10 | const MaxVisibilityTimeout = 43200 // 12 hours 11 | 12 | // RetryPolicy defines an interface to determine when to retry a Message. 13 | type RetryPolicy interface { 14 | // Amount to delay the message visibility in seconds from the time the 15 | // message was first received, based on the number of times it has been 16 | // received so far. 17 | Delay(receiveCount int) *int64 // Seconds 18 | } 19 | 20 | type defaultRetryPolicy struct{} 21 | 22 | func (r *defaultRetryPolicy) Delay(receiveCount int) *int64 { 23 | exp2 := math.Exp2(float64(receiveCount)) 24 | min := math.Min(exp2, float64(MaxVisibilityTimeout)) 25 | return aws.Int64(int64(min)) 26 | } 27 | 28 | // DefaultRetryPolicy increases the Message VisibilityTimeout exponentially 29 | // based on the received count up to MaxVisibilityTimeout and MaxReceives 30 | var DefaultRetryPolicy = &defaultRetryPolicy{} 31 | -------------------------------------------------------------------------------- /retry_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | mq "github.com/remind101/mq-go" 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestRetry(t *testing.T) { 12 | tests := []struct { 13 | ReceiveCount int 14 | Delay *int64 15 | }{ 16 | { 17 | ReceiveCount: 1, 18 | Delay: aws.Int64(2), 19 | }, 20 | { 21 | ReceiveCount: 2, 22 | Delay: aws.Int64(4), 23 | }, 24 | { 25 | ReceiveCount: 3, 26 | Delay: aws.Int64(8), 27 | }, 28 | } 29 | 30 | for _, tt := range tests { 31 | assert.Equal(t, tt.Delay, mq.DefaultRetryPolicy.Delay(tt.ReceiveCount)) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /router.go: -------------------------------------------------------------------------------- 1 | package mq 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "sync" 7 | 8 | "github.com/aws/aws-sdk-go/aws" 9 | ) 10 | 11 | // MessageAttributeNameRoute is a MessageAttribute name used as a routing key by 12 | // the Router. 13 | const MessageAttributeNameRoute = "route" 14 | 15 | // Router will route a message based on MessageAttributes to other registered Handlers. 16 | type Router struct { 17 | sync.Mutex 18 | 19 | // Resolver maps a Message to a string identifier used to match to a registered Handler. The 20 | // default implementation returns a MessageAttribute named "route". 21 | Resolver func(*Message) (string, bool) 22 | 23 | // A map of handlers to route to. The return value of Resolver should match a key in this map. 24 | handlers map[string]Handler 25 | } 26 | 27 | // NewRouter returns a new Router. 28 | func NewRouter() *Router { 29 | return &Router{ 30 | Resolver: defaultResolver, 31 | handlers: map[string]Handler{}, 32 | } 33 | } 34 | 35 | // Handle registers a Handler under a route key. 36 | func (r *Router) Handle(route string, h Handler) { 37 | r.Lock() 38 | defer r.Unlock() 39 | 40 | r.handlers[route] = h 41 | } 42 | 43 | // HandleMessage satisfies the Handler interface. 44 | func (r *Router) HandleMessage(m *Message) error { 45 | key, ok := r.Resolver(m) 46 | if !ok { 47 | return errors.New("no routing key for message") 48 | } 49 | 50 | if h, ok := r.handlers[key]; ok { 51 | return h.HandleMessage(m) 52 | } 53 | 54 | return fmt.Errorf("no handler matched for routing key: %s", key) 55 | } 56 | 57 | func defaultResolver(m *Message) (string, bool) { 58 | r := "" 59 | v, ok := m.SQSMessage.MessageAttributes[MessageAttributeNameRoute] 60 | if ok { 61 | r = aws.StringValue(v.StringValue) 62 | } 63 | return r, ok 64 | } 65 | -------------------------------------------------------------------------------- /router_test.go: -------------------------------------------------------------------------------- 1 | package mq_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/service/sqs" 8 | "github.com/stretchr/testify/assert" 9 | 10 | mq "github.com/remind101/mq-go" 11 | ) 12 | 13 | func TestRouter(t *testing.T) { 14 | r := mq.NewRouter() 15 | r.Handle("foo", mq.HandlerFunc(func(m *mq.Message) error { return nil })) 16 | 17 | // No routing key 18 | err := r.HandleMessage(&mq.Message{ 19 | SQSMessage: &sqs.Message{}, 20 | }) 21 | assert.Error(t, err) 22 | assert.Equal(t, "no routing key for message", err.Error()) 23 | 24 | // Routing key does not match 25 | err = r.HandleMessage(&mq.Message{ 26 | SQSMessage: &sqs.Message{ 27 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 28 | mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{ 29 | StringValue: aws.String("bar"), 30 | }, 31 | }, 32 | }, 33 | }) 34 | 35 | assert.Error(t, err) 36 | assert.Equal(t, "no handler matched for routing key: bar", err.Error()) 37 | 38 | // Matching routing key 39 | err = r.HandleMessage(&mq.Message{ 40 | SQSMessage: &sqs.Message{ 41 | MessageAttributes: map[string]*sqs.MessageAttributeValue{ 42 | mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{ 43 | StringValue: aws.String("foo"), 44 | }, 45 | }, 46 | }, 47 | }) 48 | assert.NoError(t, err) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/NOTICE.txt: -------------------------------------------------------------------------------- 1 | AWS SDK for Go 2 | Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | Copyright 2014-2015 Stripe, Inc. 4 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/awsutil/copy.go: -------------------------------------------------------------------------------- 1 | package awsutil 2 | 3 | import ( 4 | "io" 5 | "reflect" 6 | "time" 7 | ) 8 | 9 | // Copy deeply copies a src structure to dst. Useful for copying request and 10 | // response structures. 11 | // 12 | // Can copy between structs of different type, but will only copy fields which 13 | // are assignable, and exist in both structs. Fields which are not assignable, 14 | // or do not exist in both structs are ignored. 15 | func Copy(dst, src interface{}) { 16 | dstval := reflect.ValueOf(dst) 17 | if !dstval.IsValid() { 18 | panic("Copy dst cannot be nil") 19 | } 20 | 21 | rcopy(dstval, reflect.ValueOf(src), true) 22 | } 23 | 24 | // CopyOf returns a copy of src while also allocating the memory for dst. 25 | // src must be a pointer type or this operation will fail. 26 | func CopyOf(src interface{}) (dst interface{}) { 27 | dsti := reflect.New(reflect.TypeOf(src).Elem()) 28 | dst = dsti.Interface() 29 | rcopy(dsti, reflect.ValueOf(src), true) 30 | return 31 | } 32 | 33 | // rcopy performs a recursive copy of values from the source to destination. 34 | // 35 | // root is used to skip certain aspects of the copy which are not valid 36 | // for the root node of a object. 37 | func rcopy(dst, src reflect.Value, root bool) { 38 | if !src.IsValid() { 39 | return 40 | } 41 | 42 | switch src.Kind() { 43 | case reflect.Ptr: 44 | if _, ok := src.Interface().(io.Reader); ok { 45 | if dst.Kind() == reflect.Ptr && dst.Elem().CanSet() { 46 | dst.Elem().Set(src) 47 | } else if dst.CanSet() { 48 | dst.Set(src) 49 | } 50 | } else { 51 | e := src.Type().Elem() 52 | if dst.CanSet() && !src.IsNil() { 53 | if _, ok := src.Interface().(*time.Time); !ok { 54 | dst.Set(reflect.New(e)) 55 | } else { 56 | tempValue := reflect.New(e) 57 | tempValue.Elem().Set(src.Elem()) 58 | // Sets time.Time's unexported values 59 | dst.Set(tempValue) 60 | } 61 | } 62 | if src.Elem().IsValid() { 63 | // Keep the current root state since the depth hasn't changed 64 | rcopy(dst.Elem(), src.Elem(), root) 65 | } 66 | } 67 | case reflect.Struct: 68 | t := dst.Type() 69 | for i := 0; i < t.NumField(); i++ { 70 | name := t.Field(i).Name 71 | srcVal := src.FieldByName(name) 72 | dstVal := dst.FieldByName(name) 73 | if srcVal.IsValid() && dstVal.CanSet() { 74 | rcopy(dstVal, srcVal, false) 75 | } 76 | } 77 | case reflect.Slice: 78 | if src.IsNil() { 79 | break 80 | } 81 | 82 | s := reflect.MakeSlice(src.Type(), src.Len(), src.Cap()) 83 | dst.Set(s) 84 | for i := 0; i < src.Len(); i++ { 85 | rcopy(dst.Index(i), src.Index(i), false) 86 | } 87 | case reflect.Map: 88 | if src.IsNil() { 89 | break 90 | } 91 | 92 | s := reflect.MakeMap(src.Type()) 93 | dst.Set(s) 94 | for _, k := range src.MapKeys() { 95 | v := src.MapIndex(k) 96 | v2 := reflect.New(v.Type()).Elem() 97 | rcopy(v2, v, false) 98 | dst.SetMapIndex(k, v2) 99 | } 100 | default: 101 | // Assign the value if possible. If its not assignable, the value would 102 | // need to be converted and the impact of that may be unexpected, or is 103 | // not compatible with the dst type. 104 | if src.Type().AssignableTo(dst.Type()) { 105 | dst.Set(src) 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/awsutil/equal.go: -------------------------------------------------------------------------------- 1 | package awsutil 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | // DeepEqual returns if the two values are deeply equal like reflect.DeepEqual. 8 | // In addition to this, this method will also dereference the input values if 9 | // possible so the DeepEqual performed will not fail if one parameter is a 10 | // pointer and the other is not. 11 | // 12 | // DeepEqual will not perform indirection of nested values of the input parameters. 13 | func DeepEqual(a, b interface{}) bool { 14 | ra := reflect.Indirect(reflect.ValueOf(a)) 15 | rb := reflect.Indirect(reflect.ValueOf(b)) 16 | 17 | if raValid, rbValid := ra.IsValid(), rb.IsValid(); !raValid && !rbValid { 18 | // If the elements are both nil, and of the same type the are equal 19 | // If they are of different types they are not equal 20 | return reflect.TypeOf(a) == reflect.TypeOf(b) 21 | } else if raValid != rbValid { 22 | // Both values must be valid to be equal 23 | return false 24 | } 25 | 26 | return reflect.DeepEqual(ra.Interface(), rb.Interface()) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/awsutil/prettify.go: -------------------------------------------------------------------------------- 1 | package awsutil 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "reflect" 8 | "strings" 9 | ) 10 | 11 | // Prettify returns the string representation of a value. 12 | func Prettify(i interface{}) string { 13 | var buf bytes.Buffer 14 | prettify(reflect.ValueOf(i), 0, &buf) 15 | return buf.String() 16 | } 17 | 18 | // prettify will recursively walk value v to build a textual 19 | // representation of the value. 20 | func prettify(v reflect.Value, indent int, buf *bytes.Buffer) { 21 | for v.Kind() == reflect.Ptr { 22 | v = v.Elem() 23 | } 24 | 25 | switch v.Kind() { 26 | case reflect.Struct: 27 | strtype := v.Type().String() 28 | if strtype == "time.Time" { 29 | fmt.Fprintf(buf, "%s", v.Interface()) 30 | break 31 | } else if strings.HasPrefix(strtype, "io.") { 32 | buf.WriteString("") 33 | break 34 | } 35 | 36 | buf.WriteString("{\n") 37 | 38 | names := []string{} 39 | for i := 0; i < v.Type().NumField(); i++ { 40 | name := v.Type().Field(i).Name 41 | f := v.Field(i) 42 | if name[0:1] == strings.ToLower(name[0:1]) { 43 | continue // ignore unexported fields 44 | } 45 | if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice || f.Kind() == reflect.Map) && f.IsNil() { 46 | continue // ignore unset fields 47 | } 48 | names = append(names, name) 49 | } 50 | 51 | for i, n := range names { 52 | val := v.FieldByName(n) 53 | buf.WriteString(strings.Repeat(" ", indent+2)) 54 | buf.WriteString(n + ": ") 55 | prettify(val, indent+2, buf) 56 | 57 | if i < len(names)-1 { 58 | buf.WriteString(",\n") 59 | } 60 | } 61 | 62 | buf.WriteString("\n" + strings.Repeat(" ", indent) + "}") 63 | case reflect.Slice: 64 | strtype := v.Type().String() 65 | if strtype == "[]uint8" { 66 | fmt.Fprintf(buf, " len %d", v.Len()) 67 | break 68 | } 69 | 70 | nl, id, id2 := "", "", "" 71 | if v.Len() > 3 { 72 | nl, id, id2 = "\n", strings.Repeat(" ", indent), strings.Repeat(" ", indent+2) 73 | } 74 | buf.WriteString("[" + nl) 75 | for i := 0; i < v.Len(); i++ { 76 | buf.WriteString(id2) 77 | prettify(v.Index(i), indent+2, buf) 78 | 79 | if i < v.Len()-1 { 80 | buf.WriteString("," + nl) 81 | } 82 | } 83 | 84 | buf.WriteString(nl + id + "]") 85 | case reflect.Map: 86 | buf.WriteString("{\n") 87 | 88 | for i, k := range v.MapKeys() { 89 | buf.WriteString(strings.Repeat(" ", indent+2)) 90 | buf.WriteString(k.String() + ": ") 91 | prettify(v.MapIndex(k), indent+2, buf) 92 | 93 | if i < v.Len()-1 { 94 | buf.WriteString(",\n") 95 | } 96 | } 97 | 98 | buf.WriteString("\n" + strings.Repeat(" ", indent) + "}") 99 | default: 100 | if !v.IsValid() { 101 | fmt.Fprint(buf, "") 102 | return 103 | } 104 | format := "%v" 105 | switch v.Interface().(type) { 106 | case string: 107 | format = "%q" 108 | case io.ReadSeeker, io.Reader: 109 | format = "buffer(%p)" 110 | } 111 | fmt.Fprintf(buf, format, v.Interface()) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/awsutil/string_value.go: -------------------------------------------------------------------------------- 1 | package awsutil 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "reflect" 7 | "strings" 8 | ) 9 | 10 | // StringValue returns the string representation of a value. 11 | func StringValue(i interface{}) string { 12 | var buf bytes.Buffer 13 | stringValue(reflect.ValueOf(i), 0, &buf) 14 | return buf.String() 15 | } 16 | 17 | func stringValue(v reflect.Value, indent int, buf *bytes.Buffer) { 18 | for v.Kind() == reflect.Ptr { 19 | v = v.Elem() 20 | } 21 | 22 | switch v.Kind() { 23 | case reflect.Struct: 24 | buf.WriteString("{\n") 25 | 26 | names := []string{} 27 | for i := 0; i < v.Type().NumField(); i++ { 28 | name := v.Type().Field(i).Name 29 | f := v.Field(i) 30 | if name[0:1] == strings.ToLower(name[0:1]) { 31 | continue // ignore unexported fields 32 | } 33 | if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice) && f.IsNil() { 34 | continue // ignore unset fields 35 | } 36 | names = append(names, name) 37 | } 38 | 39 | for i, n := range names { 40 | val := v.FieldByName(n) 41 | buf.WriteString(strings.Repeat(" ", indent+2)) 42 | buf.WriteString(n + ": ") 43 | stringValue(val, indent+2, buf) 44 | 45 | if i < len(names)-1 { 46 | buf.WriteString(",\n") 47 | } 48 | } 49 | 50 | buf.WriteString("\n" + strings.Repeat(" ", indent) + "}") 51 | case reflect.Slice: 52 | nl, id, id2 := "", "", "" 53 | if v.Len() > 3 { 54 | nl, id, id2 = "\n", strings.Repeat(" ", indent), strings.Repeat(" ", indent+2) 55 | } 56 | buf.WriteString("[" + nl) 57 | for i := 0; i < v.Len(); i++ { 58 | buf.WriteString(id2) 59 | stringValue(v.Index(i), indent+2, buf) 60 | 61 | if i < v.Len()-1 { 62 | buf.WriteString("," + nl) 63 | } 64 | } 65 | 66 | buf.WriteString(nl + id + "]") 67 | case reflect.Map: 68 | buf.WriteString("{\n") 69 | 70 | for i, k := range v.MapKeys() { 71 | buf.WriteString(strings.Repeat(" ", indent+2)) 72 | buf.WriteString(k.String() + ": ") 73 | stringValue(v.MapIndex(k), indent+2, buf) 74 | 75 | if i < v.Len()-1 { 76 | buf.WriteString(",\n") 77 | } 78 | } 79 | 80 | buf.WriteString("\n" + strings.Repeat(" ", indent) + "}") 81 | default: 82 | format := "%v" 83 | switch v.Interface().(type) { 84 | case string: 85 | format = "%q" 86 | } 87 | fmt.Fprintf(buf, format, v.Interface()) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/client/client.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/aws/client/metadata" 8 | "github.com/aws/aws-sdk-go/aws/request" 9 | ) 10 | 11 | // A Config provides configuration to a service client instance. 12 | type Config struct { 13 | Config *aws.Config 14 | Handlers request.Handlers 15 | Endpoint string 16 | SigningRegion string 17 | SigningName string 18 | 19 | // States that the signing name did not come from a modeled source but 20 | // was derived based on other data. Used by service client constructors 21 | // to determine if the signin name can be overriden based on metadata the 22 | // service has. 23 | SigningNameDerived bool 24 | } 25 | 26 | // ConfigProvider provides a generic way for a service client to receive 27 | // the ClientConfig without circular dependencies. 28 | type ConfigProvider interface { 29 | ClientConfig(serviceName string, cfgs ...*aws.Config) Config 30 | } 31 | 32 | // ConfigNoResolveEndpointProvider same as ConfigProvider except it will not 33 | // resolve the endpoint automatically. The service client's endpoint must be 34 | // provided via the aws.Config.Endpoint field. 35 | type ConfigNoResolveEndpointProvider interface { 36 | ClientConfigNoResolveEndpoint(cfgs ...*aws.Config) Config 37 | } 38 | 39 | // A Client implements the base client request and response handling 40 | // used by all service clients. 41 | type Client struct { 42 | request.Retryer 43 | metadata.ClientInfo 44 | 45 | Config aws.Config 46 | Handlers request.Handlers 47 | } 48 | 49 | // New will return a pointer to a new initialized service client. 50 | func New(cfg aws.Config, info metadata.ClientInfo, handlers request.Handlers, options ...func(*Client)) *Client { 51 | svc := &Client{ 52 | Config: cfg, 53 | ClientInfo: info, 54 | Handlers: handlers.Copy(), 55 | } 56 | 57 | switch retryer, ok := cfg.Retryer.(request.Retryer); { 58 | case ok: 59 | svc.Retryer = retryer 60 | case cfg.Retryer != nil && cfg.Logger != nil: 61 | s := fmt.Sprintf("WARNING: %T does not implement request.Retryer; using DefaultRetryer instead", cfg.Retryer) 62 | cfg.Logger.Log(s) 63 | fallthrough 64 | default: 65 | maxRetries := aws.IntValue(cfg.MaxRetries) 66 | if cfg.MaxRetries == nil || maxRetries == aws.UseServiceDefaultRetries { 67 | maxRetries = 3 68 | } 69 | svc.Retryer = DefaultRetryer{NumMaxRetries: maxRetries} 70 | } 71 | 72 | svc.AddDebugHandlers() 73 | 74 | for _, option := range options { 75 | option(svc) 76 | } 77 | 78 | return svc 79 | } 80 | 81 | // NewRequest returns a new Request pointer for the service API 82 | // operation and parameters. 83 | func (c *Client) NewRequest(operation *request.Operation, params interface{}, data interface{}) *request.Request { 84 | return request.New(c.Config, c.ClientInfo, c.Handlers, c.Retryer, operation, params, data) 85 | } 86 | 87 | // AddDebugHandlers injects debug logging handlers into the service to log request 88 | // debug information. 89 | func (c *Client) AddDebugHandlers() { 90 | if !c.Config.LogLevel.AtLeast(aws.LogDebug) { 91 | return 92 | } 93 | 94 | c.Handlers.Send.PushFrontNamed(request.NamedHandler{Name: "awssdk.client.LogRequest", Fn: logRequest}) 95 | c.Handlers.Send.PushBackNamed(request.NamedHandler{Name: "awssdk.client.LogResponse", Fn: logResponse}) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/client/default_retryer.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "strconv" 5 | "time" 6 | 7 | "github.com/aws/aws-sdk-go/aws/request" 8 | "github.com/aws/aws-sdk-go/internal/sdkrand" 9 | ) 10 | 11 | // DefaultRetryer implements basic retry logic using exponential backoff for 12 | // most services. If you want to implement custom retry logic, implement the 13 | // request.Retryer interface or create a structure type that composes this 14 | // struct and override the specific methods. For example, to override only 15 | // the MaxRetries method: 16 | // 17 | // type retryer struct { 18 | // client.DefaultRetryer 19 | // } 20 | // 21 | // // This implementation always has 100 max retries 22 | // func (d retryer) MaxRetries() int { return 100 } 23 | type DefaultRetryer struct { 24 | NumMaxRetries int 25 | } 26 | 27 | // MaxRetries returns the number of maximum returns the service will use to make 28 | // an individual API request. 29 | func (d DefaultRetryer) MaxRetries() int { 30 | return d.NumMaxRetries 31 | } 32 | 33 | // RetryRules returns the delay duration before retrying this request again 34 | func (d DefaultRetryer) RetryRules(r *request.Request) time.Duration { 35 | // Set the upper limit of delay in retrying at ~five minutes 36 | minTime := 30 37 | throttle := d.shouldThrottle(r) 38 | if throttle { 39 | if delay, ok := getRetryDelay(r); ok { 40 | return delay 41 | } 42 | 43 | minTime = 500 44 | } 45 | 46 | retryCount := r.RetryCount 47 | if throttle && retryCount > 8 { 48 | retryCount = 8 49 | } else if retryCount > 13 { 50 | retryCount = 13 51 | } 52 | 53 | delay := (1 << uint(retryCount)) * (sdkrand.SeededRand.Intn(minTime) + minTime) 54 | return time.Duration(delay) * time.Millisecond 55 | } 56 | 57 | // ShouldRetry returns true if the request should be retried. 58 | func (d DefaultRetryer) ShouldRetry(r *request.Request) bool { 59 | // If one of the other handlers already set the retry state 60 | // we don't want to override it based on the service's state 61 | if r.Retryable != nil { 62 | return *r.Retryable 63 | } 64 | 65 | if r.HTTPResponse.StatusCode >= 500 && r.HTTPResponse.StatusCode != 501 { 66 | return true 67 | } 68 | return r.IsErrorRetryable() || d.shouldThrottle(r) 69 | } 70 | 71 | // ShouldThrottle returns true if the request should be throttled. 72 | func (d DefaultRetryer) shouldThrottle(r *request.Request) bool { 73 | switch r.HTTPResponse.StatusCode { 74 | case 429: 75 | case 502: 76 | case 503: 77 | case 504: 78 | default: 79 | return r.IsErrorThrottle() 80 | } 81 | 82 | return true 83 | } 84 | 85 | // This will look in the Retry-After header, RFC 7231, for how long 86 | // it will wait before attempting another request 87 | func getRetryDelay(r *request.Request) (time.Duration, bool) { 88 | if !canUseRetryAfterHeader(r) { 89 | return 0, false 90 | } 91 | 92 | delayStr := r.HTTPResponse.Header.Get("Retry-After") 93 | if len(delayStr) == 0 { 94 | return 0, false 95 | } 96 | 97 | delay, err := strconv.Atoi(delayStr) 98 | if err != nil { 99 | return 0, false 100 | } 101 | 102 | return time.Duration(delay) * time.Second, true 103 | } 104 | 105 | // Will look at the status code to see if the retry header pertains to 106 | // the status code. 107 | func canUseRetryAfterHeader(r *request.Request) bool { 108 | switch r.HTTPResponse.StatusCode { 109 | case 429: 110 | case 503: 111 | default: 112 | return false 113 | } 114 | 115 | return true 116 | } 117 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/client/logger.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "io/ioutil" 8 | "net/http/httputil" 9 | 10 | "github.com/aws/aws-sdk-go/aws" 11 | "github.com/aws/aws-sdk-go/aws/request" 12 | ) 13 | 14 | const logReqMsg = `DEBUG: Request %s/%s Details: 15 | ---[ REQUEST POST-SIGN ]----------------------------- 16 | %s 17 | -----------------------------------------------------` 18 | 19 | const logReqErrMsg = `DEBUG ERROR: Request %s/%s: 20 | ---[ REQUEST DUMP ERROR ]----------------------------- 21 | %s 22 | ------------------------------------------------------` 23 | 24 | type logWriter struct { 25 | // Logger is what we will use to log the payload of a response. 26 | Logger aws.Logger 27 | // buf stores the contents of what has been read 28 | buf *bytes.Buffer 29 | } 30 | 31 | func (logger *logWriter) Write(b []byte) (int, error) { 32 | return logger.buf.Write(b) 33 | } 34 | 35 | type teeReaderCloser struct { 36 | // io.Reader will be a tee reader that is used during logging. 37 | // This structure will read from a body and write the contents to a logger. 38 | io.Reader 39 | // Source is used just to close when we are done reading. 40 | Source io.ReadCloser 41 | } 42 | 43 | func (reader *teeReaderCloser) Close() error { 44 | return reader.Source.Close() 45 | } 46 | 47 | func logRequest(r *request.Request) { 48 | logBody := r.Config.LogLevel.Matches(aws.LogDebugWithHTTPBody) 49 | bodySeekable := aws.IsReaderSeekable(r.Body) 50 | dumpedBody, err := httputil.DumpRequestOut(r.HTTPRequest, logBody) 51 | if err != nil { 52 | r.Config.Logger.Log(fmt.Sprintf(logReqErrMsg, r.ClientInfo.ServiceName, r.Operation.Name, err)) 53 | return 54 | } 55 | 56 | if logBody { 57 | if !bodySeekable { 58 | r.SetReaderBody(aws.ReadSeekCloser(r.HTTPRequest.Body)) 59 | } 60 | // Reset the request body because dumpRequest will re-wrap the r.HTTPRequest's 61 | // Body as a NoOpCloser and will not be reset after read by the HTTP 62 | // client reader. 63 | r.ResetBody() 64 | } 65 | 66 | r.Config.Logger.Log(fmt.Sprintf(logReqMsg, r.ClientInfo.ServiceName, r.Operation.Name, string(dumpedBody))) 67 | } 68 | 69 | const logRespMsg = `DEBUG: Response %s/%s Details: 70 | ---[ RESPONSE ]-------------------------------------- 71 | %s 72 | -----------------------------------------------------` 73 | 74 | const logRespErrMsg = `DEBUG ERROR: Response %s/%s: 75 | ---[ RESPONSE DUMP ERROR ]----------------------------- 76 | %s 77 | -----------------------------------------------------` 78 | 79 | func logResponse(r *request.Request) { 80 | lw := &logWriter{r.Config.Logger, bytes.NewBuffer(nil)} 81 | r.HTTPResponse.Body = &teeReaderCloser{ 82 | Reader: io.TeeReader(r.HTTPResponse.Body, lw), 83 | Source: r.HTTPResponse.Body, 84 | } 85 | 86 | handlerFn := func(req *request.Request) { 87 | body, err := httputil.DumpResponse(req.HTTPResponse, false) 88 | if err != nil { 89 | lw.Logger.Log(fmt.Sprintf(logRespErrMsg, req.ClientInfo.ServiceName, req.Operation.Name, err)) 90 | return 91 | } 92 | 93 | b, err := ioutil.ReadAll(lw.buf) 94 | if err != nil { 95 | lw.Logger.Log(fmt.Sprintf(logRespErrMsg, req.ClientInfo.ServiceName, req.Operation.Name, err)) 96 | return 97 | } 98 | lw.Logger.Log(fmt.Sprintf(logRespMsg, req.ClientInfo.ServiceName, req.Operation.Name, string(body))) 99 | if req.Config.LogLevel.Matches(aws.LogDebugWithHTTPBody) { 100 | lw.Logger.Log(string(b)) 101 | } 102 | } 103 | 104 | const handlerName = "awsdk.client.LogResponse.ResponseBody" 105 | 106 | r.Handlers.Unmarshal.SetBackNamed(request.NamedHandler{ 107 | Name: handlerName, Fn: handlerFn, 108 | }) 109 | r.Handlers.UnmarshalError.SetBackNamed(request.NamedHandler{ 110 | Name: handlerName, Fn: handlerFn, 111 | }) 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/client/metadata/client_info.go: -------------------------------------------------------------------------------- 1 | package metadata 2 | 3 | // ClientInfo wraps immutable data from the client.Client structure. 4 | type ClientInfo struct { 5 | ServiceName string 6 | APIVersion string 7 | Endpoint string 8 | SigningName string 9 | SigningRegion string 10 | JSONVersion string 11 | TargetPrefix string 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/context.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // Context is an copy of the Go v1.7 stdlib's context.Context interface. 8 | // It is represented as a SDK interface to enable you to use the "WithContext" 9 | // API methods with Go v1.6 and a Context type such as golang.org/x/net/context. 10 | // 11 | // See https://golang.org/pkg/context on how to use contexts. 12 | type Context interface { 13 | // Deadline returns the time when work done on behalf of this context 14 | // should be canceled. Deadline returns ok==false when no deadline is 15 | // set. Successive calls to Deadline return the same results. 16 | Deadline() (deadline time.Time, ok bool) 17 | 18 | // Done returns a channel that's closed when work done on behalf of this 19 | // context should be canceled. Done may return nil if this context can 20 | // never be canceled. Successive calls to Done return the same value. 21 | Done() <-chan struct{} 22 | 23 | // Err returns a non-nil error value after Done is closed. Err returns 24 | // Canceled if the context was canceled or DeadlineExceeded if the 25 | // context's deadline passed. No other values for Err are defined. 26 | // After Done is closed, successive calls to Err return the same value. 27 | Err() error 28 | 29 | // Value returns the value associated with this context for key, or nil 30 | // if no value is associated with key. Successive calls to Value with 31 | // the same key returns the same result. 32 | // 33 | // Use context values only for request-scoped data that transits 34 | // processes and API boundaries, not for passing optional parameters to 35 | // functions. 36 | Value(key interface{}) interface{} 37 | } 38 | 39 | // BackgroundContext returns a context that will never be canceled, has no 40 | // values, and no deadline. This context is used by the SDK to provide 41 | // backwards compatibility with non-context API operations and functionality. 42 | // 43 | // Go 1.6 and before: 44 | // This context function is equivalent to context.Background in the Go stdlib. 45 | // 46 | // Go 1.7 and later: 47 | // The context returned will be the value returned by context.Background() 48 | // 49 | // See https://golang.org/pkg/context for more information on Contexts. 50 | func BackgroundContext() Context { 51 | return backgroundCtx 52 | } 53 | 54 | // SleepWithContext will wait for the timer duration to expire, or the context 55 | // is canceled. Which ever happens first. If the context is canceled the Context's 56 | // error will be returned. 57 | // 58 | // Expects Context to always return a non-nil error if the Done channel is closed. 59 | func SleepWithContext(ctx Context, dur time.Duration) error { 60 | t := time.NewTimer(dur) 61 | defer t.Stop() 62 | 63 | select { 64 | case <-t.C: 65 | break 66 | case <-ctx.Done(): 67 | return ctx.Err() 68 | } 69 | 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/context_1_6.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package aws 4 | 5 | import "time" 6 | 7 | // An emptyCtx is a copy of the Go 1.7 context.emptyCtx type. This is copied to 8 | // provide a 1.6 and 1.5 safe version of context that is compatible with Go 9 | // 1.7's Context. 10 | // 11 | // An emptyCtx is never canceled, has no values, and has no deadline. It is not 12 | // struct{}, since vars of this type must have distinct addresses. 13 | type emptyCtx int 14 | 15 | func (*emptyCtx) Deadline() (deadline time.Time, ok bool) { 16 | return 17 | } 18 | 19 | func (*emptyCtx) Done() <-chan struct{} { 20 | return nil 21 | } 22 | 23 | func (*emptyCtx) Err() error { 24 | return nil 25 | } 26 | 27 | func (*emptyCtx) Value(key interface{}) interface{} { 28 | return nil 29 | } 30 | 31 | func (e *emptyCtx) String() string { 32 | switch e { 33 | case backgroundCtx: 34 | return "aws.BackgroundContext" 35 | } 36 | return "unknown empty Context" 37 | } 38 | 39 | var ( 40 | backgroundCtx = new(emptyCtx) 41 | ) 42 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/context_1_7.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package aws 4 | 5 | import "context" 6 | 7 | var ( 8 | backgroundCtx = context.Background() 9 | ) 10 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/corehandlers/param_validator.go: -------------------------------------------------------------------------------- 1 | package corehandlers 2 | 3 | import "github.com/aws/aws-sdk-go/aws/request" 4 | 5 | // ValidateParametersHandler is a request handler to validate the input parameters. 6 | // Validating parameters only has meaning if done prior to the request being sent. 7 | var ValidateParametersHandler = request.NamedHandler{Name: "core.ValidateParametersHandler", Fn: func(r *request.Request) { 8 | if !r.ParamsFilled() { 9 | return 10 | } 11 | 12 | if v, ok := r.Params.(request.Validator); ok { 13 | if err := v.Validate(); err != nil { 14 | r.Error = err 15 | } 16 | } 17 | }} 18 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/corehandlers/user_agent.go: -------------------------------------------------------------------------------- 1 | package corehandlers 2 | 3 | import ( 4 | "os" 5 | "runtime" 6 | 7 | "github.com/aws/aws-sdk-go/aws" 8 | "github.com/aws/aws-sdk-go/aws/request" 9 | ) 10 | 11 | // SDKVersionUserAgentHandler is a request handler for adding the SDK Version 12 | // to the user agent. 13 | var SDKVersionUserAgentHandler = request.NamedHandler{ 14 | Name: "core.SDKVersionUserAgentHandler", 15 | Fn: request.MakeAddToUserAgentHandler(aws.SDKName, aws.SDKVersion, 16 | runtime.Version(), runtime.GOOS, runtime.GOARCH), 17 | } 18 | 19 | const execEnvVar = `AWS_EXECUTION_ENV` 20 | const execEnvUAKey = `exec_env` 21 | 22 | // AddHostExecEnvUserAgentHander is a request handler appending the SDK's 23 | // execution environment to the user agent. 24 | // 25 | // If the environment variable AWS_EXECUTION_ENV is set, its value will be 26 | // appended to the user agent string. 27 | var AddHostExecEnvUserAgentHander = request.NamedHandler{ 28 | Name: "core.AddHostExecEnvUserAgentHander", 29 | Fn: func(r *request.Request) { 30 | v := os.Getenv(execEnvVar) 31 | if len(v) == 0 { 32 | return 33 | } 34 | 35 | request.AddToUserAgent(r, execEnvUAKey+"/"+v) 36 | }, 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/credentials/chain_provider.go: -------------------------------------------------------------------------------- 1 | package credentials 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws/awserr" 5 | ) 6 | 7 | var ( 8 | // ErrNoValidProvidersFoundInChain Is returned when there are no valid 9 | // providers in the ChainProvider. 10 | // 11 | // This has been deprecated. For verbose error messaging set 12 | // aws.Config.CredentialsChainVerboseErrors to true 13 | // 14 | // @readonly 15 | ErrNoValidProvidersFoundInChain = awserr.New("NoCredentialProviders", 16 | `no valid providers in chain. Deprecated. 17 | For verbose messaging see aws.Config.CredentialsChainVerboseErrors`, 18 | nil) 19 | ) 20 | 21 | // A ChainProvider will search for a provider which returns credentials 22 | // and cache that provider until Retrieve is called again. 23 | // 24 | // The ChainProvider provides a way of chaining multiple providers together 25 | // which will pick the first available using priority order of the Providers 26 | // in the list. 27 | // 28 | // If none of the Providers retrieve valid credentials Value, ChainProvider's 29 | // Retrieve() will return the error ErrNoValidProvidersFoundInChain. 30 | // 31 | // If a Provider is found which returns valid credentials Value ChainProvider 32 | // will cache that Provider for all calls to IsExpired(), until Retrieve is 33 | // called again. 34 | // 35 | // Example of ChainProvider to be used with an EnvProvider and EC2RoleProvider. 36 | // In this example EnvProvider will first check if any credentials are available 37 | // via the environment variables. If there are none ChainProvider will check 38 | // the next Provider in the list, EC2RoleProvider in this case. If EC2RoleProvider 39 | // does not return any credentials ChainProvider will return the error 40 | // ErrNoValidProvidersFoundInChain 41 | // 42 | // creds := credentials.NewChainCredentials( 43 | // []credentials.Provider{ 44 | // &credentials.EnvProvider{}, 45 | // &ec2rolecreds.EC2RoleProvider{ 46 | // Client: ec2metadata.New(sess), 47 | // }, 48 | // }) 49 | // 50 | // // Usage of ChainCredentials with aws.Config 51 | // svc := ec2.New(session.Must(session.NewSession(&aws.Config{ 52 | // Credentials: creds, 53 | // }))) 54 | // 55 | type ChainProvider struct { 56 | Providers []Provider 57 | curr Provider 58 | VerboseErrors bool 59 | } 60 | 61 | // NewChainCredentials returns a pointer to a new Credentials object 62 | // wrapping a chain of providers. 63 | func NewChainCredentials(providers []Provider) *Credentials { 64 | return NewCredentials(&ChainProvider{ 65 | Providers: append([]Provider{}, providers...), 66 | }) 67 | } 68 | 69 | // Retrieve returns the credentials value or error if no provider returned 70 | // without error. 71 | // 72 | // If a provider is found it will be cached and any calls to IsExpired() 73 | // will return the expired state of the cached provider. 74 | func (c *ChainProvider) Retrieve() (Value, error) { 75 | var errs []error 76 | for _, p := range c.Providers { 77 | creds, err := p.Retrieve() 78 | if err == nil { 79 | c.curr = p 80 | return creds, nil 81 | } 82 | errs = append(errs, err) 83 | } 84 | c.curr = nil 85 | 86 | var err error 87 | err = ErrNoValidProvidersFoundInChain 88 | if c.VerboseErrors { 89 | err = awserr.NewBatchError("NoCredentialProviders", "no valid providers in chain", errs) 90 | } 91 | return Value{}, err 92 | } 93 | 94 | // IsExpired will returned the expired state of the currently cached provider 95 | // if there is one. If there is no current provider, true will be returned. 96 | func (c *ChainProvider) IsExpired() bool { 97 | if c.curr != nil { 98 | return c.curr.IsExpired() 99 | } 100 | 101 | return true 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/credentials/env_provider.go: -------------------------------------------------------------------------------- 1 | package credentials 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/aws/aws-sdk-go/aws/awserr" 7 | ) 8 | 9 | // EnvProviderName provides a name of Env provider 10 | const EnvProviderName = "EnvProvider" 11 | 12 | var ( 13 | // ErrAccessKeyIDNotFound is returned when the AWS Access Key ID can't be 14 | // found in the process's environment. 15 | // 16 | // @readonly 17 | ErrAccessKeyIDNotFound = awserr.New("EnvAccessKeyNotFound", "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment", nil) 18 | 19 | // ErrSecretAccessKeyNotFound is returned when the AWS Secret Access Key 20 | // can't be found in the process's environment. 21 | // 22 | // @readonly 23 | ErrSecretAccessKeyNotFound = awserr.New("EnvSecretNotFound", "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment", nil) 24 | ) 25 | 26 | // A EnvProvider retrieves credentials from the environment variables of the 27 | // running process. Environment credentials never expire. 28 | // 29 | // Environment variables used: 30 | // 31 | // * Access Key ID: AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY 32 | // 33 | // * Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY 34 | type EnvProvider struct { 35 | retrieved bool 36 | } 37 | 38 | // NewEnvCredentials returns a pointer to a new Credentials object 39 | // wrapping the environment variable provider. 40 | func NewEnvCredentials() *Credentials { 41 | return NewCredentials(&EnvProvider{}) 42 | } 43 | 44 | // Retrieve retrieves the keys from the environment. 45 | func (e *EnvProvider) Retrieve() (Value, error) { 46 | e.retrieved = false 47 | 48 | id := os.Getenv("AWS_ACCESS_KEY_ID") 49 | if id == "" { 50 | id = os.Getenv("AWS_ACCESS_KEY") 51 | } 52 | 53 | secret := os.Getenv("AWS_SECRET_ACCESS_KEY") 54 | if secret == "" { 55 | secret = os.Getenv("AWS_SECRET_KEY") 56 | } 57 | 58 | if id == "" { 59 | return Value{ProviderName: EnvProviderName}, ErrAccessKeyIDNotFound 60 | } 61 | 62 | if secret == "" { 63 | return Value{ProviderName: EnvProviderName}, ErrSecretAccessKeyNotFound 64 | } 65 | 66 | e.retrieved = true 67 | return Value{ 68 | AccessKeyID: id, 69 | SecretAccessKey: secret, 70 | SessionToken: os.Getenv("AWS_SESSION_TOKEN"), 71 | ProviderName: EnvProviderName, 72 | }, nil 73 | } 74 | 75 | // IsExpired returns if the credentials have been retrieved. 76 | func (e *EnvProvider) IsExpired() bool { 77 | return !e.retrieved 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/credentials/example.ini: -------------------------------------------------------------------------------- 1 | [default] 2 | aws_access_key_id = accessKey 3 | aws_secret_access_key = secret 4 | aws_session_token = token 5 | 6 | [no_token] 7 | aws_access_key_id = accessKey 8 | aws_secret_access_key = secret 9 | 10 | [with_colon] 11 | aws_access_key_id: accessKey 12 | aws_secret_access_key: secret 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go: -------------------------------------------------------------------------------- 1 | package credentials 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws/awserr" 5 | ) 6 | 7 | // StaticProviderName provides a name of Static provider 8 | const StaticProviderName = "StaticProvider" 9 | 10 | var ( 11 | // ErrStaticCredentialsEmpty is emitted when static credentials are empty. 12 | // 13 | // @readonly 14 | ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil) 15 | ) 16 | 17 | // A StaticProvider is a set of credentials which are set programmatically, 18 | // and will never expire. 19 | type StaticProvider struct { 20 | Value 21 | } 22 | 23 | // NewStaticCredentials returns a pointer to a new Credentials object 24 | // wrapping a static credentials value provider. 25 | func NewStaticCredentials(id, secret, token string) *Credentials { 26 | return NewCredentials(&StaticProvider{Value: Value{ 27 | AccessKeyID: id, 28 | SecretAccessKey: secret, 29 | SessionToken: token, 30 | }}) 31 | } 32 | 33 | // NewStaticCredentialsFromCreds returns a pointer to a new Credentials object 34 | // wrapping the static credentials value provide. Same as NewStaticCredentials 35 | // but takes the creds Value instead of individual fields 36 | func NewStaticCredentialsFromCreds(creds Value) *Credentials { 37 | return NewCredentials(&StaticProvider{Value: creds}) 38 | } 39 | 40 | // Retrieve returns the credentials or error if the credentials are invalid. 41 | func (s *StaticProvider) Retrieve() (Value, error) { 42 | if s.AccessKeyID == "" || s.SecretAccessKey == "" { 43 | return Value{ProviderName: StaticProviderName}, ErrStaticCredentialsEmpty 44 | } 45 | 46 | if len(s.Value.ProviderName) == 0 { 47 | s.Value.ProviderName = StaticProviderName 48 | } 49 | return s.Value, nil 50 | } 51 | 52 | // IsExpired returns if the credentials are expired. 53 | // 54 | // For StaticProvider, the credentials never expired. 55 | func (s *StaticProvider) IsExpired() bool { 56 | return false 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/defaults/shared_config.go: -------------------------------------------------------------------------------- 1 | package defaults 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/internal/shareddefaults" 5 | ) 6 | 7 | // SharedCredentialsFilename returns the SDK's default file path 8 | // for the shared credentials file. 9 | // 10 | // Builds the shared config file path based on the OS's platform. 11 | // 12 | // - Linux/Unix: $HOME/.aws/credentials 13 | // - Windows: %USERPROFILE%\.aws\credentials 14 | func SharedCredentialsFilename() string { 15 | return shareddefaults.SharedCredentialsFilename() 16 | } 17 | 18 | // SharedConfigFilename returns the SDK's default file path for 19 | // the shared config file. 20 | // 21 | // Builds the shared config file path based on the OS's platform. 22 | // 23 | // - Linux/Unix: $HOME/.aws/config 24 | // - Windows: %USERPROFILE%\.aws\config 25 | func SharedConfigFilename() string { 26 | return shareddefaults.SharedConfigFilename() 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/doc.go: -------------------------------------------------------------------------------- 1 | // Package aws provides the core SDK's utilities and shared types. Use this package's 2 | // utilities to simplify setting and reading API operations parameters. 3 | // 4 | // Value and Pointer Conversion Utilities 5 | // 6 | // This package includes a helper conversion utility for each scalar type the SDK's 7 | // API use. These utilities make getting a pointer of the scalar, and dereferencing 8 | // a pointer easier. 9 | // 10 | // Each conversion utility comes in two forms. Value to Pointer and Pointer to Value. 11 | // The Pointer to value will safely dereference the pointer and return its value. 12 | // If the pointer was nil, the scalar's zero value will be returned. 13 | // 14 | // The value to pointer functions will be named after the scalar type. So get a 15 | // *string from a string value use the "String" function. This makes it easy to 16 | // to get pointer of a literal string value, because getting the address of a 17 | // literal requires assigning the value to a variable first. 18 | // 19 | // var strPtr *string 20 | // 21 | // // Without the SDK's conversion functions 22 | // str := "my string" 23 | // strPtr = &str 24 | // 25 | // // With the SDK's conversion functions 26 | // strPtr = aws.String("my string") 27 | // 28 | // // Convert *string to string value 29 | // str = aws.StringValue(strPtr) 30 | // 31 | // In addition to scalars the aws package also includes conversion utilities for 32 | // map and slice for commonly types used in API parameters. The map and slice 33 | // conversion functions use similar naming pattern as the scalar conversion 34 | // functions. 35 | // 36 | // var strPtrs []*string 37 | // var strs []string = []string{"Go", "Gophers", "Go"} 38 | // 39 | // // Convert []string to []*string 40 | // strPtrs = aws.StringSlice(strs) 41 | // 42 | // // Convert []*string to []string 43 | // strs = aws.StringValueSlice(strPtrs) 44 | // 45 | // SDK Default HTTP Client 46 | // 47 | // The SDK will use the http.DefaultClient if a HTTP client is not provided to 48 | // the SDK's Session, or service client constructor. This means that if the 49 | // http.DefaultClient is modified by other components of your application the 50 | // modifications will be picked up by the SDK as well. 51 | // 52 | // In some cases this might be intended, but it is a better practice to create 53 | // a custom HTTP Client to share explicitly through your application. You can 54 | // configure the SDK to use the custom HTTP Client by setting the HTTPClient 55 | // value of the SDK's Config type when creating a Session or service client. 56 | package aws 57 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/endpoints/decode.go: -------------------------------------------------------------------------------- 1 | package endpoints 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io" 7 | 8 | "github.com/aws/aws-sdk-go/aws/awserr" 9 | ) 10 | 11 | type modelDefinition map[string]json.RawMessage 12 | 13 | // A DecodeModelOptions are the options for how the endpoints model definition 14 | // are decoded. 15 | type DecodeModelOptions struct { 16 | SkipCustomizations bool 17 | } 18 | 19 | // Set combines all of the option functions together. 20 | func (d *DecodeModelOptions) Set(optFns ...func(*DecodeModelOptions)) { 21 | for _, fn := range optFns { 22 | fn(d) 23 | } 24 | } 25 | 26 | // DecodeModel unmarshals a Regions and Endpoint model definition file into 27 | // a endpoint Resolver. If the file format is not supported, or an error occurs 28 | // when unmarshaling the model an error will be returned. 29 | // 30 | // Casting the return value of this func to a EnumPartitions will 31 | // allow you to get a list of the partitions in the order the endpoints 32 | // will be resolved in. 33 | // 34 | // resolver, err := endpoints.DecodeModel(reader) 35 | // 36 | // partitions := resolver.(endpoints.EnumPartitions).Partitions() 37 | // for _, p := range partitions { 38 | // // ... inspect partitions 39 | // } 40 | func DecodeModel(r io.Reader, optFns ...func(*DecodeModelOptions)) (Resolver, error) { 41 | var opts DecodeModelOptions 42 | opts.Set(optFns...) 43 | 44 | // Get the version of the partition file to determine what 45 | // unmarshaling model to use. 46 | modelDef := modelDefinition{} 47 | if err := json.NewDecoder(r).Decode(&modelDef); err != nil { 48 | return nil, newDecodeModelError("failed to decode endpoints model", err) 49 | } 50 | 51 | var version string 52 | if b, ok := modelDef["version"]; ok { 53 | version = string(b) 54 | } else { 55 | return nil, newDecodeModelError("endpoints version not found in model", nil) 56 | } 57 | 58 | if version == "3" { 59 | return decodeV3Endpoints(modelDef, opts) 60 | } 61 | 62 | return nil, newDecodeModelError( 63 | fmt.Sprintf("endpoints version %s, not supported", version), nil) 64 | } 65 | 66 | func decodeV3Endpoints(modelDef modelDefinition, opts DecodeModelOptions) (Resolver, error) { 67 | b, ok := modelDef["partitions"] 68 | if !ok { 69 | return nil, newDecodeModelError("endpoints model missing partitions", nil) 70 | } 71 | 72 | ps := partitions{} 73 | if err := json.Unmarshal(b, &ps); err != nil { 74 | return nil, newDecodeModelError("failed to decode endpoints model", err) 75 | } 76 | 77 | if opts.SkipCustomizations { 78 | return ps, nil 79 | } 80 | 81 | // Customization 82 | for i := 0; i < len(ps); i++ { 83 | p := &ps[i] 84 | custAddEC2Metadata(p) 85 | custAddS3DualStack(p) 86 | custRmIotDataService(p) 87 | } 88 | 89 | return ps, nil 90 | } 91 | 92 | func custAddS3DualStack(p *partition) { 93 | if p.ID != "aws" { 94 | return 95 | } 96 | 97 | s, ok := p.Services["s3"] 98 | if !ok { 99 | return 100 | } 101 | 102 | s.Defaults.HasDualStack = boxedTrue 103 | s.Defaults.DualStackHostname = "{service}.dualstack.{region}.{dnsSuffix}" 104 | 105 | p.Services["s3"] = s 106 | } 107 | 108 | func custAddEC2Metadata(p *partition) { 109 | p.Services["ec2metadata"] = service{ 110 | IsRegionalized: boxedFalse, 111 | PartitionEndpoint: "aws-global", 112 | Endpoints: endpoints{ 113 | "aws-global": endpoint{ 114 | Hostname: "169.254.169.254/latest", 115 | Protocols: []string{"http"}, 116 | }, 117 | }, 118 | } 119 | } 120 | 121 | func custRmIotDataService(p *partition) { 122 | delete(p.Services, "data.iot") 123 | } 124 | 125 | type decodeModelError struct { 126 | awsError 127 | } 128 | 129 | func newDecodeModelError(msg string, err error) decodeModelError { 130 | return decodeModelError{ 131 | awsError: awserr.New("DecodeEndpointsModelError", msg, err), 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/endpoints/doc.go: -------------------------------------------------------------------------------- 1 | // Package endpoints provides the types and functionality for defining regions 2 | // and endpoints, as well as querying those definitions. 3 | // 4 | // The SDK's Regions and Endpoints metadata is code generated into the endpoints 5 | // package, and is accessible via the DefaultResolver function. This function 6 | // returns a endpoint Resolver will search the metadata and build an associated 7 | // endpoint if one is found. The default resolver will search all partitions 8 | // known by the SDK. e.g AWS Standard (aws), AWS China (aws-cn), and 9 | // AWS GovCloud (US) (aws-us-gov). 10 | // . 11 | // 12 | // Enumerating Regions and Endpoint Metadata 13 | // 14 | // Casting the Resolver returned by DefaultResolver to a EnumPartitions interface 15 | // will allow you to get access to the list of underlying Partitions with the 16 | // Partitions method. This is helpful if you want to limit the SDK's endpoint 17 | // resolving to a single partition, or enumerate regions, services, and endpoints 18 | // in the partition. 19 | // 20 | // resolver := endpoints.DefaultResolver() 21 | // partitions := resolver.(endpoints.EnumPartitions).Partitions() 22 | // 23 | // for _, p := range partitions { 24 | // fmt.Println("Regions for", p.ID()) 25 | // for id, _ := range p.Regions() { 26 | // fmt.Println("*", id) 27 | // } 28 | // 29 | // fmt.Println("Services for", p.ID()) 30 | // for id, _ := range p.Services() { 31 | // fmt.Println("*", id) 32 | // } 33 | // } 34 | // 35 | // Using Custom Endpoints 36 | // 37 | // The endpoints package also gives you the ability to use your own logic how 38 | // endpoints are resolved. This is a great way to define a custom endpoint 39 | // for select services, without passing that logic down through your code. 40 | // 41 | // If a type implements the Resolver interface it can be used to resolve 42 | // endpoints. To use this with the SDK's Session and Config set the value 43 | // of the type to the EndpointsResolver field of aws.Config when initializing 44 | // the session, or service client. 45 | // 46 | // In addition the ResolverFunc is a wrapper for a func matching the signature 47 | // of Resolver.EndpointFor, converting it to a type that satisfies the 48 | // Resolver interface. 49 | // 50 | // 51 | // myCustomResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { 52 | // if service == endpoints.S3ServiceID { 53 | // return endpoints.ResolvedEndpoint{ 54 | // URL: "s3.custom.endpoint.com", 55 | // SigningRegion: "custom-signing-region", 56 | // }, nil 57 | // } 58 | // 59 | // return endpoints.DefaultResolver().EndpointFor(service, region, optFns...) 60 | // } 61 | // 62 | // sess := session.Must(session.NewSession(&aws.Config{ 63 | // Region: aws.String("us-west-2"), 64 | // EndpointResolver: endpoints.ResolverFunc(myCustomResolver), 65 | // })) 66 | package endpoints 67 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/errors.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import "github.com/aws/aws-sdk-go/aws/awserr" 4 | 5 | var ( 6 | // ErrMissingRegion is an error that is returned if region configuration is 7 | // not found. 8 | // 9 | // @readonly 10 | ErrMissingRegion = awserr.New("MissingRegion", "could not find region configuration", nil) 11 | 12 | // ErrMissingEndpoint is an error that is returned if an endpoint cannot be 13 | // resolved for a service. 14 | // 15 | // @readonly 16 | ErrMissingEndpoint = awserr.New("MissingEndpoint", "'Endpoint' configuration is required for this service", nil) 17 | ) 18 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/jsonvalue.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | // JSONValue is a representation of a grab bag type that will be marshaled 4 | // into a json string. This type can be used just like any other map. 5 | // 6 | // Example: 7 | // 8 | // values := aws.JSONValue{ 9 | // "Foo": "Bar", 10 | // } 11 | // values["Baz"] = "Qux" 12 | type JSONValue map[string]interface{} 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/logger.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | // A LogLevelType defines the level logging should be performed at. Used to instruct 9 | // the SDK which statements should be logged. 10 | type LogLevelType uint 11 | 12 | // LogLevel returns the pointer to a LogLevel. Should be used to workaround 13 | // not being able to take the address of a non-composite literal. 14 | func LogLevel(l LogLevelType) *LogLevelType { 15 | return &l 16 | } 17 | 18 | // Value returns the LogLevel value or the default value LogOff if the LogLevel 19 | // is nil. Safe to use on nil value LogLevelTypes. 20 | func (l *LogLevelType) Value() LogLevelType { 21 | if l != nil { 22 | return *l 23 | } 24 | return LogOff 25 | } 26 | 27 | // Matches returns true if the v LogLevel is enabled by this LogLevel. Should be 28 | // used with logging sub levels. Is safe to use on nil value LogLevelTypes. If 29 | // LogLevel is nil, will default to LogOff comparison. 30 | func (l *LogLevelType) Matches(v LogLevelType) bool { 31 | c := l.Value() 32 | return c&v == v 33 | } 34 | 35 | // AtLeast returns true if this LogLevel is at least high enough to satisfies v. 36 | // Is safe to use on nil value LogLevelTypes. If LogLevel is nil, will default 37 | // to LogOff comparison. 38 | func (l *LogLevelType) AtLeast(v LogLevelType) bool { 39 | c := l.Value() 40 | return c >= v 41 | } 42 | 43 | const ( 44 | // LogOff states that no logging should be performed by the SDK. This is the 45 | // default state of the SDK, and should be use to disable all logging. 46 | LogOff LogLevelType = iota * 0x1000 47 | 48 | // LogDebug state that debug output should be logged by the SDK. This should 49 | // be used to inspect request made and responses received. 50 | LogDebug 51 | ) 52 | 53 | // Debug Logging Sub Levels 54 | const ( 55 | // LogDebugWithSigning states that the SDK should log request signing and 56 | // presigning events. This should be used to log the signing details of 57 | // requests for debugging. Will also enable LogDebug. 58 | LogDebugWithSigning LogLevelType = LogDebug | (1 << iota) 59 | 60 | // LogDebugWithHTTPBody states the SDK should log HTTP request and response 61 | // HTTP bodys in addition to the headers and path. This should be used to 62 | // see the body content of requests and responses made while using the SDK 63 | // Will also enable LogDebug. 64 | LogDebugWithHTTPBody 65 | 66 | // LogDebugWithRequestRetries states the SDK should log when service requests will 67 | // be retried. This should be used to log when you want to log when service 68 | // requests are being retried. Will also enable LogDebug. 69 | LogDebugWithRequestRetries 70 | 71 | // LogDebugWithRequestErrors states the SDK should log when service requests fail 72 | // to build, send, validate, or unmarshal. 73 | LogDebugWithRequestErrors 74 | ) 75 | 76 | // A Logger is a minimalistic interface for the SDK to log messages to. Should 77 | // be used to provide custom logging writers for the SDK to use. 78 | type Logger interface { 79 | Log(...interface{}) 80 | } 81 | 82 | // A LoggerFunc is a convenience type to convert a function taking a variadic 83 | // list of arguments and wrap it so the Logger interface can be used. 84 | // 85 | // Example: 86 | // s3.New(sess, &aws.Config{Logger: aws.LoggerFunc(func(args ...interface{}) { 87 | // fmt.Fprintln(os.Stdout, args...) 88 | // })}) 89 | type LoggerFunc func(...interface{}) 90 | 91 | // Log calls the wrapped function with the arguments provided 92 | func (f LoggerFunc) Log(args ...interface{}) { 93 | f(args...) 94 | } 95 | 96 | // NewDefaultLogger returns a Logger which will write log messages to stdout, and 97 | // use same formatting runes as the stdlib log.Logger 98 | func NewDefaultLogger() Logger { 99 | return &defaultLogger{ 100 | logger: log.New(os.Stdout, "", log.LstdFlags), 101 | } 102 | } 103 | 104 | // A defaultLogger provides a minimalistic logger satisfying the Logger interface. 105 | type defaultLogger struct { 106 | logger *log.Logger 107 | } 108 | 109 | // Log logs the parameters to the stdlib logger. See log.Println. 110 | func (l defaultLogger) Log(args ...interface{}) { 111 | l.logger.Println(args...) 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/connection_reset_error.go: -------------------------------------------------------------------------------- 1 | // +build !appengine,!plan9 2 | 3 | package request 4 | 5 | import ( 6 | "net" 7 | "os" 8 | "syscall" 9 | ) 10 | 11 | func isErrConnectionReset(err error) bool { 12 | if opErr, ok := err.(*net.OpError); ok { 13 | if sysErr, ok := opErr.Err.(*os.SyscallError); ok { 14 | return sysErr.Err == syscall.ECONNRESET 15 | } 16 | } 17 | 18 | return false 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/connection_reset_error_other.go: -------------------------------------------------------------------------------- 1 | // +build appengine plan9 2 | 3 | package request 4 | 5 | import ( 6 | "strings" 7 | ) 8 | 9 | func isErrConnectionReset(err error) bool { 10 | return strings.Contains(err.Error(), "connection reset") 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/http_request.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "net/url" 7 | ) 8 | 9 | func copyHTTPRequest(r *http.Request, body io.ReadCloser) *http.Request { 10 | req := new(http.Request) 11 | *req = *r 12 | req.URL = &url.URL{} 13 | *req.URL = *r.URL 14 | req.Body = body 15 | 16 | req.Header = http.Header{} 17 | for k, v := range r.Header { 18 | for _, vv := range v { 19 | req.Header.Add(k, vv) 20 | } 21 | } 22 | 23 | return req 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/offset_reader.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | import ( 4 | "io" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go/internal/sdkio" 8 | ) 9 | 10 | // offsetReader is a thread-safe io.ReadCloser to prevent racing 11 | // with retrying requests 12 | type offsetReader struct { 13 | buf io.ReadSeeker 14 | lock sync.Mutex 15 | closed bool 16 | } 17 | 18 | func newOffsetReader(buf io.ReadSeeker, offset int64) *offsetReader { 19 | reader := &offsetReader{} 20 | buf.Seek(offset, sdkio.SeekStart) 21 | 22 | reader.buf = buf 23 | return reader 24 | } 25 | 26 | // Close will close the instance of the offset reader's access to 27 | // the underlying io.ReadSeeker. 28 | func (o *offsetReader) Close() error { 29 | o.lock.Lock() 30 | defer o.lock.Unlock() 31 | o.closed = true 32 | return nil 33 | } 34 | 35 | // Read is a thread-safe read of the underlying io.ReadSeeker 36 | func (o *offsetReader) Read(p []byte) (int, error) { 37 | o.lock.Lock() 38 | defer o.lock.Unlock() 39 | 40 | if o.closed { 41 | return 0, io.EOF 42 | } 43 | 44 | return o.buf.Read(p) 45 | } 46 | 47 | // Seek is a thread-safe seeking operation. 48 | func (o *offsetReader) Seek(offset int64, whence int) (int64, error) { 49 | o.lock.Lock() 50 | defer o.lock.Unlock() 51 | 52 | return o.buf.Seek(offset, whence) 53 | } 54 | 55 | // CloseAndCopy will return a new offsetReader with a copy of the old buffer 56 | // and close the old buffer. 57 | func (o *offsetReader) CloseAndCopy(offset int64) *offsetReader { 58 | o.Close() 59 | return newOffsetReader(o.buf, offset) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/request_1_7.go: -------------------------------------------------------------------------------- 1 | // +build !go1.8 2 | 3 | package request 4 | 5 | import "io" 6 | 7 | // NoBody is an io.ReadCloser with no bytes. Read always returns EOF 8 | // and Close always returns nil. It can be used in an outgoing client 9 | // request to explicitly signal that a request has zero bytes. 10 | // An alternative, however, is to simply set Request.Body to nil. 11 | // 12 | // Copy of Go 1.8 NoBody type from net/http/http.go 13 | type noBody struct{} 14 | 15 | func (noBody) Read([]byte) (int, error) { return 0, io.EOF } 16 | func (noBody) Close() error { return nil } 17 | func (noBody) WriteTo(io.Writer) (int64, error) { return 0, nil } 18 | 19 | // NoBody is an empty reader that will trigger the Go HTTP client to not include 20 | // and body in the HTTP request. 21 | var NoBody = noBody{} 22 | 23 | // ResetBody rewinds the request body back to its starting position, and 24 | // set's the HTTP Request body reference. When the body is read prior 25 | // to being sent in the HTTP request it will need to be rewound. 26 | // 27 | // ResetBody will automatically be called by the SDK's build handler, but if 28 | // the request is being used directly ResetBody must be called before the request 29 | // is Sent. SetStringBody, SetBufferBody, and SetReaderBody will automatically 30 | // call ResetBody. 31 | func (r *Request) ResetBody() { 32 | body, err := r.getNextRequestBody() 33 | if err != nil { 34 | r.Error = err 35 | return 36 | } 37 | 38 | r.HTTPRequest.Body = body 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/request_1_8.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | package request 4 | 5 | import ( 6 | "net/http" 7 | ) 8 | 9 | // NoBody is a http.NoBody reader instructing Go HTTP client to not include 10 | // and body in the HTTP request. 11 | var NoBody = http.NoBody 12 | 13 | // ResetBody rewinds the request body back to its starting position, and 14 | // set's the HTTP Request body reference. When the body is read prior 15 | // to being sent in the HTTP request it will need to be rewound. 16 | // 17 | // ResetBody will automatically be called by the SDK's build handler, but if 18 | // the request is being used directly ResetBody must be called before the request 19 | // is Sent. SetStringBody, SetBufferBody, and SetReaderBody will automatically 20 | // call ResetBody. 21 | // 22 | // Will also set the Go 1.8's http.Request.GetBody member to allow retrying 23 | // PUT/POST redirects. 24 | func (r *Request) ResetBody() { 25 | body, err := r.getNextRequestBody() 26 | if err != nil { 27 | r.Error = err 28 | return 29 | } 30 | 31 | r.HTTPRequest.Body = body 32 | r.HTTPRequest.GetBody = r.getNextRequestBody 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/request_context.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package request 4 | 5 | import "github.com/aws/aws-sdk-go/aws" 6 | 7 | // setContext updates the Request to use the passed in context for cancellation. 8 | // Context will also be used for request retry delay. 9 | // 10 | // Creates shallow copy of the http.Request with the WithContext method. 11 | func setRequestContext(r *Request, ctx aws.Context) { 12 | r.context = ctx 13 | r.HTTPRequest = r.HTTPRequest.WithContext(ctx) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/request_context_1_6.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package request 4 | 5 | import "github.com/aws/aws-sdk-go/aws" 6 | 7 | // setContext updates the Request to use the passed in context for cancellation. 8 | // Context will also be used for request retry delay. 9 | // 10 | // Creates shallow copy of the http.Request with the WithContext method. 11 | func setRequestContext(r *Request, ctx aws.Context) { 12 | r.context = ctx 13 | r.HTTPRequest.Cancel = ctx.Done() 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/request/timeout_read_closer.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | import ( 4 | "io" 5 | "time" 6 | 7 | "github.com/aws/aws-sdk-go/aws/awserr" 8 | ) 9 | 10 | var timeoutErr = awserr.New( 11 | ErrCodeResponseTimeout, 12 | "read on body has reached the timeout limit", 13 | nil, 14 | ) 15 | 16 | type readResult struct { 17 | n int 18 | err error 19 | } 20 | 21 | // timeoutReadCloser will handle body reads that take too long. 22 | // We will return a ErrReadTimeout error if a timeout occurs. 23 | type timeoutReadCloser struct { 24 | reader io.ReadCloser 25 | duration time.Duration 26 | } 27 | 28 | // Read will spin off a goroutine to call the reader's Read method. We will 29 | // select on the timer's channel or the read's channel. Whoever completes first 30 | // will be returned. 31 | func (r *timeoutReadCloser) Read(b []byte) (int, error) { 32 | timer := time.NewTimer(r.duration) 33 | c := make(chan readResult, 1) 34 | 35 | go func() { 36 | n, err := r.reader.Read(b) 37 | timer.Stop() 38 | c <- readResult{n: n, err: err} 39 | }() 40 | 41 | select { 42 | case data := <-c: 43 | return data.n, data.err 44 | case <-timer.C: 45 | return 0, timeoutErr 46 | } 47 | } 48 | 49 | func (r *timeoutReadCloser) Close() error { 50 | return r.reader.Close() 51 | } 52 | 53 | const ( 54 | // HandlerResponseTimeout is what we use to signify the name of the 55 | // response timeout handler. 56 | HandlerResponseTimeout = "ResponseTimeoutHandler" 57 | ) 58 | 59 | // adaptToResponseTimeoutError is a handler that will replace any top level error 60 | // to a ErrCodeResponseTimeout, if its child is that. 61 | func adaptToResponseTimeoutError(req *Request) { 62 | if err, ok := req.Error.(awserr.Error); ok { 63 | aerr, ok := err.OrigErr().(awserr.Error) 64 | if ok && aerr.Code() == ErrCodeResponseTimeout { 65 | req.Error = aerr 66 | } 67 | } 68 | } 69 | 70 | // WithResponseReadTimeout is a request option that will wrap the body in a timeout read closer. 71 | // This will allow for per read timeouts. If a timeout occurred, we will return the 72 | // ErrCodeResponseTimeout. 73 | // 74 | // svc.PutObjectWithContext(ctx, params, request.WithTimeoutReadCloser(30 * time.Second) 75 | func WithResponseReadTimeout(duration time.Duration) Option { 76 | return func(r *Request) { 77 | 78 | var timeoutHandler = NamedHandler{ 79 | HandlerResponseTimeout, 80 | func(req *Request) { 81 | req.HTTPResponse.Body = &timeoutReadCloser{ 82 | reader: req.HTTPResponse.Body, 83 | duration: duration, 84 | } 85 | }} 86 | 87 | // remove the handler so we are not stomping over any new durations. 88 | r.Handlers.Send.RemoveByName(HandlerResponseTimeout) 89 | r.Handlers.Send.PushBackNamed(timeoutHandler) 90 | 91 | r.Handlers.Unmarshal.PushBack(adaptToResponseTimeoutError) 92 | r.Handlers.UnmarshalError.PushBack(adaptToResponseTimeoutError) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/signer/v4/header_rules.go: -------------------------------------------------------------------------------- 1 | package v4 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | ) 7 | 8 | // validator houses a set of rule needed for validation of a 9 | // string value 10 | type rules []rule 11 | 12 | // rule interface allows for more flexible rules and just simply 13 | // checks whether or not a value adheres to that rule 14 | type rule interface { 15 | IsValid(value string) bool 16 | } 17 | 18 | // IsValid will iterate through all rules and see if any rules 19 | // apply to the value and supports nested rules 20 | func (r rules) IsValid(value string) bool { 21 | for _, rule := range r { 22 | if rule.IsValid(value) { 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | 29 | // mapRule generic rule for maps 30 | type mapRule map[string]struct{} 31 | 32 | // IsValid for the map rule satisfies whether it exists in the map 33 | func (m mapRule) IsValid(value string) bool { 34 | _, ok := m[value] 35 | return ok 36 | } 37 | 38 | // whitelist is a generic rule for whitelisting 39 | type whitelist struct { 40 | rule 41 | } 42 | 43 | // IsValid for whitelist checks if the value is within the whitelist 44 | func (w whitelist) IsValid(value string) bool { 45 | return w.rule.IsValid(value) 46 | } 47 | 48 | // blacklist is a generic rule for blacklisting 49 | type blacklist struct { 50 | rule 51 | } 52 | 53 | // IsValid for whitelist checks if the value is within the whitelist 54 | func (b blacklist) IsValid(value string) bool { 55 | return !b.rule.IsValid(value) 56 | } 57 | 58 | type patterns []string 59 | 60 | // IsValid for patterns checks each pattern and returns if a match has 61 | // been found 62 | func (p patterns) IsValid(value string) bool { 63 | for _, pattern := range p { 64 | if strings.HasPrefix(http.CanonicalHeaderKey(value), pattern) { 65 | return true 66 | } 67 | } 68 | return false 69 | } 70 | 71 | // inclusiveRules rules allow for rules to depend on one another 72 | type inclusiveRules []rule 73 | 74 | // IsValid will return true if all rules are true 75 | func (r inclusiveRules) IsValid(value string) bool { 76 | for _, rule := range r { 77 | if !rule.IsValid(value) { 78 | return false 79 | } 80 | } 81 | return true 82 | } 83 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/signer/v4/options.go: -------------------------------------------------------------------------------- 1 | package v4 2 | 3 | // WithUnsignedPayload will enable and set the UnsignedPayload field to 4 | // true of the signer. 5 | func WithUnsignedPayload(v4 *Signer) { 6 | v4.UnsignedPayload = true 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/signer/v4/uri_path.go: -------------------------------------------------------------------------------- 1 | // +build go1.5 2 | 3 | package v4 4 | 5 | import ( 6 | "net/url" 7 | "strings" 8 | ) 9 | 10 | func getURIPath(u *url.URL) string { 11 | var uri string 12 | 13 | if len(u.Opaque) > 0 { 14 | uri = "/" + strings.Join(strings.Split(u.Opaque, "/")[3:], "/") 15 | } else { 16 | uri = u.EscapedPath() 17 | } 18 | 19 | if len(uri) == 0 { 20 | uri = "/" 21 | } 22 | 23 | return uri 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/url.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | package aws 4 | 5 | import "net/url" 6 | 7 | // URLHostname will extract the Hostname without port from the URL value. 8 | // 9 | // Wrapper of net/url#URL.Hostname for backwards Go version compatibility. 10 | func URLHostname(url *url.URL) string { 11 | return url.Hostname() 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/url_1_7.go: -------------------------------------------------------------------------------- 1 | // +build !go1.8 2 | 3 | package aws 4 | 5 | import ( 6 | "net/url" 7 | "strings" 8 | ) 9 | 10 | // URLHostname will extract the Hostname without port from the URL value. 11 | // 12 | // Copy of Go 1.8's net/url#URL.Hostname functionality. 13 | func URLHostname(url *url.URL) string { 14 | return stripPort(url.Host) 15 | 16 | } 17 | 18 | // stripPort is copy of Go 1.8 url#URL.Hostname functionality. 19 | // https://golang.org/src/net/url/url.go 20 | func stripPort(hostport string) string { 21 | colon := strings.IndexByte(hostport, ':') 22 | if colon == -1 { 23 | return hostport 24 | } 25 | if i := strings.IndexByte(hostport, ']'); i != -1 { 26 | return strings.TrimPrefix(hostport[:i], "[") 27 | } 28 | return hostport[:colon] 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/aws/version.go: -------------------------------------------------------------------------------- 1 | // Package aws provides core functionality for making requests to AWS services. 2 | package aws 3 | 4 | // SDKName is the name of this AWS SDK 5 | const SDKName = "aws-sdk-go" 6 | 7 | // SDKVersion is the version of this SDK 8 | const SDKVersion = "1.13.32" 9 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/internal/sdkio/io_go1.6.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package sdkio 4 | 5 | // Copy of Go 1.7 io package's Seeker constants. 6 | const ( 7 | SeekStart = 0 // seek relative to the origin of the file 8 | SeekCurrent = 1 // seek relative to the current offset 9 | SeekEnd = 2 // seek relative to the end 10 | ) 11 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/internal/sdkio/io_go1.7.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package sdkio 4 | 5 | import "io" 6 | 7 | // Alias for Go 1.7 io package Seeker constants 8 | const ( 9 | SeekStart = io.SeekStart // seek relative to the origin of the file 10 | SeekCurrent = io.SeekCurrent // seek relative to the current offset 11 | SeekEnd = io.SeekEnd // seek relative to the end 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/internal/sdkrand/locked_source.go: -------------------------------------------------------------------------------- 1 | package sdkrand 2 | 3 | import ( 4 | "math/rand" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | // lockedSource is a thread-safe implementation of rand.Source 10 | type lockedSource struct { 11 | lk sync.Mutex 12 | src rand.Source 13 | } 14 | 15 | func (r *lockedSource) Int63() (n int64) { 16 | r.lk.Lock() 17 | n = r.src.Int63() 18 | r.lk.Unlock() 19 | return 20 | } 21 | 22 | func (r *lockedSource) Seed(seed int64) { 23 | r.lk.Lock() 24 | r.src.Seed(seed) 25 | r.lk.Unlock() 26 | } 27 | 28 | // SeededRand is a new RNG using a thread safe implementation of rand.Source 29 | var SeededRand = rand.New(&lockedSource{src: rand.NewSource(time.Now().UnixNano())}) 30 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/internal/shareddefaults/shared_config.go: -------------------------------------------------------------------------------- 1 | package shareddefaults 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "runtime" 7 | ) 8 | 9 | // SharedCredentialsFilename returns the SDK's default file path 10 | // for the shared credentials file. 11 | // 12 | // Builds the shared config file path based on the OS's platform. 13 | // 14 | // - Linux/Unix: $HOME/.aws/credentials 15 | // - Windows: %USERPROFILE%\.aws\credentials 16 | func SharedCredentialsFilename() string { 17 | return filepath.Join(UserHomeDir(), ".aws", "credentials") 18 | } 19 | 20 | // SharedConfigFilename returns the SDK's default file path for 21 | // the shared config file. 22 | // 23 | // Builds the shared config file path based on the OS's platform. 24 | // 25 | // - Linux/Unix: $HOME/.aws/config 26 | // - Windows: %USERPROFILE%\.aws\config 27 | func SharedConfigFilename() string { 28 | return filepath.Join(UserHomeDir(), ".aws", "config") 29 | } 30 | 31 | // UserHomeDir returns the home directory for the user the process is 32 | // running under. 33 | func UserHomeDir() string { 34 | if runtime.GOOS == "windows" { // Windows 35 | return os.Getenv("USERPROFILE") 36 | } 37 | 38 | // *nix 39 | return os.Getenv("HOME") 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/idempotency.go: -------------------------------------------------------------------------------- 1 | package protocol 2 | 3 | import ( 4 | "crypto/rand" 5 | "fmt" 6 | "reflect" 7 | ) 8 | 9 | // RandReader is the random reader the protocol package will use to read 10 | // random bytes from. This is exported for testing, and should not be used. 11 | var RandReader = rand.Reader 12 | 13 | const idempotencyTokenFillTag = `idempotencyToken` 14 | 15 | // CanSetIdempotencyToken returns true if the struct field should be 16 | // automatically populated with a Idempotency token. 17 | // 18 | // Only *string and string type fields that are tagged with idempotencyToken 19 | // which are not already set can be auto filled. 20 | func CanSetIdempotencyToken(v reflect.Value, f reflect.StructField) bool { 21 | switch u := v.Interface().(type) { 22 | // To auto fill an Idempotency token the field must be a string, 23 | // tagged for auto fill, and have a zero value. 24 | case *string: 25 | return u == nil && len(f.Tag.Get(idempotencyTokenFillTag)) != 0 26 | case string: 27 | return len(u) == 0 && len(f.Tag.Get(idempotencyTokenFillTag)) != 0 28 | } 29 | 30 | return false 31 | } 32 | 33 | // GetIdempotencyToken returns a randomly generated idempotency token. 34 | func GetIdempotencyToken() string { 35 | b := make([]byte, 16) 36 | RandReader.Read(b) 37 | 38 | return UUIDVersion4(b) 39 | } 40 | 41 | // SetIdempotencyToken will set the value provided with a Idempotency Token. 42 | // Given that the value can be set. Will panic if value is not setable. 43 | func SetIdempotencyToken(v reflect.Value) { 44 | if v.Kind() == reflect.Ptr { 45 | if v.IsNil() && v.CanSet() { 46 | v.Set(reflect.New(v.Type().Elem())) 47 | } 48 | v = v.Elem() 49 | } 50 | v = reflect.Indirect(v) 51 | 52 | if !v.CanSet() { 53 | panic(fmt.Sprintf("unable to set idempotnecy token %v", v)) 54 | } 55 | 56 | b := make([]byte, 16) 57 | _, err := rand.Read(b) 58 | if err != nil { 59 | // TODO handle error 60 | return 61 | } 62 | 63 | v.Set(reflect.ValueOf(UUIDVersion4(b))) 64 | } 65 | 66 | // UUIDVersion4 returns a Version 4 random UUID from the byte slice provided 67 | func UUIDVersion4(u []byte) string { 68 | // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 69 | // 13th character is "4" 70 | u[6] = (u[6] | 0x40) & 0x4F 71 | // 17th character is "8", "9", "a", or "b" 72 | u[8] = (u[8] | 0x80) & 0xBF 73 | 74 | return fmt.Sprintf(`%X-%X-%X-%X-%X`, u[0:4], u[4:6], u[6:8], u[8:10], u[10:]) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/jsonvalue.go: -------------------------------------------------------------------------------- 1 | package protocol 2 | 3 | import ( 4 | "encoding/base64" 5 | "encoding/json" 6 | "fmt" 7 | "strconv" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | ) 11 | 12 | // EscapeMode is the mode that should be use for escaping a value 13 | type EscapeMode uint 14 | 15 | // The modes for escaping a value before it is marshaled, and unmarshaled. 16 | const ( 17 | NoEscape EscapeMode = iota 18 | Base64Escape 19 | QuotedEscape 20 | ) 21 | 22 | // EncodeJSONValue marshals the value into a JSON string, and optionally base64 23 | // encodes the string before returning it. 24 | // 25 | // Will panic if the escape mode is unknown. 26 | func EncodeJSONValue(v aws.JSONValue, escape EscapeMode) (string, error) { 27 | b, err := json.Marshal(v) 28 | if err != nil { 29 | return "", err 30 | } 31 | 32 | switch escape { 33 | case NoEscape: 34 | return string(b), nil 35 | case Base64Escape: 36 | return base64.StdEncoding.EncodeToString(b), nil 37 | case QuotedEscape: 38 | return strconv.Quote(string(b)), nil 39 | } 40 | 41 | panic(fmt.Sprintf("EncodeJSONValue called with unknown EscapeMode, %v", escape)) 42 | } 43 | 44 | // DecodeJSONValue will attempt to decode the string input as a JSONValue. 45 | // Optionally decoding base64 the value first before JSON unmarshaling. 46 | // 47 | // Will panic if the escape mode is unknown. 48 | func DecodeJSONValue(v string, escape EscapeMode) (aws.JSONValue, error) { 49 | var b []byte 50 | var err error 51 | 52 | switch escape { 53 | case NoEscape: 54 | b = []byte(v) 55 | case Base64Escape: 56 | b, err = base64.StdEncoding.DecodeString(v) 57 | case QuotedEscape: 58 | var u string 59 | u, err = strconv.Unquote(v) 60 | b = []byte(u) 61 | default: 62 | panic(fmt.Sprintf("DecodeJSONValue called with unknown EscapeMode, %v", escape)) 63 | } 64 | 65 | if err != nil { 66 | return nil, err 67 | } 68 | 69 | m := aws.JSONValue{} 70 | err = json.Unmarshal(b, &m) 71 | if err != nil { 72 | return nil, err 73 | } 74 | 75 | return m, nil 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/query/build.go: -------------------------------------------------------------------------------- 1 | // Package query provides serialization of AWS query requests, and responses. 2 | package query 3 | 4 | //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/query.json build_test.go 5 | 6 | import ( 7 | "net/url" 8 | 9 | "github.com/aws/aws-sdk-go/aws/awserr" 10 | "github.com/aws/aws-sdk-go/aws/request" 11 | "github.com/aws/aws-sdk-go/private/protocol/query/queryutil" 12 | ) 13 | 14 | // BuildHandler is a named request handler for building query protocol requests 15 | var BuildHandler = request.NamedHandler{Name: "awssdk.query.Build", Fn: Build} 16 | 17 | // Build builds a request for an AWS Query service. 18 | func Build(r *request.Request) { 19 | body := url.Values{ 20 | "Action": {r.Operation.Name}, 21 | "Version": {r.ClientInfo.APIVersion}, 22 | } 23 | if err := queryutil.Parse(body, r.Params, false); err != nil { 24 | r.Error = awserr.New("SerializationError", "failed encoding Query request", err) 25 | return 26 | } 27 | 28 | if !r.IsPresigned() { 29 | r.HTTPRequest.Method = "POST" 30 | r.HTTPRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8") 31 | r.SetBufferBody([]byte(body.Encode())) 32 | } else { // This is a pre-signed request 33 | r.HTTPRequest.Method = "GET" 34 | r.HTTPRequest.URL.RawQuery = body.Encode() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal.go: -------------------------------------------------------------------------------- 1 | package query 2 | 3 | //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/query.json unmarshal_test.go 4 | 5 | import ( 6 | "encoding/xml" 7 | 8 | "github.com/aws/aws-sdk-go/aws/awserr" 9 | "github.com/aws/aws-sdk-go/aws/request" 10 | "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil" 11 | ) 12 | 13 | // UnmarshalHandler is a named request handler for unmarshaling query protocol requests 14 | var UnmarshalHandler = request.NamedHandler{Name: "awssdk.query.Unmarshal", Fn: Unmarshal} 15 | 16 | // UnmarshalMetaHandler is a named request handler for unmarshaling query protocol request metadata 17 | var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.query.UnmarshalMeta", Fn: UnmarshalMeta} 18 | 19 | // Unmarshal unmarshals a response for an AWS Query service. 20 | func Unmarshal(r *request.Request) { 21 | defer r.HTTPResponse.Body.Close() 22 | if r.DataFilled() { 23 | decoder := xml.NewDecoder(r.HTTPResponse.Body) 24 | err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result") 25 | if err != nil { 26 | r.Error = awserr.New("SerializationError", "failed decoding Query response", err) 27 | return 28 | } 29 | } 30 | } 31 | 32 | // UnmarshalMeta unmarshals header response values for an AWS Query service. 33 | func UnmarshalMeta(r *request.Request) { 34 | r.RequestID = r.HTTPResponse.Header.Get("X-Amzn-Requestid") 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal_error.go: -------------------------------------------------------------------------------- 1 | package query 2 | 3 | import ( 4 | "encoding/xml" 5 | "io/ioutil" 6 | 7 | "github.com/aws/aws-sdk-go/aws/awserr" 8 | "github.com/aws/aws-sdk-go/aws/request" 9 | ) 10 | 11 | type xmlErrorResponse struct { 12 | XMLName xml.Name `xml:"ErrorResponse"` 13 | Code string `xml:"Error>Code"` 14 | Message string `xml:"Error>Message"` 15 | RequestID string `xml:"RequestId"` 16 | } 17 | 18 | type xmlServiceUnavailableResponse struct { 19 | XMLName xml.Name `xml:"ServiceUnavailableException"` 20 | } 21 | 22 | // UnmarshalErrorHandler is a name request handler to unmarshal request errors 23 | var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.query.UnmarshalError", Fn: UnmarshalError} 24 | 25 | // UnmarshalError unmarshals an error response for an AWS Query service. 26 | func UnmarshalError(r *request.Request) { 27 | defer r.HTTPResponse.Body.Close() 28 | 29 | bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body) 30 | if err != nil { 31 | r.Error = awserr.New("SerializationError", "failed to read from query HTTP response body", err) 32 | return 33 | } 34 | 35 | // First check for specific error 36 | resp := xmlErrorResponse{} 37 | decodeErr := xml.Unmarshal(bodyBytes, &resp) 38 | if decodeErr == nil { 39 | reqID := resp.RequestID 40 | if reqID == "" { 41 | reqID = r.RequestID 42 | } 43 | r.Error = awserr.NewRequestFailure( 44 | awserr.New(resp.Code, resp.Message, nil), 45 | r.HTTPResponse.StatusCode, 46 | reqID, 47 | ) 48 | return 49 | } 50 | 51 | // Check for unhandled error 52 | servUnavailResp := xmlServiceUnavailableResponse{} 53 | unavailErr := xml.Unmarshal(bodyBytes, &servUnavailResp) 54 | if unavailErr == nil { 55 | r.Error = awserr.NewRequestFailure( 56 | awserr.New("ServiceUnavailableException", "service is unavailable", nil), 57 | r.HTTPResponse.StatusCode, 58 | r.RequestID, 59 | ) 60 | return 61 | } 62 | 63 | // Failed to retrieve any error message from the response body 64 | r.Error = awserr.New("SerializationError", 65 | "failed to decode query XML error response", decodeErr) 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/rest/payload.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import "reflect" 4 | 5 | // PayloadMember returns the payload field member of i if there is one, or nil. 6 | func PayloadMember(i interface{}) interface{} { 7 | if i == nil { 8 | return nil 9 | } 10 | 11 | v := reflect.ValueOf(i).Elem() 12 | if !v.IsValid() { 13 | return nil 14 | } 15 | if field, ok := v.Type().FieldByName("_"); ok { 16 | if payloadName := field.Tag.Get("payload"); payloadName != "" { 17 | field, _ := v.Type().FieldByName(payloadName) 18 | if field.Tag.Get("type") != "structure" { 19 | return nil 20 | } 21 | 22 | payload := v.FieldByName(payloadName) 23 | if payload.IsValid() || (payload.Kind() == reflect.Ptr && !payload.IsNil()) { 24 | return payload.Interface() 25 | } 26 | } 27 | } 28 | return nil 29 | } 30 | 31 | // PayloadType returns the type of a payload field member of i if there is one, or "". 32 | func PayloadType(i interface{}) string { 33 | v := reflect.Indirect(reflect.ValueOf(i)) 34 | if !v.IsValid() { 35 | return "" 36 | } 37 | if field, ok := v.Type().FieldByName("_"); ok { 38 | if payloadName := field.Tag.Get("payload"); payloadName != "" { 39 | if member, ok := v.Type().FieldByName(payloadName); ok { 40 | return member.Tag.Get("type") 41 | } 42 | } 43 | } 44 | return "" 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/unmarshal.go: -------------------------------------------------------------------------------- 1 | package protocol 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | 7 | "github.com/aws/aws-sdk-go/aws/request" 8 | ) 9 | 10 | // UnmarshalDiscardBodyHandler is a named request handler to empty and close a response's body 11 | var UnmarshalDiscardBodyHandler = request.NamedHandler{Name: "awssdk.shared.UnmarshalDiscardBody", Fn: UnmarshalDiscardBody} 12 | 13 | // UnmarshalDiscardBody is a request handler to empty a response's body and closing it. 14 | func UnmarshalDiscardBody(r *request.Request) { 15 | if r.HTTPResponse == nil || r.HTTPResponse.Body == nil { 16 | return 17 | } 18 | 19 | io.Copy(ioutil.Discard, r.HTTPResponse.Body) 20 | r.HTTPResponse.Body.Close() 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil/xml_to_struct.go: -------------------------------------------------------------------------------- 1 | package xmlutil 2 | 3 | import ( 4 | "encoding/xml" 5 | "fmt" 6 | "io" 7 | "sort" 8 | ) 9 | 10 | // A XMLNode contains the values to be encoded or decoded. 11 | type XMLNode struct { 12 | Name xml.Name `json:",omitempty"` 13 | Children map[string][]*XMLNode `json:",omitempty"` 14 | Text string `json:",omitempty"` 15 | Attr []xml.Attr `json:",omitempty"` 16 | 17 | namespaces map[string]string 18 | parent *XMLNode 19 | } 20 | 21 | // NewXMLElement returns a pointer to a new XMLNode initialized to default values. 22 | func NewXMLElement(name xml.Name) *XMLNode { 23 | return &XMLNode{ 24 | Name: name, 25 | Children: map[string][]*XMLNode{}, 26 | Attr: []xml.Attr{}, 27 | } 28 | } 29 | 30 | // AddChild adds child to the XMLNode. 31 | func (n *XMLNode) AddChild(child *XMLNode) { 32 | if _, ok := n.Children[child.Name.Local]; !ok { 33 | n.Children[child.Name.Local] = []*XMLNode{} 34 | } 35 | n.Children[child.Name.Local] = append(n.Children[child.Name.Local], child) 36 | } 37 | 38 | // XMLToStruct converts a xml.Decoder stream to XMLNode with nested values. 39 | func XMLToStruct(d *xml.Decoder, s *xml.StartElement) (*XMLNode, error) { 40 | out := &XMLNode{} 41 | for { 42 | tok, err := d.Token() 43 | if err != nil { 44 | if err == io.EOF { 45 | break 46 | } else { 47 | return out, err 48 | } 49 | } 50 | 51 | if tok == nil { 52 | break 53 | } 54 | 55 | switch typed := tok.(type) { 56 | case xml.CharData: 57 | out.Text = string(typed.Copy()) 58 | case xml.StartElement: 59 | el := typed.Copy() 60 | out.Attr = el.Attr 61 | if out.Children == nil { 62 | out.Children = map[string][]*XMLNode{} 63 | } 64 | 65 | name := typed.Name.Local 66 | slice := out.Children[name] 67 | if slice == nil { 68 | slice = []*XMLNode{} 69 | } 70 | node, e := XMLToStruct(d, &el) 71 | out.findNamespaces() 72 | if e != nil { 73 | return out, e 74 | } 75 | node.Name = typed.Name 76 | node.findNamespaces() 77 | tempOut := *out 78 | // Save into a temp variable, simply because out gets squashed during 79 | // loop iterations 80 | node.parent = &tempOut 81 | slice = append(slice, node) 82 | out.Children[name] = slice 83 | case xml.EndElement: 84 | if s != nil && s.Name.Local == typed.Name.Local { // matching end token 85 | return out, nil 86 | } 87 | out = &XMLNode{} 88 | } 89 | } 90 | return out, nil 91 | } 92 | 93 | func (n *XMLNode) findNamespaces() { 94 | ns := map[string]string{} 95 | for _, a := range n.Attr { 96 | if a.Name.Space == "xmlns" { 97 | ns[a.Value] = a.Name.Local 98 | } 99 | } 100 | 101 | n.namespaces = ns 102 | } 103 | 104 | func (n *XMLNode) findElem(name string) (string, bool) { 105 | for node := n; node != nil; node = node.parent { 106 | for _, a := range node.Attr { 107 | namespace := a.Name.Space 108 | if v, ok := node.namespaces[namespace]; ok { 109 | namespace = v 110 | } 111 | if name == fmt.Sprintf("%s:%s", namespace, a.Name.Local) { 112 | return a.Value, true 113 | } 114 | } 115 | } 116 | return "", false 117 | } 118 | 119 | // StructToXML writes an XMLNode to a xml.Encoder as tokens. 120 | func StructToXML(e *xml.Encoder, node *XMLNode, sorted bool) error { 121 | e.EncodeToken(xml.StartElement{Name: node.Name, Attr: node.Attr}) 122 | 123 | if node.Text != "" { 124 | e.EncodeToken(xml.CharData([]byte(node.Text))) 125 | } else if sorted { 126 | sortedNames := []string{} 127 | for k := range node.Children { 128 | sortedNames = append(sortedNames, k) 129 | } 130 | sort.Strings(sortedNames) 131 | 132 | for _, k := range sortedNames { 133 | for _, v := range node.Children[k] { 134 | StructToXML(e, v, sorted) 135 | } 136 | } 137 | } else { 138 | for _, c := range node.Children { 139 | for _, v := range c { 140 | StructToXML(e, v, sorted) 141 | } 142 | } 143 | } 144 | 145 | e.EncodeToken(xml.EndElement{Name: node.Name}) 146 | return e.Flush() 147 | } 148 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sqs/checksums.go: -------------------------------------------------------------------------------- 1 | package sqs 2 | 3 | import ( 4 | "crypto/md5" 5 | "encoding/hex" 6 | "fmt" 7 | "strings" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/aws/awserr" 11 | "github.com/aws/aws-sdk-go/aws/request" 12 | ) 13 | 14 | var ( 15 | errChecksumMissingBody = fmt.Errorf("cannot compute checksum. missing body") 16 | errChecksumMissingMD5 = fmt.Errorf("cannot verify checksum. missing response MD5") 17 | ) 18 | 19 | func setupChecksumValidation(r *request.Request) { 20 | if aws.BoolValue(r.Config.DisableComputeChecksums) { 21 | return 22 | } 23 | 24 | switch r.Operation.Name { 25 | case opSendMessage: 26 | r.Handlers.Unmarshal.PushBack(verifySendMessage) 27 | case opSendMessageBatch: 28 | r.Handlers.Unmarshal.PushBack(verifySendMessageBatch) 29 | case opReceiveMessage: 30 | r.Handlers.Unmarshal.PushBack(verifyReceiveMessage) 31 | } 32 | } 33 | 34 | func verifySendMessage(r *request.Request) { 35 | if r.DataFilled() && r.ParamsFilled() { 36 | in := r.Params.(*SendMessageInput) 37 | out := r.Data.(*SendMessageOutput) 38 | err := checksumsMatch(in.MessageBody, out.MD5OfMessageBody) 39 | if err != nil { 40 | setChecksumError(r, err.Error()) 41 | } 42 | } 43 | } 44 | 45 | func verifySendMessageBatch(r *request.Request) { 46 | if r.DataFilled() && r.ParamsFilled() { 47 | entries := map[string]*SendMessageBatchResultEntry{} 48 | ids := []string{} 49 | 50 | out := r.Data.(*SendMessageBatchOutput) 51 | for _, entry := range out.Successful { 52 | entries[*entry.Id] = entry 53 | } 54 | 55 | in := r.Params.(*SendMessageBatchInput) 56 | for _, entry := range in.Entries { 57 | if e := entries[*entry.Id]; e != nil { 58 | err := checksumsMatch(entry.MessageBody, e.MD5OfMessageBody) 59 | if err != nil { 60 | ids = append(ids, *e.MessageId) 61 | } 62 | } 63 | } 64 | if len(ids) > 0 { 65 | setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", ")) 66 | } 67 | } 68 | } 69 | 70 | func verifyReceiveMessage(r *request.Request) { 71 | if r.DataFilled() && r.ParamsFilled() { 72 | ids := []string{} 73 | out := r.Data.(*ReceiveMessageOutput) 74 | for i, msg := range out.Messages { 75 | err := checksumsMatch(msg.Body, msg.MD5OfBody) 76 | if err != nil { 77 | if msg.MessageId == nil { 78 | if r.Config.Logger != nil { 79 | r.Config.Logger.Log(fmt.Sprintf( 80 | "WARN: SQS.ReceiveMessage failed checksum request id: %s, message %d has no message ID.", 81 | r.RequestID, i, 82 | )) 83 | } 84 | continue 85 | } 86 | 87 | ids = append(ids, *msg.MessageId) 88 | } 89 | } 90 | if len(ids) > 0 { 91 | setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", ")) 92 | } 93 | } 94 | } 95 | 96 | func checksumsMatch(body, expectedMD5 *string) error { 97 | if body == nil { 98 | return errChecksumMissingBody 99 | } else if expectedMD5 == nil { 100 | return errChecksumMissingMD5 101 | } 102 | 103 | msum := md5.Sum([]byte(*body)) 104 | sum := hex.EncodeToString(msum[:]) 105 | if sum != *expectedMD5 { 106 | return fmt.Errorf("expected MD5 checksum '%s', got '%s'", *expectedMD5, sum) 107 | } 108 | 109 | return nil 110 | } 111 | 112 | func setChecksumError(r *request.Request, format string, args ...interface{}) { 113 | r.Retryable = aws.Bool(true) 114 | r.Error = awserr.New("InvalidChecksum", fmt.Sprintf(format, args...), nil) 115 | } 116 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sqs/customizations.go: -------------------------------------------------------------------------------- 1 | package sqs 2 | 3 | import "github.com/aws/aws-sdk-go/aws/request" 4 | 5 | func init() { 6 | initRequest = func(r *request.Request) { 7 | setupChecksumValidation(r) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sqs/doc.go: -------------------------------------------------------------------------------- 1 | // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 | 3 | // Package sqs provides the client and types for making API 4 | // requests to Amazon Simple Queue Service. 5 | // 6 | // Welcome to the Amazon Simple Queue Service API Reference. 7 | // 8 | // Amazon Simple Queue Service (Amazon SQS) is a reliable, highly-scalable hosted 9 | // queue for storing messages as they travel between applications or microservices. 10 | // Amazon SQS moves data between distributed application components and helps 11 | // you decouple these components. 12 | // 13 | // Standard queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html) 14 | // are available in all regions. FIFO queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html) 15 | // are available in the US East (N. Virginia), US East (Ohio), US West (Oregon), 16 | // and EU (Ireland) regions. 17 | // 18 | // You can use AWS SDKs (http://aws.amazon.com/tools/#sdk) to access Amazon 19 | // SQS using your favorite programming language. The SDKs perform tasks such 20 | // as the following automatically: 21 | // 22 | // * Cryptographically sign your service requests 23 | // 24 | // * Retry requests 25 | // 26 | // * Handle error responses 27 | // 28 | // Additional Information 29 | // 30 | // * Amazon SQS Product Page (http://aws.amazon.com/sqs/) 31 | // 32 | // * Amazon Simple Queue Service Developer Guide 33 | // 34 | // Making API Requests (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/MakingRequestsArticle.html) 35 | // 36 | // Using Amazon SQS Message Attributes (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html) 37 | // 38 | // Using Amazon SQS Dead-Letter Queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html) 39 | // 40 | // * Amazon Web Services General Reference 41 | // 42 | // Regions and Endpoints (http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region) 43 | // 44 | // See https://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05 for more information on this service. 45 | // 46 | // See sqs package documentation for more information. 47 | // https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/ 48 | // 49 | // Using the Client 50 | // 51 | // To contact Amazon Simple Queue Service with the SDK use the New function to create 52 | // a new service client. With that client you can make API requests to the service. 53 | // These clients are safe to use concurrently. 54 | // 55 | // See the SDK's documentation for more information on how to use the SDK. 56 | // https://docs.aws.amazon.com/sdk-for-go/api/ 57 | // 58 | // See aws.Config documentation for more information on configuring SDK clients. 59 | // https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config 60 | // 61 | // See the Amazon Simple Queue Service client SQS for more 62 | // information on creating client for this service. 63 | // https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/#New 64 | package sqs 65 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sqs/service.go: -------------------------------------------------------------------------------- 1 | // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 | 3 | package sqs 4 | 5 | import ( 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/aws/client" 8 | "github.com/aws/aws-sdk-go/aws/client/metadata" 9 | "github.com/aws/aws-sdk-go/aws/request" 10 | "github.com/aws/aws-sdk-go/aws/signer/v4" 11 | "github.com/aws/aws-sdk-go/private/protocol/query" 12 | ) 13 | 14 | // SQS provides the API operation methods for making requests to 15 | // Amazon Simple Queue Service. See this package's package overview docs 16 | // for details on the service. 17 | // 18 | // SQS methods are safe to use concurrently. It is not safe to 19 | // modify mutate any of the struct's properties though. 20 | type SQS struct { 21 | *client.Client 22 | } 23 | 24 | // Used for custom client initialization logic 25 | var initClient func(*client.Client) 26 | 27 | // Used for custom request initialization logic 28 | var initRequest func(*request.Request) 29 | 30 | // Service information constants 31 | const ( 32 | ServiceName = "sqs" // Service endpoint prefix API calls made to. 33 | EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata. 34 | ) 35 | 36 | // New creates a new instance of the SQS client with a session. 37 | // If additional configuration is needed for the client instance use the optional 38 | // aws.Config parameter to add your extra config. 39 | // 40 | // Example: 41 | // // Create a SQS client from just a session. 42 | // svc := sqs.New(mySession) 43 | // 44 | // // Create a SQS client with additional configuration 45 | // svc := sqs.New(mySession, aws.NewConfig().WithRegion("us-west-2")) 46 | func New(p client.ConfigProvider, cfgs ...*aws.Config) *SQS { 47 | c := p.ClientConfig(EndpointsID, cfgs...) 48 | return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName) 49 | } 50 | 51 | // newClient creates, initializes and returns a new service client instance. 52 | func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *SQS { 53 | svc := &SQS{ 54 | Client: client.New( 55 | cfg, 56 | metadata.ClientInfo{ 57 | ServiceName: ServiceName, 58 | SigningName: signingName, 59 | SigningRegion: signingRegion, 60 | Endpoint: endpoint, 61 | APIVersion: "2012-11-05", 62 | }, 63 | handlers, 64 | ), 65 | } 66 | 67 | // Handlers 68 | svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler) 69 | svc.Handlers.Build.PushBackNamed(query.BuildHandler) 70 | svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler) 71 | svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler) 72 | svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler) 73 | 74 | // Run custom client initialization if present 75 | if initClient != nil { 76 | initClient(svc.Client) 77 | } 78 | 79 | return svc 80 | } 81 | 82 | // newRequest creates a new request for a SQS operation and runs any 83 | // custom request initialization. 84 | func (c *SQS) newRequest(op *request.Operation, params, data interface{}) *request.Request { 85 | req := c.NewRequest(op, params, data) 86 | 87 | // Run custom request initialization if present 88 | if initRequest != nil { 89 | initRequest(req) 90 | } 91 | 92 | return req 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sts/customizations.go: -------------------------------------------------------------------------------- 1 | package sts 2 | 3 | import "github.com/aws/aws-sdk-go/aws/request" 4 | 5 | func init() { 6 | initRequest = func(r *request.Request) { 7 | switch r.Operation.Name { 8 | case opAssumeRoleWithSAML, opAssumeRoleWithWebIdentity: 9 | r.Handlers.Sign.Clear() // these operations are unsigned 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sts/errors.go: -------------------------------------------------------------------------------- 1 | // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 | 3 | package sts 4 | 5 | const ( 6 | 7 | // ErrCodeExpiredTokenException for service response error code 8 | // "ExpiredTokenException". 9 | // 10 | // The web identity token that was passed is expired or is not valid. Get a 11 | // new identity token from the identity provider and then retry the request. 12 | ErrCodeExpiredTokenException = "ExpiredTokenException" 13 | 14 | // ErrCodeIDPCommunicationErrorException for service response error code 15 | // "IDPCommunicationError". 16 | // 17 | // The request could not be fulfilled because the non-AWS identity provider 18 | // (IDP) that was asked to verify the incoming identity token could not be reached. 19 | // This is often a transient error caused by network conditions. Retry the request 20 | // a limited number of times so that you don't exceed the request rate. If the 21 | // error persists, the non-AWS identity provider might be down or not responding. 22 | ErrCodeIDPCommunicationErrorException = "IDPCommunicationError" 23 | 24 | // ErrCodeIDPRejectedClaimException for service response error code 25 | // "IDPRejectedClaim". 26 | // 27 | // The identity provider (IdP) reported that authentication failed. This might 28 | // be because the claim is invalid. 29 | // 30 | // If this error is returned for the AssumeRoleWithWebIdentity operation, it 31 | // can also mean that the claim has expired or has been explicitly revoked. 32 | ErrCodeIDPRejectedClaimException = "IDPRejectedClaim" 33 | 34 | // ErrCodeInvalidAuthorizationMessageException for service response error code 35 | // "InvalidAuthorizationMessageException". 36 | // 37 | // The error returned if the message passed to DecodeAuthorizationMessage was 38 | // invalid. This can happen if the token contains invalid characters, such as 39 | // linebreaks. 40 | ErrCodeInvalidAuthorizationMessageException = "InvalidAuthorizationMessageException" 41 | 42 | // ErrCodeInvalidIdentityTokenException for service response error code 43 | // "InvalidIdentityToken". 44 | // 45 | // The web identity token that was passed could not be validated by AWS. Get 46 | // a new identity token from the identity provider and then retry the request. 47 | ErrCodeInvalidIdentityTokenException = "InvalidIdentityToken" 48 | 49 | // ErrCodeMalformedPolicyDocumentException for service response error code 50 | // "MalformedPolicyDocument". 51 | // 52 | // The request was rejected because the policy document was malformed. The error 53 | // message describes the specific error. 54 | ErrCodeMalformedPolicyDocumentException = "MalformedPolicyDocument" 55 | 56 | // ErrCodePackedPolicyTooLargeException for service response error code 57 | // "PackedPolicyTooLarge". 58 | // 59 | // The request was rejected because the policy document was too large. The error 60 | // message describes how big the policy document is, in packed form, as a percentage 61 | // of what the API allows. 62 | ErrCodePackedPolicyTooLargeException = "PackedPolicyTooLarge" 63 | 64 | // ErrCodeRegionDisabledException for service response error code 65 | // "RegionDisabledException". 66 | // 67 | // STS is not activated in the requested region for the account that is being 68 | // asked to generate credentials. The account administrator must use the IAM 69 | // console to activate STS in that region. For more information, see Activating 70 | // and Deactivating AWS STS in an AWS Region (http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) 71 | // in the IAM User Guide. 72 | ErrCodeRegionDisabledException = "RegionDisabledException" 73 | ) 74 | -------------------------------------------------------------------------------- /vendor/github.com/aws/aws-sdk-go/service/sts/service.go: -------------------------------------------------------------------------------- 1 | // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 | 3 | package sts 4 | 5 | import ( 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/aws/client" 8 | "github.com/aws/aws-sdk-go/aws/client/metadata" 9 | "github.com/aws/aws-sdk-go/aws/request" 10 | "github.com/aws/aws-sdk-go/aws/signer/v4" 11 | "github.com/aws/aws-sdk-go/private/protocol/query" 12 | ) 13 | 14 | // STS provides the API operation methods for making requests to 15 | // AWS Security Token Service. See this package's package overview docs 16 | // for details on the service. 17 | // 18 | // STS methods are safe to use concurrently. It is not safe to 19 | // modify mutate any of the struct's properties though. 20 | type STS struct { 21 | *client.Client 22 | } 23 | 24 | // Used for custom client initialization logic 25 | var initClient func(*client.Client) 26 | 27 | // Used for custom request initialization logic 28 | var initRequest func(*request.Request) 29 | 30 | // Service information constants 31 | const ( 32 | ServiceName = "sts" // Service endpoint prefix API calls made to. 33 | EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata. 34 | ) 35 | 36 | // New creates a new instance of the STS client with a session. 37 | // If additional configuration is needed for the client instance use the optional 38 | // aws.Config parameter to add your extra config. 39 | // 40 | // Example: 41 | // // Create a STS client from just a session. 42 | // svc := sts.New(mySession) 43 | // 44 | // // Create a STS client with additional configuration 45 | // svc := sts.New(mySession, aws.NewConfig().WithRegion("us-west-2")) 46 | func New(p client.ConfigProvider, cfgs ...*aws.Config) *STS { 47 | c := p.ClientConfig(EndpointsID, cfgs...) 48 | return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName) 49 | } 50 | 51 | // newClient creates, initializes and returns a new service client instance. 52 | func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *STS { 53 | svc := &STS{ 54 | Client: client.New( 55 | cfg, 56 | metadata.ClientInfo{ 57 | ServiceName: ServiceName, 58 | SigningName: signingName, 59 | SigningRegion: signingRegion, 60 | Endpoint: endpoint, 61 | APIVersion: "2011-06-15", 62 | }, 63 | handlers, 64 | ), 65 | } 66 | 67 | // Handlers 68 | svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler) 69 | svc.Handlers.Build.PushBackNamed(query.BuildHandler) 70 | svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler) 71 | svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler) 72 | svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler) 73 | 74 | // Run custom client initialization if present 75 | if initClient != nil { 76 | initClient(svc.Client) 77 | } 78 | 79 | return svc 80 | } 81 | 82 | // newRequest creates a new request for a STS operation and runs any 83 | // custom request initialization. 84 | func (c *STS) newRequest(op *request.Operation, params, data interface{}) *request.Request { 85 | req := c.NewRequest(op, params, data) 86 | 87 | // Run custom request initialization if present 88 | if initRequest != nil { 89 | initRequest(req) 90 | } 91 | 92 | return req 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-ini/ini/.gitignore: -------------------------------------------------------------------------------- 1 | testdata/conf_out.ini 2 | ini.sublime-project 3 | ini.sublime-workspace 4 | testdata/conf_reflect.ini 5 | .idea 6 | /.vscode 7 | -------------------------------------------------------------------------------- /vendor/github.com/go-ini/ini/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.5.x 5 | - 1.6.x 6 | - 1.7.x 7 | - 1.8.x 8 | - 1.9.x 9 | - 1.10.x 10 | 11 | script: 12 | - go get golang.org/x/tools/cmd/cover 13 | - go get github.com/smartystreets/goconvey 14 | - mkdir -p $HOME/gopath/src/gopkg.in 15 | - ln -s $HOME/gopath/src/github.com/go-ini/ini $HOME/gopath/src/gopkg.in/ini.v1 16 | - go test -v -cover -race 17 | -------------------------------------------------------------------------------- /vendor/github.com/go-ini/ini/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build test bench vet coverage 2 | 3 | build: vet bench 4 | 5 | test: 6 | go test -v -cover -race 7 | 8 | bench: 9 | go test -v -cover -race -test.bench=. -test.benchmem 10 | 11 | vet: 12 | go vet 13 | 14 | coverage: 15 | go test -coverprofile=c.out && go tool cover -html=c.out && rm c.out 16 | -------------------------------------------------------------------------------- /vendor/github.com/go-ini/ini/README.md: -------------------------------------------------------------------------------- 1 | INI [![Build Status](https://travis-ci.org/go-ini/ini.svg?branch=master)](https://travis-ci.org/go-ini/ini) [![Sourcegraph](https://sourcegraph.com/github.com/go-ini/ini/-/badge.svg)](https://sourcegraph.com/github.com/go-ini/ini?badge) 2 | === 3 | 4 | ![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200) 5 | 6 | Package ini provides INI file read and write functionality in Go. 7 | 8 | ## Features 9 | 10 | - Load from multiple data sources(`[]byte`, file and `io.ReadCloser`) with overwrites. 11 | - Read with recursion values. 12 | - Read with parent-child sections. 13 | - Read with auto-increment key names. 14 | - Read with multiple-line values. 15 | - Read with tons of helper methods. 16 | - Read and convert values to Go types. 17 | - Read and **WRITE** comments of sections and keys. 18 | - Manipulate sections, keys and comments with ease. 19 | - Keep sections and keys in order as you parse and save. 20 | 21 | ## Installation 22 | 23 | To use a tagged revision: 24 | 25 | ```sh 26 | $ go get gopkg.in/ini.v1 27 | ``` 28 | 29 | To use with latest changes: 30 | 31 | ```sh 32 | $ go get github.com/go-ini/ini 33 | ``` 34 | 35 | Please add `-u` flag to update in the future. 36 | 37 | ## Getting Help 38 | 39 | - [Getting Started](https://ini.unknwon.io/docs/intro/getting_started) 40 | - [API Documentation](https://gowalker.org/gopkg.in/ini.v1) 41 | 42 | ## License 43 | 44 | This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text. 45 | -------------------------------------------------------------------------------- /vendor/github.com/go-ini/ini/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Unknwon 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package ini 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | type ErrDelimiterNotFound struct { 22 | Line string 23 | } 24 | 25 | func IsErrDelimiterNotFound(err error) bool { 26 | _, ok := err.(ErrDelimiterNotFound) 27 | return ok 28 | } 29 | 30 | func (err ErrDelimiterNotFound) Error() string { 31 | return fmt.Sprintf("key-value delimiter not found: %s", err.Line) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4.3 5 | - 1.5.3 6 | - tip 7 | 8 | script: 9 | - go test -v ./... 10 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We definitely welcome patches and contribution to this project! 4 | 5 | ### Legal requirements 6 | 7 | In order to protect both you and ourselves, you will need to sign the 8 | [Contributor License Agreement](https://cla.developers.google.com/clas). 9 | 10 | You may have already signed it for other Google projects. 11 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Paul Borman 2 | bmatsuo 3 | shawnps 4 | theory 5 | jboverfelt 6 | dsymonds 7 | cd1 8 | wallclockbuilder 9 | dansouza 10 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009,2014 Google Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/README.md: -------------------------------------------------------------------------------- 1 | **This package is currently in development and the API may not be stable.** 2 | 3 | The API will become stable with v1. 4 | 5 | # uuid ![build status](https://travis-ci.org/google/uuid.svg?branch=master) 6 | The uuid package generates and inspects UUIDs based on 7 | [RFC 4122](http://tools.ietf.org/html/rfc4122) 8 | and DCE 1.1: Authentication and Security Services. 9 | 10 | This package is based on the github.com/pborman/uuid package (previously named 11 | code.google.com/p/go-uuid). It differs from these earlier packages in that 12 | a UUID is a 16 byte array rather than a byte slice. One loss due to this 13 | change is the ability to represent an invalid UUID (vs a NIL UUID). 14 | 15 | ###### Install 16 | `go get github.com/google/uuid` 17 | 18 | ###### Documentation 19 | [![GoDoc](https://godoc.org/github.com/google/uuid?status.svg)](http://godoc.org/github.com/google/uuid) 20 | 21 | Full `go doc` style documentation for the package can be viewed online without 22 | installing this package by using the GoDoc site here: 23 | http://godoc.org/github.com/google/uuid 24 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/dce.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "encoding/binary" 9 | "fmt" 10 | "os" 11 | ) 12 | 13 | // A Domain represents a Version 2 domain 14 | type Domain byte 15 | 16 | // Domain constants for DCE Security (Version 2) UUIDs. 17 | const ( 18 | Person = Domain(0) 19 | Group = Domain(1) 20 | Org = Domain(2) 21 | ) 22 | 23 | // NewDCESecurity returns a DCE Security (Version 2) UUID. 24 | // 25 | // The domain should be one of Person, Group or Org. 26 | // On a POSIX system the id should be the users UID for the Person 27 | // domain and the users GID for the Group. The meaning of id for 28 | // the domain Org or on non-POSIX systems is site defined. 29 | // 30 | // For a given domain/id pair the same token may be returned for up to 31 | // 7 minutes and 10 seconds. 32 | func NewDCESecurity(domain Domain, id uint32) (UUID, error) { 33 | uuid, err := NewUUID() 34 | if err == nil { 35 | uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2 36 | uuid[9] = byte(domain) 37 | binary.BigEndian.PutUint32(uuid[0:], id) 38 | } 39 | return uuid, err 40 | } 41 | 42 | // NewDCEPerson returns a DCE Security (Version 2) UUID in the person 43 | // domain with the id returned by os.Getuid. 44 | // 45 | // NewDCEPerson(Person, uint32(os.Getuid())) 46 | func NewDCEPerson() (UUID, error) { 47 | return NewDCESecurity(Person, uint32(os.Getuid())) 48 | } 49 | 50 | // NewDCEGroup returns a DCE Security (Version 2) UUID in the group 51 | // domain with the id returned by os.Getgid. 52 | // 53 | // NewDCEGroup(Group, uint32(os.Getgid())) 54 | func NewDCEGroup() (UUID, error) { 55 | return NewDCESecurity(Group, uint32(os.Getgid())) 56 | } 57 | 58 | // Domain returns the domain for a Version 2 UUID. Domains are only defined 59 | // for Version 2 UUIDs. 60 | func (uuid UUID) Domain() Domain { 61 | return Domain(uuid[9]) 62 | } 63 | 64 | // ID returns the id for a Version 2 UUID. IDs are only defined for Version 2 65 | // UUIDs. 66 | func (uuid UUID) ID() uint32 { 67 | return binary.BigEndian.Uint32(uuid[0:4]) 68 | } 69 | 70 | func (d Domain) String() string { 71 | switch d { 72 | case Person: 73 | return "Person" 74 | case Group: 75 | return "Group" 76 | case Org: 77 | return "Org" 78 | } 79 | return fmt.Sprintf("Domain%d", int(d)) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package uuid generates and inspects UUIDs. 6 | // 7 | // UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security 8 | // Services. 9 | // 10 | // A UUID is a 16 byte (128 bit) array. UUIDs may be used as keys to 11 | // maps or compared directly. 12 | package uuid 13 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/hash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "crypto/md5" 9 | "crypto/sha1" 10 | "hash" 11 | ) 12 | 13 | // Well known namespace IDs and UUIDs 14 | var ( 15 | NameSpaceDNS = Must(Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")) 16 | NameSpaceURL = Must(Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")) 17 | NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")) 18 | NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) 19 | Nil UUID // empty UUID, all zeros 20 | ) 21 | 22 | // NewHash returns a new UUID derived from the hash of space concatenated with 23 | // data generated by h. The hash should be at least 16 byte in length. The 24 | // first 16 bytes of the hash are used to form the UUID. The version of the 25 | // UUID will be the lower 4 bits of version. NewHash is used to implement 26 | // NewMD5 and NewSHA1. 27 | func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID { 28 | h.Reset() 29 | h.Write(space[:]) 30 | h.Write([]byte(data)) 31 | s := h.Sum(nil) 32 | var uuid UUID 33 | copy(uuid[:], s) 34 | uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4) 35 | uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant 36 | return uuid 37 | } 38 | 39 | // NewMD5 returns a new MD5 (Version 3) UUID based on the 40 | // supplied name space and data. It is the same as calling: 41 | // 42 | // NewHash(md5.New(), space, data, 3) 43 | func NewMD5(space UUID, data []byte) UUID { 44 | return NewHash(md5.New(), space, data, 3) 45 | } 46 | 47 | // NewSHA1 returns a new SHA1 (Version 5) UUID based on the 48 | // supplied name space and data. It is the same as calling: 49 | // 50 | // NewHash(sha1.New(), space, data, 5) 51 | func NewSHA1(space UUID, data []byte) UUID { 52 | return NewHash(sha1.New(), space, data, 5) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/marshal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import "fmt" 8 | 9 | // MarshalText implements encoding.TextMarshaler. 10 | func (uuid UUID) MarshalText() ([]byte, error) { 11 | var js [36]byte 12 | encodeHex(js[:], uuid) 13 | return js[:], nil 14 | } 15 | 16 | // UnmarshalText implements encoding.TextUnmarshaler. 17 | func (uuid *UUID) UnmarshalText(data []byte) error { 18 | // See comment in ParseBytes why we do this. 19 | // id, err := ParseBytes(data) 20 | id, err := ParseBytes(data) 21 | if err == nil { 22 | *uuid = id 23 | } 24 | return err 25 | } 26 | 27 | // MarshalBinary implements encoding.BinaryMarshaler. 28 | func (uuid UUID) MarshalBinary() ([]byte, error) { 29 | return uuid[:], nil 30 | } 31 | 32 | // UnmarshalBinary implements encoding.BinaryUnmarshaler. 33 | func (uuid *UUID) UnmarshalBinary(data []byte) error { 34 | if len(data) != 16 { 35 | return fmt.Errorf("invalid UUID (got %d bytes)", len(data)) 36 | } 37 | copy(uuid[:], data) 38 | return nil 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/node.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "net" 9 | "sync" 10 | ) 11 | 12 | var ( 13 | nodeMu sync.Mutex 14 | interfaces []net.Interface // cached list of interfaces 15 | ifname string // name of interface being used 16 | nodeID [6]byte // hardware for version 1 UUIDs 17 | zeroID [6]byte // nodeID with only 0's 18 | ) 19 | 20 | // NodeInterface returns the name of the interface from which the NodeID was 21 | // derived. The interface "user" is returned if the NodeID was set by 22 | // SetNodeID. 23 | func NodeInterface() string { 24 | defer nodeMu.Unlock() 25 | nodeMu.Lock() 26 | return ifname 27 | } 28 | 29 | // SetNodeInterface selects the hardware address to be used for Version 1 UUIDs. 30 | // If name is "" then the first usable interface found will be used or a random 31 | // Node ID will be generated. If a named interface cannot be found then false 32 | // is returned. 33 | // 34 | // SetNodeInterface never fails when name is "". 35 | func SetNodeInterface(name string) bool { 36 | defer nodeMu.Unlock() 37 | nodeMu.Lock() 38 | return setNodeInterface(name) 39 | } 40 | 41 | func setNodeInterface(name string) bool { 42 | if interfaces == nil { 43 | var err error 44 | interfaces, err = net.Interfaces() 45 | if err != nil && name != "" { 46 | return false 47 | } 48 | } 49 | 50 | for _, ifs := range interfaces { 51 | if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) { 52 | copy(nodeID[:], ifs.HardwareAddr) 53 | ifname = ifs.Name 54 | return true 55 | } 56 | } 57 | 58 | // We found no interfaces with a valid hardware address. If name 59 | // does not specify a specific interface generate a random Node ID 60 | // (section 4.1.6) 61 | if name == "" { 62 | randomBits(nodeID[:]) 63 | return true 64 | } 65 | return false 66 | } 67 | 68 | // NodeID returns a slice of a copy of the current Node ID, setting the Node ID 69 | // if not already set. 70 | func NodeID() []byte { 71 | defer nodeMu.Unlock() 72 | nodeMu.Lock() 73 | if nodeID == zeroID { 74 | setNodeInterface("") 75 | } 76 | nid := nodeID 77 | return nid[:] 78 | } 79 | 80 | // SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes 81 | // of id are used. If id is less than 6 bytes then false is returned and the 82 | // Node ID is not set. 83 | func SetNodeID(id []byte) bool { 84 | if len(id) < 6 { 85 | return false 86 | } 87 | defer nodeMu.Unlock() 88 | nodeMu.Lock() 89 | copy(nodeID[:], id) 90 | ifname = "user" 91 | return true 92 | } 93 | 94 | // NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is 95 | // not valid. The NodeID is only well defined for version 1 and 2 UUIDs. 96 | func (uuid UUID) NodeID() []byte { 97 | if len(uuid) != 16 { 98 | return nil 99 | } 100 | var node [6]byte 101 | copy(node[:], uuid[10:]) 102 | return node[:] 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/sql.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "database/sql/driver" 9 | "fmt" 10 | ) 11 | 12 | // Scan implements sql.Scanner so UUIDs can be read from databases transparently 13 | // Currently, database types that map to string and []byte are supported. Please 14 | // consult database-specific driver documentation for matching types. 15 | func (uuid *UUID) Scan(src interface{}) error { 16 | switch src.(type) { 17 | case string: 18 | // if an empty UUID comes from a table, we return a null UUID 19 | if src.(string) == "" { 20 | return nil 21 | } 22 | 23 | // see Parse for required string format 24 | u, err := Parse(src.(string)) 25 | 26 | if err != nil { 27 | return fmt.Errorf("Scan: %v", err) 28 | } 29 | 30 | *uuid = u 31 | case []byte: 32 | b := src.([]byte) 33 | 34 | // if an empty UUID comes from a table, we return a null UUID 35 | if len(b) == 0 { 36 | return nil 37 | } 38 | 39 | // assumes a simple slice of bytes if 16 bytes 40 | // otherwise attempts to parse 41 | if len(b) != 16 { 42 | return uuid.Scan(string(b)) 43 | } 44 | copy((*uuid)[:], b) 45 | 46 | default: 47 | return fmt.Errorf("Scan: unable to scan type %T into UUID", src) 48 | } 49 | 50 | return nil 51 | } 52 | 53 | // Value implements sql.Valuer so that UUIDs can be written to databases 54 | // transparently. Currently, UUIDs map to strings. Please consult 55 | // database-specific driver documentation for matching types. 56 | func (uuid UUID) Value() (driver.Value, error) { 57 | return uuid.String(), nil 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/time.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "encoding/binary" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | // A Time represents a time as the number of 100's of nanoseconds since 15 Oct 14 | // 1582. 15 | type Time int64 16 | 17 | const ( 18 | lillian = 2299160 // Julian day of 15 Oct 1582 19 | unix = 2440587 // Julian day of 1 Jan 1970 20 | epoch = unix - lillian // Days between epochs 21 | g1582 = epoch * 86400 // seconds between epochs 22 | g1582ns100 = g1582 * 10000000 // 100s of a nanoseconds between epochs 23 | ) 24 | 25 | var ( 26 | timeMu sync.Mutex 27 | lasttime uint64 // last time we returned 28 | clockSeq uint16 // clock sequence for this run 29 | 30 | timeNow = time.Now // for testing 31 | ) 32 | 33 | // UnixTime converts t the number of seconds and nanoseconds using the Unix 34 | // epoch of 1 Jan 1970. 35 | func (t Time) UnixTime() (sec, nsec int64) { 36 | sec = int64(t - g1582ns100) 37 | nsec = (sec % 10000000) * 100 38 | sec /= 10000000 39 | return sec, nsec 40 | } 41 | 42 | // GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and 43 | // clock sequence as well as adjusting the clock sequence as needed. An error 44 | // is returned if the current time cannot be determined. 45 | func GetTime() (Time, uint16, error) { 46 | defer timeMu.Unlock() 47 | timeMu.Lock() 48 | return getTime() 49 | } 50 | 51 | func getTime() (Time, uint16, error) { 52 | t := timeNow() 53 | 54 | // If we don't have a clock sequence already, set one. 55 | if clockSeq == 0 { 56 | setClockSequence(-1) 57 | } 58 | now := uint64(t.UnixNano()/100) + g1582ns100 59 | 60 | // If time has gone backwards with this clock sequence then we 61 | // increment the clock sequence 62 | if now <= lasttime { 63 | clockSeq = ((clockSeq + 1) & 0x3fff) | 0x8000 64 | } 65 | lasttime = now 66 | return Time(now), clockSeq, nil 67 | } 68 | 69 | // ClockSequence returns the current clock sequence, generating one if not 70 | // already set. The clock sequence is only used for Version 1 UUIDs. 71 | // 72 | // The uuid package does not use global static storage for the clock sequence or 73 | // the last time a UUID was generated. Unless SetClockSequence is used, a new 74 | // random clock sequence is generated the first time a clock sequence is 75 | // requested by ClockSequence, GetTime, or NewUUID. (section 4.2.1.1) 76 | func ClockSequence() int { 77 | defer timeMu.Unlock() 78 | timeMu.Lock() 79 | return clockSequence() 80 | } 81 | 82 | func clockSequence() int { 83 | if clockSeq == 0 { 84 | setClockSequence(-1) 85 | } 86 | return int(clockSeq & 0x3fff) 87 | } 88 | 89 | // SetClockSeq sets the clock sequence to the lower 14 bits of seq. Setting to 90 | // -1 causes a new sequence to be generated. 91 | func SetClockSequence(seq int) { 92 | defer timeMu.Unlock() 93 | timeMu.Lock() 94 | setClockSequence(seq) 95 | } 96 | 97 | func setClockSequence(seq int) { 98 | if seq == -1 { 99 | var b [2]byte 100 | randomBits(b[:]) // clock sequence 101 | seq = int(b[0])<<8 | int(b[1]) 102 | } 103 | old_seq := clockSeq 104 | clockSeq = uint16(seq&0x3fff) | 0x8000 // Set our variant 105 | if old_seq != clockSeq { 106 | lasttime = 0 107 | } 108 | } 109 | 110 | // Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in 111 | // uuid. The time is only defined for version 1 and 2 UUIDs. 112 | func (uuid UUID) Time() Time { 113 | time := int64(binary.BigEndian.Uint32(uuid[0:4])) 114 | time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32 115 | time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48 116 | return Time(time) 117 | } 118 | 119 | // ClockSequence returns the clock sequence encoded in uuid. 120 | // The clock sequence is only well defined for version 1 and 2 UUIDs. 121 | func (uuid UUID) ClockSequence() int { 122 | return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "io" 9 | ) 10 | 11 | // randomBits completely fills slice b with random data. 12 | func randomBits(b []byte) { 13 | if _, err := io.ReadFull(rander, b); err != nil { 14 | panic(err.Error()) // rand should never fail 15 | } 16 | } 17 | 18 | // xvalues returns the value of a byte as a hexadecimal digit or 255. 19 | var xvalues = [256]byte{ 20 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 21 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 22 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 23 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, 24 | 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 25 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 26 | 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 27 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 28 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 29 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 30 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 31 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 32 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 33 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 34 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 35 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 36 | } 37 | 38 | // xtob converts hex characters x1 and x2 into a byte. 39 | func xtob(x1, x2 byte) (byte, bool) { 40 | b1 := xvalues[x1] 41 | b2 := xvalues[x2] 42 | return (b1 << 4) | b2, b1 != 255 && b2 != 255 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/version1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import ( 8 | "encoding/binary" 9 | ) 10 | 11 | // NewUUID returns a Version 1 UUID based on the current NodeID and clock 12 | // sequence, and the current time. If the NodeID has not been set by SetNodeID 13 | // or SetNodeInterface then it will be set automatically. If the NodeID cannot 14 | // be set NewUUID returns nil. If clock sequence has not been set by 15 | // SetClockSequence then it will be set automatically. If GetTime fails to 16 | // return the current NewUUID returns Nil and an error. 17 | // 18 | // In most cases, New should be used. 19 | func NewUUID() (UUID, error) { 20 | nodeMu.Lock() 21 | if nodeID == zeroID { 22 | setNodeInterface("") 23 | } 24 | nodeMu.Unlock() 25 | 26 | var uuid UUID 27 | now, seq, err := GetTime() 28 | if err != nil { 29 | return uuid, err 30 | } 31 | 32 | timeLow := uint32(now & 0xffffffff) 33 | timeMid := uint16((now >> 32) & 0xffff) 34 | timeHi := uint16((now >> 48) & 0x0fff) 35 | timeHi |= 0x1000 // Version 1 36 | 37 | binary.BigEndian.PutUint32(uuid[0:], timeLow) 38 | binary.BigEndian.PutUint16(uuid[4:], timeMid) 39 | binary.BigEndian.PutUint16(uuid[6:], timeHi) 40 | binary.BigEndian.PutUint16(uuid[8:], seq) 41 | copy(uuid[10:], nodeID[:]) 42 | 43 | return uuid, nil 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/google/uuid/version4.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package uuid 6 | 7 | import "io" 8 | 9 | // New is creates a new random UUID or panics. New is equivalent to 10 | // the expression 11 | // 12 | // uuid.Must(uuid.NewRandom()) 13 | func New() UUID { 14 | return Must(NewRandom()) 15 | } 16 | 17 | // NewRandom returns a Random (Version 4) UUID or panics. 18 | // 19 | // The strength of the UUIDs is based on the strength of the crypto/rand 20 | // package. 21 | // 22 | // A note about uniqueness derived from from the UUID Wikipedia entry: 23 | // 24 | // Randomly generated UUIDs have 122 random bits. One's annual risk of being 25 | // hit by a meteorite is estimated to be one chance in 17 billion, that 26 | // means the probability is about 0.00000000006 (6 × 10−11), 27 | // equivalent to the odds of creating a few tens of trillions of UUIDs in a 28 | // year and having one duplicate. 29 | func NewRandom() (UUID, error) { 30 | var uuid UUID 31 | _, err := io.ReadFull(rander, uuid[:]) 32 | if err != nil { 33 | return Nil, err 34 | } 35 | uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4 36 | uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10 37 | return uuid, nil 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/.gitignore: -------------------------------------------------------------------------------- 1 | jpgo 2 | jmespath-fuzz.zip 3 | cpu.out 4 | go-jmespath.test 5 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | sudo: false 4 | 5 | go: 6 | - 1.4 7 | 8 | install: go get -v -t ./... 9 | script: make test 10 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 James Saryerwinnie 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CMD = jpgo 3 | 4 | help: 5 | @echo "Please use \`make ' where is one of" 6 | @echo " test to run all the tests" 7 | @echo " build to build the library and jp executable" 8 | @echo " generate to run codegen" 9 | 10 | 11 | generate: 12 | go generate ./... 13 | 14 | build: 15 | rm -f $(CMD) 16 | go build ./... 17 | rm -f cmd/$(CMD)/$(CMD) && cd cmd/$(CMD)/ && go build ./... 18 | mv cmd/$(CMD)/$(CMD) . 19 | 20 | test: 21 | go test -v ./... 22 | 23 | check: 24 | go vet ./... 25 | @echo "golint ./..." 26 | @lint=`golint ./...`; \ 27 | lint=`echo "$$lint" | grep -v "astnodetype_string.go" | grep -v "toktype_string.go"`; \ 28 | echo "$$lint"; \ 29 | if [ "$$lint" != "" ]; then exit 1; fi 30 | 31 | htmlc: 32 | go test -coverprofile="/tmp/jpcov" && go tool cover -html="/tmp/jpcov" && unlink /tmp/jpcov 33 | 34 | buildfuzz: 35 | go-fuzz-build github.com/jmespath/go-jmespath/fuzz 36 | 37 | fuzz: buildfuzz 38 | go-fuzz -bin=./jmespath-fuzz.zip -workdir=fuzz/testdata 39 | 40 | bench: 41 | go test -bench . -cpuprofile cpu.out 42 | 43 | pprof-cpu: 44 | go tool pprof ./go-jmespath.test ./cpu.out 45 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/README.md: -------------------------------------------------------------------------------- 1 | # go-jmespath - A JMESPath implementation in Go 2 | 3 | [![Build Status](https://img.shields.io/travis/jmespath/go-jmespath.svg)](https://travis-ci.org/jmespath/go-jmespath) 4 | 5 | 6 | 7 | See http://jmespath.org for more info. 8 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/api.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import "strconv" 4 | 5 | // JmesPath is the epresentation of a compiled JMES path query. A JmesPath is 6 | // safe for concurrent use by multiple goroutines. 7 | type JMESPath struct { 8 | ast ASTNode 9 | intr *treeInterpreter 10 | } 11 | 12 | // Compile parses a JMESPath expression and returns, if successful, a JMESPath 13 | // object that can be used to match against data. 14 | func Compile(expression string) (*JMESPath, error) { 15 | parser := NewParser() 16 | ast, err := parser.Parse(expression) 17 | if err != nil { 18 | return nil, err 19 | } 20 | jmespath := &JMESPath{ast: ast, intr: newInterpreter()} 21 | return jmespath, nil 22 | } 23 | 24 | // MustCompile is like Compile but panics if the expression cannot be parsed. 25 | // It simplifies safe initialization of global variables holding compiled 26 | // JMESPaths. 27 | func MustCompile(expression string) *JMESPath { 28 | jmespath, err := Compile(expression) 29 | if err != nil { 30 | panic(`jmespath: Compile(` + strconv.Quote(expression) + `): ` + err.Error()) 31 | } 32 | return jmespath 33 | } 34 | 35 | // Search evaluates a JMESPath expression against input data and returns the result. 36 | func (jp *JMESPath) Search(data interface{}) (interface{}, error) { 37 | return jp.intr.Execute(jp.ast, data) 38 | } 39 | 40 | // Search evaluates a JMESPath expression against input data and returns the result. 41 | func Search(expression string, data interface{}) (interface{}, error) { 42 | intr := newInterpreter() 43 | parser := NewParser() 44 | ast, err := parser.Parse(expression) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return intr.Execute(ast, data) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/astnodetype_string.go: -------------------------------------------------------------------------------- 1 | // generated by stringer -type astNodeType; DO NOT EDIT 2 | 3 | package jmespath 4 | 5 | import "fmt" 6 | 7 | const _astNodeType_name = "ASTEmptyASTComparatorASTCurrentNodeASTExpRefASTFunctionExpressionASTFieldASTFilterProjectionASTFlattenASTIdentityASTIndexASTIndexExpressionASTKeyValPairASTLiteralASTMultiSelectHashASTMultiSelectListASTOrExpressionASTAndExpressionASTNotExpressionASTPipeASTProjectionASTSubexpressionASTSliceASTValueProjection" 8 | 9 | var _astNodeType_index = [...]uint16{0, 8, 21, 35, 44, 65, 73, 92, 102, 113, 121, 139, 152, 162, 180, 198, 213, 229, 245, 252, 265, 281, 289, 307} 10 | 11 | func (i astNodeType) String() string { 12 | if i < 0 || i >= astNodeType(len(_astNodeType_index)-1) { 13 | return fmt.Sprintf("astNodeType(%d)", i) 14 | } 15 | return _astNodeType_name[_astNodeType_index[i]:_astNodeType_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/jmespath/go-jmespath/toktype_string.go: -------------------------------------------------------------------------------- 1 | // generated by stringer -type=tokType; DO NOT EDIT 2 | 3 | package jmespath 4 | 5 | import "fmt" 6 | 7 | const _tokType_name = "tUnknowntStartDottFiltertFlattentLparentRparentLbrackettRbrackettLbracetRbracetOrtPipetNumbertUnquotedIdentifiertQuotedIdentifiertCommatColontLTtLTEtGTtGTEtEQtNEtJSONLiteraltStringLiteraltCurrenttExpreftAndtNottEOF" 8 | 9 | var _tokType_index = [...]uint8{0, 8, 13, 17, 24, 32, 39, 46, 55, 64, 71, 78, 81, 86, 93, 112, 129, 135, 141, 144, 148, 151, 155, 158, 161, 173, 187, 195, 202, 206, 210, 214} 10 | 11 | func (i tokType) String() string { 12 | if i < 0 || i >= tokType(len(_tokType_index)-1) { 13 | return fmt.Sprintf("tokType(%d)", i) 14 | } 15 | return _tokType_name[_tokType_index[i]:_tokType_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ project files 2 | .idea/ 3 | opentracing-go.iml 4 | opentracing-go.ipr 5 | opentracing-go.iws 6 | 7 | # Test results 8 | *.cov 9 | *.html 10 | test.log 11 | 12 | # Build dir 13 | build/ 14 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.6 5 | - 1.7 6 | - 1.8 7 | - tip 8 | 9 | install: 10 | - go get -d -t github.com/opentracing/opentracing-go/... 11 | - go get -u github.com/golang/lint/... 12 | script: 13 | - make test lint 14 | - go build ./... 15 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changes by Version 2 | ================== 3 | 4 | 1.1.0 (unreleased) 5 | ------------------- 6 | 7 | - Deprecate InitGlobalTracer() in favor of SetGlobalTracer() 8 | 9 | 10 | 1.0.0 (2016-09-26) 11 | ------------------- 12 | 13 | - This release implements OpenTracing Specification 1.0 (http://opentracing.io/spec) 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 The OpenTracing Authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/Makefile: -------------------------------------------------------------------------------- 1 | PACKAGES := . ./mocktracer/... ./ext/... 2 | 3 | .DEFAULT_GOAL := test-and-lint 4 | 5 | .PHONE: test-and-lint 6 | 7 | test-and-lint: test lint 8 | 9 | .PHONY: test 10 | test: 11 | go test -v -cover ./... 12 | 13 | cover: 14 | @rm -rf cover-all.out 15 | $(foreach pkg, $(PACKAGES), $(MAKE) cover-pkg PKG=$(pkg) || true;) 16 | @grep mode: cover.out > coverage.out 17 | @cat cover-all.out >> coverage.out 18 | go tool cover -html=coverage.out -o cover.html 19 | @rm -rf cover.out cover-all.out coverage.out 20 | 21 | cover-pkg: 22 | go test -coverprofile cover.out $(PKG) 23 | @grep -v mode: cover.out >> cover-all.out 24 | 25 | .PHONY: lint 26 | lint: 27 | go fmt ./... 28 | golint ./... 29 | @# Run again with magic to exit non-zero if golint outputs anything. 30 | @! (golint ./... | read dummy) 31 | go vet ./... 32 | 33 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/globaltracer.go: -------------------------------------------------------------------------------- 1 | package opentracing 2 | 3 | var ( 4 | globalTracer Tracer = NoopTracer{} 5 | ) 6 | 7 | // SetGlobalTracer sets the [singleton] opentracing.Tracer returned by 8 | // GlobalTracer(). Those who use GlobalTracer (rather than directly manage an 9 | // opentracing.Tracer instance) should call SetGlobalTracer as early as 10 | // possible in main(), prior to calling the `StartSpan` global func below. 11 | // Prior to calling `SetGlobalTracer`, any Spans started via the `StartSpan` 12 | // (etc) globals are noops. 13 | func SetGlobalTracer(tracer Tracer) { 14 | globalTracer = tracer 15 | } 16 | 17 | // GlobalTracer returns the global singleton `Tracer` implementation. 18 | // Before `SetGlobalTracer()` is called, the `GlobalTracer()` is a noop 19 | // implementation that drops all data handed to it. 20 | func GlobalTracer() Tracer { 21 | return globalTracer 22 | } 23 | 24 | // StartSpan defers to `Tracer.StartSpan`. See `GlobalTracer()`. 25 | func StartSpan(operationName string, opts ...StartSpanOption) Span { 26 | return globalTracer.StartSpan(operationName, opts...) 27 | } 28 | 29 | // InitGlobalTracer is deprecated. Please use SetGlobalTracer. 30 | func InitGlobalTracer(tracer Tracer) { 31 | SetGlobalTracer(tracer) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/gocontext.go: -------------------------------------------------------------------------------- 1 | package opentracing 2 | 3 | import "golang.org/x/net/context" 4 | 5 | type contextKey struct{} 6 | 7 | var activeSpanKey = contextKey{} 8 | 9 | // ContextWithSpan returns a new `context.Context` that holds a reference to 10 | // `span`'s SpanContext. 11 | func ContextWithSpan(ctx context.Context, span Span) context.Context { 12 | return context.WithValue(ctx, activeSpanKey, span) 13 | } 14 | 15 | // SpanFromContext returns the `Span` previously associated with `ctx`, or 16 | // `nil` if no such `Span` could be found. 17 | // 18 | // NOTE: context.Context != SpanContext: the former is Go's intra-process 19 | // context propagation mechanism, and the latter houses OpenTracing's per-Span 20 | // identity and baggage information. 21 | func SpanFromContext(ctx context.Context) Span { 22 | val := ctx.Value(activeSpanKey) 23 | if sp, ok := val.(Span); ok { 24 | return sp 25 | } 26 | return nil 27 | } 28 | 29 | // StartSpanFromContext starts and returns a Span with `operationName`, using 30 | // any Span found within `ctx` as a ChildOfRef. If no such parent could be 31 | // found, StartSpanFromContext creates a root (parentless) Span. 32 | // 33 | // The second return value is a context.Context object built around the 34 | // returned Span. 35 | // 36 | // Example usage: 37 | // 38 | // SomeFunction(ctx context.Context, ...) { 39 | // sp, ctx := opentracing.StartSpanFromContext(ctx, "SomeFunction") 40 | // defer sp.Finish() 41 | // ... 42 | // } 43 | func StartSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context) { 44 | return startSpanFromContextWithTracer(ctx, GlobalTracer(), operationName, opts...) 45 | } 46 | 47 | // startSpanFromContextWithTracer is factored out for testing purposes. 48 | func startSpanFromContextWithTracer(ctx context.Context, tracer Tracer, operationName string, opts ...StartSpanOption) (Span, context.Context) { 49 | var span Span 50 | if parentSpan := SpanFromContext(ctx); parentSpan != nil { 51 | opts = append(opts, ChildOf(parentSpan.Context())) 52 | span = tracer.StartSpan(operationName, opts...) 53 | } else { 54 | span = tracer.StartSpan(operationName, opts...) 55 | } 56 | return span, ContextWithSpan(ctx, span) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/log/util.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import "fmt" 4 | 5 | // InterleavedKVToFields converts keyValues a la Span.LogKV() to a Field slice 6 | // a la Span.LogFields(). 7 | func InterleavedKVToFields(keyValues ...interface{}) ([]Field, error) { 8 | if len(keyValues)%2 != 0 { 9 | return nil, fmt.Errorf("non-even keyValues len: %d", len(keyValues)) 10 | } 11 | fields := make([]Field, len(keyValues)/2) 12 | for i := 0; i*2 < len(keyValues); i++ { 13 | key, ok := keyValues[i*2].(string) 14 | if !ok { 15 | return nil, fmt.Errorf( 16 | "non-string key (pair #%d): %T", 17 | i, keyValues[i*2]) 18 | } 19 | switch typedVal := keyValues[i*2+1].(type) { 20 | case bool: 21 | fields[i] = Bool(key, typedVal) 22 | case string: 23 | fields[i] = String(key, typedVal) 24 | case int: 25 | fields[i] = Int(key, typedVal) 26 | case int8: 27 | fields[i] = Int32(key, int32(typedVal)) 28 | case int16: 29 | fields[i] = Int32(key, int32(typedVal)) 30 | case int32: 31 | fields[i] = Int32(key, typedVal) 32 | case int64: 33 | fields[i] = Int64(key, typedVal) 34 | case uint: 35 | fields[i] = Uint64(key, uint64(typedVal)) 36 | case uint64: 37 | fields[i] = Uint64(key, typedVal) 38 | case uint8: 39 | fields[i] = Uint32(key, uint32(typedVal)) 40 | case uint16: 41 | fields[i] = Uint32(key, uint32(typedVal)) 42 | case uint32: 43 | fields[i] = Uint32(key, typedVal) 44 | case float32: 45 | fields[i] = Float32(key, typedVal) 46 | case float64: 47 | fields[i] = Float64(key, typedVal) 48 | default: 49 | // When in doubt, coerce to a string 50 | fields[i] = String(key, fmt.Sprint(typedVal)) 51 | } 52 | } 53 | return fields, nil 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/mocktracer/mocklogrecord.go: -------------------------------------------------------------------------------- 1 | package mocktracer 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "time" 7 | 8 | "github.com/opentracing/opentracing-go/log" 9 | ) 10 | 11 | // MockLogRecord represents data logged to a Span via Span.LogFields or 12 | // Span.LogKV. 13 | type MockLogRecord struct { 14 | Timestamp time.Time 15 | Fields []MockKeyValue 16 | } 17 | 18 | // MockKeyValue represents a single key:value pair. 19 | type MockKeyValue struct { 20 | Key string 21 | 22 | // All MockLogRecord values are coerced to strings via fmt.Sprint(), though 23 | // we retain their type separately. 24 | ValueKind reflect.Kind 25 | ValueString string 26 | } 27 | 28 | // EmitString belongs to the log.Encoder interface 29 | func (m *MockKeyValue) EmitString(key, value string) { 30 | m.Key = key 31 | m.ValueKind = reflect.TypeOf(value).Kind() 32 | m.ValueString = fmt.Sprint(value) 33 | } 34 | 35 | // EmitBool belongs to the log.Encoder interface 36 | func (m *MockKeyValue) EmitBool(key string, value bool) { 37 | m.Key = key 38 | m.ValueKind = reflect.TypeOf(value).Kind() 39 | m.ValueString = fmt.Sprint(value) 40 | } 41 | 42 | // EmitInt belongs to the log.Encoder interface 43 | func (m *MockKeyValue) EmitInt(key string, value int) { 44 | m.Key = key 45 | m.ValueKind = reflect.TypeOf(value).Kind() 46 | m.ValueString = fmt.Sprint(value) 47 | } 48 | 49 | // EmitInt32 belongs to the log.Encoder interface 50 | func (m *MockKeyValue) EmitInt32(key string, value int32) { 51 | m.Key = key 52 | m.ValueKind = reflect.TypeOf(value).Kind() 53 | m.ValueString = fmt.Sprint(value) 54 | } 55 | 56 | // EmitInt64 belongs to the log.Encoder interface 57 | func (m *MockKeyValue) EmitInt64(key string, value int64) { 58 | m.Key = key 59 | m.ValueKind = reflect.TypeOf(value).Kind() 60 | m.ValueString = fmt.Sprint(value) 61 | } 62 | 63 | // EmitUint32 belongs to the log.Encoder interface 64 | func (m *MockKeyValue) EmitUint32(key string, value uint32) { 65 | m.Key = key 66 | m.ValueKind = reflect.TypeOf(value).Kind() 67 | m.ValueString = fmt.Sprint(value) 68 | } 69 | 70 | // EmitUint64 belongs to the log.Encoder interface 71 | func (m *MockKeyValue) EmitUint64(key string, value uint64) { 72 | m.Key = key 73 | m.ValueKind = reflect.TypeOf(value).Kind() 74 | m.ValueString = fmt.Sprint(value) 75 | } 76 | 77 | // EmitFloat32 belongs to the log.Encoder interface 78 | func (m *MockKeyValue) EmitFloat32(key string, value float32) { 79 | m.Key = key 80 | m.ValueKind = reflect.TypeOf(value).Kind() 81 | m.ValueString = fmt.Sprint(value) 82 | } 83 | 84 | // EmitFloat64 belongs to the log.Encoder interface 85 | func (m *MockKeyValue) EmitFloat64(key string, value float64) { 86 | m.Key = key 87 | m.ValueKind = reflect.TypeOf(value).Kind() 88 | m.ValueString = fmt.Sprint(value) 89 | } 90 | 91 | // EmitObject belongs to the log.Encoder interface 92 | func (m *MockKeyValue) EmitObject(key string, value interface{}) { 93 | m.Key = key 94 | m.ValueKind = reflect.TypeOf(value).Kind() 95 | m.ValueString = fmt.Sprint(value) 96 | } 97 | 98 | // EmitLazyLogger belongs to the log.Encoder interface 99 | func (m *MockKeyValue) EmitLazyLogger(value log.LazyLogger) { 100 | var meta MockKeyValue 101 | value(&meta) 102 | m.Key = meta.Key 103 | m.ValueKind = meta.ValueKind 104 | m.ValueString = meta.ValueString 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/mocktracer/mocktracer.go: -------------------------------------------------------------------------------- 1 | package mocktracer 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/opentracing/opentracing-go" 7 | ) 8 | 9 | // New returns a MockTracer opentracing.Tracer implementation that's intended 10 | // to facilitate tests of OpenTracing instrumentation. 11 | func New() *MockTracer { 12 | t := &MockTracer{ 13 | finishedSpans: []*MockSpan{}, 14 | injectors: make(map[interface{}]Injector), 15 | extractors: make(map[interface{}]Extractor), 16 | } 17 | 18 | // register default injectors/extractors 19 | textPropagator := new(TextMapPropagator) 20 | t.RegisterInjector(opentracing.TextMap, textPropagator) 21 | t.RegisterExtractor(opentracing.TextMap, textPropagator) 22 | 23 | httpPropagator := &TextMapPropagator{HTTPHeaders: true} 24 | t.RegisterInjector(opentracing.HTTPHeaders, httpPropagator) 25 | t.RegisterExtractor(opentracing.HTTPHeaders, httpPropagator) 26 | 27 | return t 28 | } 29 | 30 | // MockTracer is only intended for testing OpenTracing instrumentation. 31 | // 32 | // It is entirely unsuitable for production use, but appropriate for tests 33 | // that want to verify tracing behavior in other frameworks/applications. 34 | type MockTracer struct { 35 | sync.RWMutex 36 | finishedSpans []*MockSpan 37 | injectors map[interface{}]Injector 38 | extractors map[interface{}]Extractor 39 | } 40 | 41 | // FinishedSpans returns all spans that have been Finish()'ed since the 42 | // MockTracer was constructed or since the last call to its Reset() method. 43 | func (t *MockTracer) FinishedSpans() []*MockSpan { 44 | t.RLock() 45 | defer t.RUnlock() 46 | spans := make([]*MockSpan, len(t.finishedSpans)) 47 | copy(spans, t.finishedSpans) 48 | return spans 49 | } 50 | 51 | // Reset clears the internally accumulated finished spans. Note that any 52 | // extant MockSpans will still append to finishedSpans when they Finish(), 53 | // even after a call to Reset(). 54 | func (t *MockTracer) Reset() { 55 | t.Lock() 56 | defer t.Unlock() 57 | t.finishedSpans = []*MockSpan{} 58 | } 59 | 60 | // StartSpan belongs to the Tracer interface. 61 | func (t *MockTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { 62 | sso := opentracing.StartSpanOptions{} 63 | for _, o := range opts { 64 | o.Apply(&sso) 65 | } 66 | return newMockSpan(t, operationName, sso) 67 | } 68 | 69 | // RegisterInjector registers injector for given format 70 | func (t *MockTracer) RegisterInjector(format interface{}, injector Injector) { 71 | t.injectors[format] = injector 72 | } 73 | 74 | // RegisterExtractor registers extractor for given format 75 | func (t *MockTracer) RegisterExtractor(format interface{}, extractor Extractor) { 76 | t.extractors[format] = extractor 77 | } 78 | 79 | // Inject belongs to the Tracer interface. 80 | func (t *MockTracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error { 81 | spanContext, ok := sm.(MockSpanContext) 82 | if !ok { 83 | return opentracing.ErrInvalidCarrier 84 | } 85 | injector, ok := t.injectors[format] 86 | if !ok { 87 | return opentracing.ErrUnsupportedFormat 88 | } 89 | return injector.Inject(spanContext, carrier) 90 | } 91 | 92 | // Extract belongs to the Tracer interface. 93 | func (t *MockTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) { 94 | extractor, ok := t.extractors[format] 95 | if !ok { 96 | return nil, opentracing.ErrUnsupportedFormat 97 | } 98 | return extractor.Extract(carrier) 99 | } 100 | 101 | func (t *MockTracer) recordSpan(span *MockSpan) { 102 | t.Lock() 103 | defer t.Unlock() 104 | t.finishedSpans = append(t.finishedSpans, span) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/mocktracer/propagation.go: -------------------------------------------------------------------------------- 1 | package mocktracer 2 | 3 | import ( 4 | "fmt" 5 | "net/url" 6 | "strconv" 7 | "strings" 8 | 9 | "github.com/opentracing/opentracing-go" 10 | ) 11 | 12 | const mockTextMapIdsPrefix = "mockpfx-ids-" 13 | const mockTextMapBaggagePrefix = "mockpfx-baggage-" 14 | 15 | var emptyContext = MockSpanContext{} 16 | 17 | // Injector is responsible for injecting SpanContext instances in a manner suitable 18 | // for propagation via a format-specific "carrier" object. Typically the 19 | // injection will take place across an RPC boundary, but message queues and 20 | // other IPC mechanisms are also reasonable places to use an Injector. 21 | type Injector interface { 22 | // Inject takes `SpanContext` and injects it into `carrier`. The actual type 23 | // of `carrier` depends on the `format` passed to `Tracer.Inject()`. 24 | // 25 | // Implementations may return opentracing.ErrInvalidCarrier or any other 26 | // implementation-specific error if injection fails. 27 | Inject(ctx MockSpanContext, carrier interface{}) error 28 | } 29 | 30 | // Extractor is responsible for extracting SpanContext instances from a 31 | // format-specific "carrier" object. Typically the extraction will take place 32 | // on the server side of an RPC boundary, but message queues and other IPC 33 | // mechanisms are also reasonable places to use an Extractor. 34 | type Extractor interface { 35 | // Extract decodes a SpanContext instance from the given `carrier`, 36 | // or (nil, opentracing.ErrSpanContextNotFound) if no context could 37 | // be found in the `carrier`. 38 | Extract(carrier interface{}) (MockSpanContext, error) 39 | } 40 | 41 | // TextMapPropagator implements Injector/Extractor for TextMap and HTTPHeaders formats. 42 | type TextMapPropagator struct { 43 | HTTPHeaders bool 44 | } 45 | 46 | // Inject implements the Injector interface 47 | func (t *TextMapPropagator) Inject(spanContext MockSpanContext, carrier interface{}) error { 48 | writer, ok := carrier.(opentracing.TextMapWriter) 49 | if !ok { 50 | return opentracing.ErrInvalidCarrier 51 | } 52 | // Ids: 53 | writer.Set(mockTextMapIdsPrefix+"traceid", strconv.Itoa(spanContext.TraceID)) 54 | writer.Set(mockTextMapIdsPrefix+"spanid", strconv.Itoa(spanContext.SpanID)) 55 | writer.Set(mockTextMapIdsPrefix+"sampled", fmt.Sprint(spanContext.Sampled)) 56 | // Baggage: 57 | for baggageKey, baggageVal := range spanContext.Baggage { 58 | safeVal := baggageVal 59 | if t.HTTPHeaders { 60 | safeVal = url.QueryEscape(baggageVal) 61 | } 62 | writer.Set(mockTextMapBaggagePrefix+baggageKey, safeVal) 63 | } 64 | return nil 65 | } 66 | 67 | // Extract implements the Extractor interface 68 | func (t *TextMapPropagator) Extract(carrier interface{}) (MockSpanContext, error) { 69 | reader, ok := carrier.(opentracing.TextMapReader) 70 | if !ok { 71 | return emptyContext, opentracing.ErrInvalidCarrier 72 | } 73 | rval := MockSpanContext{0, 0, true, nil} 74 | err := reader.ForeachKey(func(key, val string) error { 75 | lowerKey := strings.ToLower(key) 76 | switch { 77 | case lowerKey == mockTextMapIdsPrefix+"traceid": 78 | // Ids: 79 | i, err := strconv.Atoi(val) 80 | if err != nil { 81 | return err 82 | } 83 | rval.TraceID = i 84 | case lowerKey == mockTextMapIdsPrefix+"spanid": 85 | // Ids: 86 | i, err := strconv.Atoi(val) 87 | if err != nil { 88 | return err 89 | } 90 | rval.SpanID = i 91 | case lowerKey == mockTextMapIdsPrefix+"sampled": 92 | b, err := strconv.ParseBool(val) 93 | if err != nil { 94 | return err 95 | } 96 | rval.Sampled = b 97 | case strings.HasPrefix(lowerKey, mockTextMapBaggagePrefix): 98 | // Baggage: 99 | if rval.Baggage == nil { 100 | rval.Baggage = make(map[string]string) 101 | } 102 | safeVal := val 103 | if t.HTTPHeaders { 104 | // unescape errors are ignored, nothing can be done 105 | if rawVal, err := url.QueryUnescape(val); err == nil { 106 | safeVal = rawVal 107 | } 108 | } 109 | rval.Baggage[lowerKey[len(mockTextMapBaggagePrefix):]] = safeVal 110 | } 111 | return nil 112 | }) 113 | if rval.TraceID == 0 || rval.SpanID == 0 { 114 | return emptyContext, opentracing.ErrSpanContextNotFound 115 | } 116 | if err != nil { 117 | return emptyContext, err 118 | } 119 | return rval, nil 120 | } 121 | -------------------------------------------------------------------------------- /vendor/github.com/opentracing/opentracing-go/noop.go: -------------------------------------------------------------------------------- 1 | package opentracing 2 | 3 | import "github.com/opentracing/opentracing-go/log" 4 | 5 | // A NoopTracer is a trivial, minimum overhead implementation of Tracer 6 | // for which all operations are no-ops. 7 | // 8 | // The primary use of this implementation is in libraries, such as RPC 9 | // frameworks, that make tracing an optional feature controlled by the 10 | // end user. A no-op implementation allows said libraries to use it 11 | // as the default Tracer and to write instrumentation that does 12 | // not need to keep checking if the tracer instance is nil. 13 | // 14 | // For the same reason, the NoopTracer is the default "global" tracer 15 | // (see GlobalTracer and SetGlobalTracer functions). 16 | // 17 | // WARNING: NoopTracer does not support baggage propagation. 18 | type NoopTracer struct{} 19 | 20 | type noopSpan struct{} 21 | type noopSpanContext struct{} 22 | 23 | var ( 24 | defaultNoopSpanContext = noopSpanContext{} 25 | defaultNoopSpan = noopSpan{} 26 | defaultNoopTracer = NoopTracer{} 27 | ) 28 | 29 | const ( 30 | emptyString = "" 31 | ) 32 | 33 | // noopSpanContext: 34 | func (n noopSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {} 35 | 36 | // noopSpan: 37 | func (n noopSpan) Context() SpanContext { return defaultNoopSpanContext } 38 | func (n noopSpan) SetBaggageItem(key, val string) Span { return defaultNoopSpan } 39 | func (n noopSpan) BaggageItem(key string) string { return emptyString } 40 | func (n noopSpan) SetTag(key string, value interface{}) Span { return n } 41 | func (n noopSpan) LogFields(fields ...log.Field) {} 42 | func (n noopSpan) LogKV(keyVals ...interface{}) {} 43 | func (n noopSpan) Finish() {} 44 | func (n noopSpan) FinishWithOptions(opts FinishOptions) {} 45 | func (n noopSpan) SetOperationName(operationName string) Span { return n } 46 | func (n noopSpan) Tracer() Tracer { return defaultNoopTracer } 47 | func (n noopSpan) LogEvent(event string) {} 48 | func (n noopSpan) LogEventWithPayload(event string, payload interface{}) {} 49 | func (n noopSpan) Log(data LogData) {} 50 | 51 | // StartSpan belongs to the Tracer interface. 52 | func (n NoopTracer) StartSpan(operationName string, opts ...StartSpanOption) Span { 53 | return defaultNoopSpan 54 | } 55 | 56 | // Inject belongs to the Tracer interface. 57 | func (n NoopTracer) Inject(sp SpanContext, format interface{}, carrier interface{}) error { 58 | return nil 59 | } 60 | 61 | // Extract belongs to the Tracer interface. 62 | func (n NoopTracer) Extract(format interface{}, carrier interface{}) (SpanContext, error) { 63 | return nil, ErrSpanContextNotFound 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell 2 | 3 | Please consider promoting this project if you find it useful. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 21 | OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 4 | } 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 4 | } 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/doc.go: -------------------------------------------------------------------------------- 1 | // Package require implements the same assertions as the `assert` package but 2 | // stops test execution when a test fails. 3 | // 4 | // Example Usage 5 | // 6 | // The following is a complete example using require in a standard test function: 7 | // import ( 8 | // "testing" 9 | // "github.com/stretchr/testify/require" 10 | // ) 11 | // 12 | // func TestSomething(t *testing.T) { 13 | // 14 | // var a string = "Hello" 15 | // var b string = "Hello" 16 | // 17 | // require.Equal(t, a, b, "The two words should be the same.") 18 | // 19 | // } 20 | // 21 | // Assertions 22 | // 23 | // The `require` package have same global functions as in the `assert` package, 24 | // but instead of returning a boolean result they call `t.FailNow()`. 25 | // 26 | // Every assertion function also takes an optional string message as the final argument, 27 | // allowing custom error messages to be appended to the message the assertion method outputs. 28 | package require 29 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/forward_requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.Comment}} 2 | func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { 3 | if !assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { 4 | t.FailNow() 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) { 3 | {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 4 | } 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // TestingT is an interface wrapper around *testing.T 4 | type TestingT interface { 5 | Errorf(format string, args ...interface{}) 6 | FailNow() 7 | } 8 | 9 | //go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl -include-format-funcs 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/context.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package context defines the Context type, which carries deadlines, 6 | // cancelation signals, and other request-scoped values across API boundaries 7 | // and between processes. 8 | // As of Go 1.7 this package is available in the standard library under the 9 | // name context. https://golang.org/pkg/context. 10 | // 11 | // Incoming requests to a server should create a Context, and outgoing calls to 12 | // servers should accept a Context. The chain of function calls between must 13 | // propagate the Context, optionally replacing it with a modified copy created 14 | // using WithDeadline, WithTimeout, WithCancel, or WithValue. 15 | // 16 | // Programs that use Contexts should follow these rules to keep interfaces 17 | // consistent across packages and enable static analysis tools to check context 18 | // propagation: 19 | // 20 | // Do not store Contexts inside a struct type; instead, pass a Context 21 | // explicitly to each function that needs it. The Context should be the first 22 | // parameter, typically named ctx: 23 | // 24 | // func DoSomething(ctx context.Context, arg Arg) error { 25 | // // ... use ctx ... 26 | // } 27 | // 28 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO 29 | // if you are unsure about which Context to use. 30 | // 31 | // Use context Values only for request-scoped data that transits processes and 32 | // APIs, not for passing optional parameters to functions. 33 | // 34 | // The same Context may be passed to functions running in different goroutines; 35 | // Contexts are safe for simultaneous use by multiple goroutines. 36 | // 37 | // See http://blog.golang.org/context for example code for a server that uses 38 | // Contexts. 39 | package context // import "golang.org/x/net/context" 40 | 41 | // Background returns a non-nil, empty Context. It is never canceled, has no 42 | // values, and has no deadline. It is typically used by the main function, 43 | // initialization, and tests, and as the top-level Context for incoming 44 | // requests. 45 | func Background() Context { 46 | return background 47 | } 48 | 49 | // TODO returns a non-nil, empty Context. Code should use context.TODO when 50 | // it's unclear which Context to use or it is not yet available (because the 51 | // surrounding function has not yet been extended to accept a Context 52 | // parameter). TODO is recognized by static analysis tools that determine 53 | // whether Contexts are propagated correctly in a program. 54 | func TODO() Context { 55 | return todo 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package context 8 | 9 | import ( 10 | "context" // standard library's context, as of Go 1.7 11 | "time" 12 | ) 13 | 14 | var ( 15 | todo = context.TODO() 16 | background = context.Background() 17 | ) 18 | 19 | // Canceled is the error returned by Context.Err when the context is canceled. 20 | var Canceled = context.Canceled 21 | 22 | // DeadlineExceeded is the error returned by Context.Err when the context's 23 | // deadline passes. 24 | var DeadlineExceeded = context.DeadlineExceeded 25 | 26 | // WithCancel returns a copy of parent with a new Done channel. The returned 27 | // context's Done channel is closed when the returned cancel function is called 28 | // or when the parent context's Done channel is closed, whichever happens first. 29 | // 30 | // Canceling this context releases resources associated with it, so code should 31 | // call cancel as soon as the operations running in this Context complete. 32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { 33 | ctx, f := context.WithCancel(parent) 34 | return ctx, CancelFunc(f) 35 | } 36 | 37 | // WithDeadline returns a copy of the parent context with the deadline adjusted 38 | // to be no later than d. If the parent's deadline is already earlier than d, 39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned 40 | // context's Done channel is closed when the deadline expires, when the returned 41 | // cancel function is called, or when the parent context's Done channel is 42 | // closed, whichever happens first. 43 | // 44 | // Canceling this context releases resources associated with it, so code should 45 | // call cancel as soon as the operations running in this Context complete. 46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { 47 | ctx, f := context.WithDeadline(parent, deadline) 48 | return ctx, CancelFunc(f) 49 | } 50 | 51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). 52 | // 53 | // Canceling this context releases resources associated with it, so code should 54 | // call cancel as soon as the operations running in this Context complete: 55 | // 56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { 57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) 58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses 59 | // return slowOperation(ctx) 60 | // } 61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { 62 | return WithDeadline(parent, time.Now().Add(timeout)) 63 | } 64 | 65 | // WithValue returns a copy of parent in which the value associated with key is 66 | // val. 67 | // 68 | // Use context Values only for request-scoped data that transits processes and 69 | // APIs, not for passing optional parameters to functions. 70 | func WithValue(parent Context, key interface{}, val interface{}) Context { 71 | return context.WithValue(parent, key, val) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package context 8 | 9 | import "context" // standard library's context, as of Go 1.7 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context = context.Context 16 | 17 | // A CancelFunc tells an operation to abandon its work. 18 | // A CancelFunc does not wait for the work to stop. 19 | // After the first call, subsequent calls to a CancelFunc do nothing. 20 | type CancelFunc = context.CancelFunc 21 | --------------------------------------------------------------------------------