├── vendor ├── github.com │ ├── kr │ │ └── logfmt │ │ │ ├── .gitignore │ │ │ ├── Readme │ │ │ ├── bench_test.go │ │ │ ├── example_test.go │ │ │ └── scanner_test.go │ ├── go-logfmt │ │ └── logfmt │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── doc.go │ │ │ ├── LICENSE │ │ │ ├── example_test.go │ │ │ ├── decode-bench_test.go │ │ │ └── README.md │ ├── alecthomas │ │ ├── template │ │ │ ├── testdata │ │ │ │ ├── file1.tmpl │ │ │ │ ├── tmpl1.tmpl │ │ │ │ ├── tmpl2.tmpl │ │ │ │ └── file2.tmpl │ │ │ ├── README.md │ │ │ ├── LICENSE │ │ │ ├── examplefunc_test.go │ │ │ └── example_test.go │ │ └── units │ │ │ ├── README.md │ │ │ ├── doc.go │ │ │ ├── si.go │ │ │ ├── COPYING │ │ │ └── bytes_test.go │ ├── go-kit │ │ └── kit │ │ │ ├── transport │ │ │ ├── grpc │ │ │ │ ├── doc.go │ │ │ │ ├── _grpc_test │ │ │ │ │ ├── pb │ │ │ │ │ │ ├── generate.go │ │ │ │ │ │ └── test.proto │ │ │ │ │ ├── service.go │ │ │ │ │ ├── request_response.go │ │ │ │ │ ├── client.go │ │ │ │ │ └── server.go │ │ │ │ ├── client_test.go │ │ │ │ └── encode_decode.go │ │ │ ├── doc.go │ │ │ ├── http │ │ │ │ ├── doc.go │ │ │ │ ├── request_response_funcs_test.go │ │ │ │ ├── example_test.go │ │ │ │ └── encode_decode.go │ │ │ ├── httprp │ │ │ │ ├── doc.go │ │ │ │ └── server.go │ │ │ ├── netrpc │ │ │ │ └── README.md │ │ │ └── thrift │ │ │ │ └── README.md │ │ │ ├── util │ │ │ ├── conn │ │ │ │ └── doc.go │ │ │ └── README.md │ │ │ ├── sd │ │ │ ├── zk │ │ │ │ ├── doc.go │ │ │ │ ├── logwrapper.go │ │ │ │ └── registrar.go │ │ │ ├── consul │ │ │ │ ├── doc.go │ │ │ │ ├── registrar_test.go │ │ │ │ ├── registrar.go │ │ │ │ └── client.go │ │ │ ├── dnssrv │ │ │ │ ├── doc.go │ │ │ │ └── lookup.go │ │ │ ├── eureka │ │ │ │ └── doc.go │ │ │ ├── etcd │ │ │ │ ├── doc.go │ │ │ │ ├── instancer_test.go │ │ │ │ └── instancer.go │ │ │ ├── lb │ │ │ │ ├── doc.go │ │ │ │ ├── balancer.go │ │ │ │ ├── random.go │ │ │ │ ├── round_robin.go │ │ │ │ └── random_test.go │ │ │ ├── doc.go │ │ │ ├── registrar.go │ │ │ ├── factory.go │ │ │ ├── benchmark_test.go │ │ │ ├── instancer.go │ │ │ └── internal │ │ │ │ └── instance │ │ │ │ └── cache.go │ │ │ ├── log │ │ │ ├── term │ │ │ │ ├── terminal_openbsd.go │ │ │ │ ├── terminal_freebsd.go │ │ │ │ ├── terminal_darwin.go │ │ │ │ ├── colorwriter_others.go │ │ │ │ ├── terminal_linux.go │ │ │ │ ├── terminal_appengine.go │ │ │ │ ├── term.go │ │ │ │ ├── terminal_notwindows.go │ │ │ │ ├── LICENSE │ │ │ │ ├── example_test.go │ │ │ │ └── terminal_windows_test.go │ │ │ ├── nop_logger.go │ │ │ ├── benchmark_test.go │ │ │ ├── nop_logger_test.go │ │ │ ├── level │ │ │ │ ├── example_test.go │ │ │ │ ├── doc.go │ │ │ │ └── benchmark_test.go │ │ │ ├── concurrency_test.go │ │ │ ├── logfmt_logger.go │ │ │ ├── logfmt_logger_test.go │ │ │ ├── deprecated_levels │ │ │ │ └── levels_test.go │ │ │ └── sync_test.go │ │ │ ├── metrics │ │ │ ├── debug.test │ │ │ ├── internal │ │ │ │ ├── lv │ │ │ │ │ ├── labelvalues.go │ │ │ │ │ └── labelvalues_test.go │ │ │ │ └── ratemap │ │ │ │ │ └── ratemap.go │ │ │ ├── provider │ │ │ │ ├── discard.go │ │ │ │ ├── expvar.go │ │ │ │ ├── influx.go │ │ │ │ ├── graphite.go │ │ │ │ ├── statsd.go │ │ │ │ ├── dogstatsd.go │ │ │ │ └── provider.go │ │ │ ├── metrics.go │ │ │ ├── timer.go │ │ │ ├── discard │ │ │ │ └── discard.go │ │ │ ├── expvar │ │ │ │ └── expvar_test.go │ │ │ ├── timer_test.go │ │ │ └── pcp │ │ │ │ └── pcp_test.go │ │ │ ├── examples │ │ │ ├── README.md │ │ │ ├── profilesvc │ │ │ │ ├── README.md │ │ │ │ └── cmd │ │ │ │ │ └── profilesvc │ │ │ │ │ └── main.go │ │ │ ├── addsvc │ │ │ │ ├── thrift │ │ │ │ │ ├── gen-go │ │ │ │ │ │ └── addsvc │ │ │ │ │ │ │ ├── GoUnusedProtection__.go │ │ │ │ │ │ │ └── addsvc-consts.go │ │ │ │ │ ├── compile.sh │ │ │ │ │ └── addsvc.thrift │ │ │ │ ├── pb │ │ │ │ │ ├── compile.sh │ │ │ │ │ └── addsvc.proto │ │ │ │ ├── README.md │ │ │ │ ├── cmd │ │ │ │ │ └── addsvc │ │ │ │ │ │ ├── wiring_test.go │ │ │ │ │ │ └── pact_test.go │ │ │ │ └── pkg │ │ │ │ │ ├── addendpoint │ │ │ │ │ └── middleware.go │ │ │ │ │ └── addservice │ │ │ │ │ └── middleware.go │ │ │ ├── shipping │ │ │ │ ├── routing │ │ │ │ │ └── routing.go │ │ │ │ ├── tracking │ │ │ │ │ ├── logging.go │ │ │ │ │ ├── endpoint.go │ │ │ │ │ └── instrumenting.go │ │ │ │ ├── location │ │ │ │ │ ├── sample_locations.go │ │ │ │ │ └── location.go │ │ │ │ ├── handling │ │ │ │ │ ├── endpoint.go │ │ │ │ │ ├── logging.go │ │ │ │ │ └── instrumenting.go │ │ │ │ ├── voyage │ │ │ │ │ ├── voyage.go │ │ │ │ │ └── sample_voyages.go │ │ │ │ ├── inspection │ │ │ │ │ └── inspection.go │ │ │ │ └── README.md │ │ │ ├── stringsvc2 │ │ │ │ ├── service.go │ │ │ │ ├── logging.go │ │ │ │ ├── instrumenting.go │ │ │ │ ├── transport.go │ │ │ │ └── main.go │ │ │ └── stringsvc3 │ │ │ │ ├── service.go │ │ │ │ ├── logging.go │ │ │ │ └── instrumenting.go │ │ │ ├── endpoint │ │ │ ├── doc.go │ │ │ ├── endpoint.go │ │ │ └── endpoint_example_test.go │ │ │ ├── tracing │ │ │ ├── opentracing │ │ │ │ ├── doc.go │ │ │ │ └── endpoint.go │ │ │ └── doc.go │ │ │ ├── .travis.yml │ │ │ ├── circuitbreaker │ │ │ ├── doc.go │ │ │ ├── gobreaker_test.go │ │ │ ├── handy_breaker_test.go │ │ │ ├── gobreaker.go │ │ │ ├── hystrix.go │ │ │ ├── handy_breaker.go │ │ │ └── hystrix_test.go │ │ │ ├── ROADMAP.md │ │ │ ├── docker-compose-integration.yml │ │ │ ├── lint │ │ │ ├── coveralls.bash │ │ │ ├── update_deps.bash │ │ │ ├── .gitignore │ │ │ ├── CONTRIBUTING.md │ │ │ ├── auth │ │ │ └── basic │ │ │ │ ├── README.md │ │ │ │ └── middleware_test.go │ │ │ ├── LICENSE │ │ │ ├── circle.yml │ │ │ └── ratelimit │ │ │ └── token_bucket_test.go │ ├── pkg │ │ └── errors │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ ├── appveyor.yml │ │ │ ├── bench_test.go │ │ │ └── LICENSE │ ├── go-stack │ │ └── stack │ │ │ ├── .travis.yml │ │ │ ├── format_test.go │ │ │ ├── LICENSE.md │ │ │ ├── README.md │ │ │ └── stack-go19_test.go │ ├── gorilla │ │ ├── context │ │ │ ├── README.md │ │ │ ├── .travis.yml │ │ │ └── LICENSE │ │ └── mux │ │ │ ├── .travis.yml │ │ │ ├── context_native.go │ │ │ ├── context_gorilla.go │ │ │ ├── context_native_test.go │ │ │ ├── context_gorilla_test.go │ │ │ ├── LICENSE │ │ │ └── bench_test.go │ └── aybabtme │ │ └── log │ │ ├── README.md │ │ ├── LICENSE │ │ └── log.go └── gopkg.in │ └── alecthomas │ └── kingpin.v2 │ ├── .travis.yml │ ├── guesswidth.go │ ├── _examples │ ├── chat1 │ │ └── main.go │ ├── ping │ │ └── main.go │ ├── modular │ │ └── main.go │ └── chat2 │ │ └── main.go │ ├── guesswidth_unix.go │ ├── completions.go │ ├── envar.go │ ├── COPYING │ ├── actions.go │ ├── examples_test.go │ ├── usage_test.go │ └── values.json ├── Gopkg.toml └── cmd └── subdomainr └── main.go /vendor/github.com/kr/logfmt/.gitignore: -------------------------------------------------------------------------------- 1 | *.test 2 | *.swp 3 | *.prof 4 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/.gitignore: -------------------------------------------------------------------------------- 1 | _testdata/ 2 | _testdata2/ 3 | logfmt-fuzz.zip 4 | logfmt.test.exe 5 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/testdata/file1.tmpl: -------------------------------------------------------------------------------- 1 | {{define "x"}}TEXT{{end}} 2 | {{define "dotV"}}{{.V}}{{end}} 3 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/testdata/tmpl1.tmpl: -------------------------------------------------------------------------------- 1 | template1 2 | {{define "x"}}x{{end}} 3 | {{template "y"}} 4 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/testdata/tmpl2.tmpl: -------------------------------------------------------------------------------- 1 | template2 2 | {{define "y"}}y{{end}} 3 | {{template "x"}} 4 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/doc.go: -------------------------------------------------------------------------------- 1 | // Package grpc provides a gRPC binding for endpoints. 2 | package grpc 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/util/conn/doc.go: -------------------------------------------------------------------------------- 1 | // Package conn provides utilities related to connections. 2 | package conn 3 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | install: go get -t -v ./... 4 | go: 1.2 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/zk/doc.go: -------------------------------------------------------------------------------- 1 | // Package zk provides Instancer and Registrar implementations for ZooKeeper. 2 | package zk 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/doc.go: -------------------------------------------------------------------------------- 1 | // Package transport contains bindings to concrete transports. 2 | package transport 3 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/testdata/file2.tmpl: -------------------------------------------------------------------------------- 1 | {{define "dot"}}{{.}}{{end}} 2 | {{define "nested"}}{{template "dot" .}}{{end}} 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/http/doc.go: -------------------------------------------------------------------------------- 1 | // Package http provides a general purpose HTTP binding for endpoints. 2 | package http 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/consul/doc.go: -------------------------------------------------------------------------------- 1 | // Package consul provides Instancer and Registrar implementations for Consul. 2 | package consul 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/dnssrv/doc.go: -------------------------------------------------------------------------------- 1 | // Package dnssrv provides an Instancer implementation for DNS SRV records. 2 | package dnssrv 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_openbsd.go: -------------------------------------------------------------------------------- 1 | package term 2 | 3 | import "syscall" 4 | 5 | const ioctlReadTermios = syscall.TIOCGETA 6 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/pb/generate.go: -------------------------------------------------------------------------------- 1 | package pb 2 | 3 | //go:generate protoc test.proto --go_out=plugins=grpc:. 4 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/debug.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iheanyi/go-subdomains-example/master/vendor/github.com/go-kit/kit/metrics/debug.test -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/eureka/doc.go: -------------------------------------------------------------------------------- 1 | // Package eureka provides Instancer and Registrar implementations for Netflix OSS's Eureka 2 | package eureka 3 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_freebsd.go: -------------------------------------------------------------------------------- 1 | package term 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | const ioctlReadTermios = syscall.TIOCGETA 8 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | For more information about these examples, 4 | including a walkthrough of the stringsvc example, 5 | see [gokit.io/examples](https://gokit.io/examples). 6 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.4.3 5 | - 1.5.4 6 | - 1.6.2 7 | - 1.7.1 8 | - tip 9 | 10 | script: 11 | - go test -v ./... 12 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth.go: -------------------------------------------------------------------------------- 1 | // +build appengine !linux,!freebsd,!darwin,!dragonfly,!netbsd,!openbsd 2 | 3 | package kingpin 4 | 5 | import "io" 6 | 7 | func guessWidth(w io.Writer) int { 8 | return 80 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/profilesvc/README.md: -------------------------------------------------------------------------------- 1 | # profilesvc 2 | 3 | This example demonstrates how to use Go kit to implement a REST-y HTTP service. 4 | It leverages the excellent [gorilla mux package](https://github.com/gorilla/mux) for routing. 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/util/README.md: -------------------------------------------------------------------------------- 1 | # util 2 | 3 | This directory holds packages of general utility to multiple consumers within Go kit, 4 | and potentially other consumers in the wider Go ecosystem. 5 | There is no `package util` and will never be. 6 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | go: 4 | - 1.7 5 | - 1.8 6 | - 1.9 7 | - tip 8 | 9 | before_install: 10 | - go get github.com/mattn/goveralls 11 | 12 | script: 13 | - goveralls -service=travis-ci 14 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/endpoint/doc.go: -------------------------------------------------------------------------------- 1 | // Package endpoint defines an abstraction for RPCs. 2 | // 3 | // Endpoints are a fundamental building block for many Go kit components. 4 | // Endpoints are implemented by servers, and called by clients. 5 | package endpoint 6 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package addsvc 5 | 6 | var GoUnusedProtection__ int; 7 | 8 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/nop_logger.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | type nopLogger struct{} 4 | 5 | // NewNopLogger returns a logger that doesn't do anything. 6 | func NewNopLogger() Logger { return nopLogger{} } 7 | 8 | func (nopLogger) Log(...interface{}) error { return nil } 9 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/httprp/doc.go: -------------------------------------------------------------------------------- 1 | // Package httprp provides an HTTP reverse-proxy transport. HTTP handlers that 2 | // need to proxy requests to another HTTP service can do so with this package by 3 | // specifying the URL to forward the request to. 4 | package httprp 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/etcd/doc.go: -------------------------------------------------------------------------------- 1 | // Package etcd provides an Instancer and Registrar implementation for etcd. If 2 | // you use etcd as your service discovery system, this package will help you 3 | // implement the registration and client-side load balancing patterns. 4 | package etcd 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/lb/doc.go: -------------------------------------------------------------------------------- 1 | // Package lb implements the client-side load balancer pattern. When combined 2 | // with a service discovery system of record, it enables a more decentralized 3 | // architecture, removing the need for separate load balancers like HAProxy. 4 | package lb 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/thrift/compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # See also https://thrift.apache.org/tutorial/go 4 | 5 | thrift -r --gen "go:package_prefix=github.com/go-kit/kit/examples/addsvc/thrift/gen-go/,thrift_import=github.com/apache/thrift/lib/go/thrift" addsvc.thrift 6 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/dnssrv/lookup.go: -------------------------------------------------------------------------------- 1 | package dnssrv 2 | 3 | import "net" 4 | 5 | // Lookup is a function that resolves a DNS SRV record to multiple addresses. 6 | // It has the same signature as net.LookupSRV. 7 | type Lookup func(service, proto, name string) (cname string, addrs []*net.SRV, err error) 8 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/tracing/opentracing/doc.go: -------------------------------------------------------------------------------- 1 | // Package opentracing provides Go kit integration to the OpenTracing project. 2 | // OpenTracing implements a general purpose interface that microservices can 3 | // program against, and which adapts to all major distributed tracing systems. 4 | package opentracing 5 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | go: 4 | - 1.3 5 | - 1.4 6 | - 1.5 7 | - 1.6 8 | - tip 9 | 10 | before_install: 11 | - go get github.com/mattn/goveralls 12 | - go get golang.org/x/tools/cmd/cover 13 | 14 | script: 15 | - goveralls -service=travis-ci 16 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/thrift/addsvc.thrift: -------------------------------------------------------------------------------- 1 | struct SumReply { 2 | 1: i64 value 3 | 2: string err 4 | } 5 | 6 | struct ConcatReply { 7 | 1: string value 8 | 2: string err 9 | } 10 | 11 | service AddService { 12 | SumReply Sum(1: i64 a, 2: i64 b) 13 | ConcatReply Concat(1: string a, 2: string b) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/pb/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pb; 4 | 5 | service Test { 6 | rpc Test (TestRequest) returns (TestResponse) {} 7 | } 8 | 9 | message TestRequest { 10 | string a = 1; 11 | int64 b = 2; 12 | } 13 | 14 | message TestResponse { 15 | string v = 1; 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/context/README.md: -------------------------------------------------------------------------------- 1 | context 2 | ======= 3 | [![Build Status](https://travis-ci.org/gorilla/context.png?branch=master)](https://travis-ci.org/gorilla/context) 4 | 5 | gorilla/context is a general purpose registry for global request variables. 6 | 7 | Read the full documentation here: http://www.gorillatoolkit.org/pkg/context 8 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | env: 4 | - COVERALLS_TOKEN=MYSkSqcsWXd6DmP6TnSeiDhtvuL4u6ndp 5 | 6 | before_install: 7 | - go get github.com/mattn/goveralls 8 | - go get github.com/modocache/gover 9 | 10 | script: 11 | - go test -race -v ./... 12 | - ./coveralls.bash 13 | 14 | go: 15 | - 1.9.x 16 | - tip 17 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_darwin.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package term 7 | 8 | import "syscall" 9 | 10 | const ioctlReadTermios = syscall.TIOCGETA 11 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/units/README.md: -------------------------------------------------------------------------------- 1 | # Units - Helpful unit multipliers and functions for Go 2 | 3 | The goal of this package is to have functionality similar to the [time](http://golang.org/pkg/time/) package. 4 | 5 | It allows for code like this: 6 | 7 | ```go 8 | n, err := ParseBase2Bytes("1KB") 9 | // n == 1024 10 | n = units.Mebibyte * 512 11 | ``` 12 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/colorwriter_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package term 4 | 5 | import "io" 6 | 7 | // NewColorWriter returns an io.Writer that writes to w and provides cross 8 | // platform support for ANSI color codes. If w is not a terminal it is 9 | // returned unmodified. 10 | func NewColorWriter(w io.Writer) io.Writer { 11 | return w 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_linux.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build !appengine 7 | 8 | package term 9 | 10 | import "syscall" 11 | 12 | const ioctlReadTermios = syscall.TCGETS 13 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/service.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import "context" 4 | 5 | type Service interface { 6 | Test(ctx context.Context, a string, b int64) (context.Context, string, error) 7 | } 8 | 9 | type TestRequest struct { 10 | A string 11 | B int64 12 | } 13 | 14 | type TestResponse struct { 15 | Ctx context.Context 16 | V string 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/doc.go: -------------------------------------------------------------------------------- 1 | // Package logfmt implements utilities to marshal and unmarshal data in the 2 | // logfmt format. The logfmt format records key/value pairs in a way that 3 | // balances readability for humans and simplicity of computer parsing. It is 4 | // most commonly used as a more human friendly alternative to JSON for 5 | // structured logging. 6 | package logfmt 7 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/context/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | 4 | matrix: 5 | include: 6 | - go: 1.3 7 | - go: 1.4 8 | - go: 1.5 9 | - go: 1.6 10 | - go: tip 11 | 12 | install: 13 | - go get golang.org/x/tools/cmd/vet 14 | 15 | script: 16 | - go get -t -v ./... 17 | - diff -u <(echo -n) <(gofmt -d .) 18 | - go tool vet . 19 | - go test -v -race ./... 20 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/mux/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | 4 | matrix: 5 | include: 6 | - go: 1.5 7 | - go: 1.6 8 | - go: 1.7 9 | - go: 1.8 10 | - go: 1.9 11 | - go: tip 12 | allow_failures: 13 | - go: tip 14 | 15 | install: 16 | - # Skip 17 | 18 | script: 19 | - go get -t -v ./... 20 | - diff -u <(echo -n) <(gofmt -d .) 21 | - go tool vet . 22 | - go test -v -race ./... 23 | -------------------------------------------------------------------------------- /vendor/github.com/aybabtme/log/README.md: -------------------------------------------------------------------------------- 1 | # Structured logger 2 | 3 | Bare minimum structured logger. 4 | 5 | * Logs in JSON. 6 | * 3 log levels: info, error, fatal. 7 | * Reusable context logging 8 | 9 | ```go 10 | ll := log.KV("who", "world") 11 | ll.Info("hello?") 12 | 13 | if err := doThing(); err != nil { 14 | ll.Err(err).Error("this thing failed") 15 | } 16 | ll.KV("why", "no reason").Fatal("abort abort abort!") 17 | ``` 18 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/lb/balancer.go: -------------------------------------------------------------------------------- 1 | package lb 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/go-kit/kit/endpoint" 7 | ) 8 | 9 | // Balancer yields endpoints according to some heuristic. 10 | type Balancer interface { 11 | Endpoint() (endpoint.Endpoint, error) 12 | } 13 | 14 | // ErrNoEndpoints is returned when no qualifying endpoints are available. 15 | var ErrNoEndpoints = errors.New("no endpoints available") 16 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/units/doc.go: -------------------------------------------------------------------------------- 1 | // Package units provides helpful unit multipliers and functions for Go. 2 | // 3 | // The goal of this package is to have functionality similar to the time [1] package. 4 | // 5 | // 6 | // [1] http://golang.org/pkg/time/ 7 | // 8 | // It allows for code like this: 9 | // 10 | // n, err := ParseBase2Bytes("1KB") 11 | // // n == 1024 12 | // n = units.Mebibyte * 512 13 | package units 14 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/doc.go: -------------------------------------------------------------------------------- 1 | // Package sd provides utilities related to service discovery. That includes the 2 | // client-side loadbalancer pattern, where a microservice subscribes to a 3 | // service discovery system in order to reach remote instances; as well as the 4 | // registrator pattern, where a microservice registers itself in a service 5 | // discovery system. Implementations are provided for most common systems. 6 | package sd 7 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_appengine.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build appengine 7 | 8 | package term 9 | 10 | import "io" 11 | 12 | // IsTerminal always returns false on AppEngine. 13 | func IsTerminal(w io.Writer) bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/format_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.2 2 | 3 | package stack_test 4 | 5 | import ( 6 | "fmt" 7 | 8 | "github.com/go-stack/stack" 9 | ) 10 | 11 | func Example_callFormat() { 12 | logCaller("%+s") 13 | logCaller("%v %[1]n()") 14 | // Output: 15 | // github.com/go-stack/stack/format_test.go 16 | // format_test.go:13 Example_callFormat() 17 | } 18 | 19 | func logCaller(format string) { 20 | fmt.Printf(format+"\n", stack.Caller(1)) 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/tracing/doc.go: -------------------------------------------------------------------------------- 1 | // Package tracing provides helpers and bindings for distributed tracing. 2 | // 3 | // As your infrastructure grows, it becomes important to be able to trace a 4 | // request, as it travels through multiple services and back to the user. 5 | // Package tracing provides endpoints and transport helpers and middlewares to 6 | // capture and emit request-scoped information. We use the excellent OpenTracing 7 | // project to bind to concrete tracing systems. 8 | package tracing 9 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/pb/compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Install proto3 from source 4 | # brew install autoconf automake libtool 5 | # git clone https://github.com/google/protobuf 6 | # ./autogen.sh ; ./configure ; make ; make install 7 | # 8 | # Update protoc Go bindings via 9 | # go get -u github.com/golang/protobuf/{proto,protoc-gen-go} 10 | # 11 | # See also 12 | # https://github.com/grpc/grpc-go/tree/master/examples 13 | 14 | protoc addsvc.proto --go_out=plugins=grpc:. 15 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/mux/context_native.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package mux 4 | 5 | import ( 6 | "context" 7 | "net/http" 8 | ) 9 | 10 | func contextGet(r *http.Request, key interface{}) interface{} { 11 | return r.Context().Value(key) 12 | } 13 | 14 | func contextSet(r *http.Request, key, val interface{}) *http.Request { 15 | if val == nil { 16 | return r 17 | } 18 | 19 | return r.WithContext(context.WithValue(r.Context(), key, val)) 20 | } 21 | 22 | func contextClear(r *http.Request) { 23 | return 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/README.md: -------------------------------------------------------------------------------- 1 | # Go's `text/template` package with newline elision 2 | 3 | This is a fork of Go 1.4's [text/template](http://golang.org/pkg/text/template/) package with one addition: a backslash immediately after a closing delimiter will delete all subsequent newlines until a non-newline. 4 | 5 | eg. 6 | 7 | ``` 8 | {{if true}}\ 9 | hello 10 | {{end}}\ 11 | ``` 12 | 13 | Will result in: 14 | 15 | ``` 16 | hello\n 17 | ``` 18 | 19 | Rather than: 20 | 21 | ``` 22 | \n 23 | hello\n 24 | \n 25 | ``` 26 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/mux/context_gorilla.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package mux 4 | 5 | import ( 6 | "net/http" 7 | 8 | "github.com/gorilla/context" 9 | ) 10 | 11 | func contextGet(r *http.Request, key interface{}) interface{} { 12 | return context.Get(r, key) 13 | } 14 | 15 | func contextSet(r *http.Request, key, val interface{}) *http.Request { 16 | if val == nil { 17 | return r 18 | } 19 | 20 | context.Set(r, key, val) 21 | return r 22 | } 23 | 24 | func contextClear(r *http.Request) { 25 | context.Clear(r) 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/doc.go: -------------------------------------------------------------------------------- 1 | // Package circuitbreaker implements the circuit breaker pattern. 2 | // 3 | // Circuit breakers prevent thundering herds, and improve resiliency against 4 | // intermittent errors. Every client-side endpoint should be wrapped in a 5 | // circuit breaker. 6 | // 7 | // We provide several implementations in this package, but if you're looking 8 | // for guidance, Gobreaker is probably the best place to start. It has a 9 | // simple and intuitive API, and is well-tested. 10 | package circuitbreaker 11 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | 3 | This is a coarse-grained roadmap of Go kit development direction in the short 4 | to mid-term future. It will be kept reasonably up-to-date by the project 5 | maintainers. Suggest new ideas, enhancements, and features using the standard 6 | [issues](https://github.com/go-kit/kit/issues) model. 7 | 8 | ## Prioritized 9 | 10 | 1. kitgen code generation (#308, #70) 11 | 1. package pubsub (#298, #295) 12 | 13 | ## Unprioritized 14 | 15 | - package log/levels refactor (#250, #269, #252) 16 | - package auth/jwt (#255) 17 | 18 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/benchmark_test.go: -------------------------------------------------------------------------------- 1 | package log_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/go-kit/kit/log" 7 | ) 8 | 9 | func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) { 10 | lc := log.With(logger, "common_key", "common_value") 11 | b.ReportAllocs() 12 | b.ResetTimer() 13 | for i := 0; i < b.N; i++ { 14 | f(lc) 15 | } 16 | } 17 | 18 | var ( 19 | baseMessage = func(logger log.Logger) { logger.Log("foo_key", "foo_value") } 20 | withMessage = func(logger log.Logger) { log.With(logger, "a", "b").Log("c", "d") } 21 | ) 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/internal/lv/labelvalues.go: -------------------------------------------------------------------------------- 1 | package lv 2 | 3 | // LabelValues is a type alias that provides validation on its With method. 4 | // Metrics may include it as a member to help them satisfy With semantics and 5 | // save some code duplication. 6 | type LabelValues []string 7 | 8 | // With validates the input, and returns a new aggregate labelValues. 9 | func (lvs LabelValues) With(labelValues ...string) LabelValues { 10 | if len(labelValues)%2 != 0 { 11 | labelValues = append(labelValues, "unknown") 12 | } 13 | return append(lvs, labelValues...) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/registrar.go: -------------------------------------------------------------------------------- 1 | package sd 2 | 3 | // Registrar registers instance information to a service discovery system when 4 | // an instance becomes alive and healthy, and deregisters that information when 5 | // the service becomes unhealthy or goes away. 6 | // 7 | // Registrar implementations exist for various service discovery systems. Note 8 | // that identifying instance information (e.g. host:port) must be given via the 9 | // concrete constructor; this interface merely signals lifecycle changes. 10 | type Registrar interface { 11 | Register() 12 | Deregister() 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/thrift/gen-go/addsvc/addsvc-consts.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package addsvc 5 | 6 | import ( 7 | "bytes" 8 | "reflect" 9 | "context" 10 | "fmt" 11 | "github.com/apache/thrift/lib/go/thrift" 12 | ) 13 | 14 | // (needed to ensure safety because of naive import list construction.) 15 | var _ = thrift.ZERO 16 | var _ = fmt.Printf 17 | var _ = context.Background 18 | var _ = reflect.DeepEqual 19 | var _ = bytes.Equal 20 | 21 | 22 | func init() { 23 | } 24 | 25 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/routing/routing.go: -------------------------------------------------------------------------------- 1 | // Package routing provides the routing domain service. It does not actually 2 | // implement the routing service but merely acts as a proxy for a separate 3 | // bounded context. 4 | package routing 5 | 6 | import ( 7 | "github.com/go-kit/kit/examples/shipping/cargo" 8 | ) 9 | 10 | // Service provides access to an external routing service. 11 | type Service interface { 12 | // FetchRoutesForSpecification finds all possible routes that satisfy a 13 | // given specification. 14 | FetchRoutesForSpecification(rs cargo.RouteSpecification) []cargo.Itinerary 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/nop_logger_test.go: -------------------------------------------------------------------------------- 1 | package log_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/go-kit/kit/log" 7 | ) 8 | 9 | func TestNopLogger(t *testing.T) { 10 | t.Parallel() 11 | logger := log.NewNopLogger() 12 | if err := logger.Log("abc", 123); err != nil { 13 | t.Error(err) 14 | } 15 | if err := log.With(logger, "def", "ghi").Log(); err != nil { 16 | t.Error(err) 17 | } 18 | } 19 | 20 | func BenchmarkNopLoggerSimple(b *testing.B) { 21 | benchmarkRunner(b, log.NewNopLogger(), baseMessage) 22 | } 23 | 24 | func BenchmarkNopLoggerContextual(b *testing.B) { 25 | benchmarkRunner(b, log.NewNopLogger(), withMessage) 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/gobreaker_test.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/sony/gobreaker" 7 | 8 | "github.com/go-kit/kit/circuitbreaker" 9 | ) 10 | 11 | func TestGobreaker(t *testing.T) { 12 | var ( 13 | breaker = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{})) 14 | primeWith = 100 15 | shouldPass = func(n int) bool { return n <= 5 } // https://github.com/sony/gobreaker/blob/bfa846d/gobreaker.go#L76 16 | circuitOpenError = "circuit breaker is open" 17 | ) 18 | testFailingEndpoint(t, breaker, primeWith, shouldPass, 0, circuitOpenError) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc2/service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | ) 7 | 8 | // StringService provides operations on strings. 9 | type StringService interface { 10 | Uppercase(string) (string, error) 11 | Count(string) int 12 | } 13 | 14 | type stringService struct{} 15 | 16 | func (stringService) Uppercase(s string) (string, error) { 17 | if s == "" { 18 | return "", ErrEmpty 19 | } 20 | return strings.ToUpper(s), nil 21 | } 22 | 23 | func (stringService) Count(s string) int { 24 | return len(s) 25 | } 26 | 27 | // ErrEmpty is returned when an input string is empty. 28 | var ErrEmpty = errors.New("empty string") 29 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/tracking/logging.go: -------------------------------------------------------------------------------- 1 | package tracking 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/log" 7 | ) 8 | 9 | type loggingService struct { 10 | logger log.Logger 11 | Service 12 | } 13 | 14 | // NewLoggingService returns a new instance of a logging Service. 15 | func NewLoggingService(logger log.Logger, s Service) Service { 16 | return &loggingService{logger, s} 17 | } 18 | 19 | func (s *loggingService) Track(id string) (c Cargo, err error) { 20 | defer func(begin time.Time) { 21 | s.logger.Log("method", "track", "tracking_id", id, "took", time.Since(begin), "err", err) 22 | }(time.Now()) 23 | return s.Service.Track(id) 24 | } 25 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/_examples/chat1/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "gopkg.in/alecthomas/kingpin.v2" 7 | ) 8 | 9 | var ( 10 | debug = kingpin.Flag("debug", "Enable debug mode.").Bool() 11 | timeout = kingpin.Flag("timeout", "Timeout waiting for ping.").Default("5s").OverrideDefaultFromEnvar("PING_TIMEOUT").Short('t').Duration() 12 | ip = kingpin.Arg("ip", "IP address to ping.").Required().IP() 13 | count = kingpin.Arg("count", "Number of packets to send").Int() 14 | ) 15 | 16 | func main() { 17 | kingpin.Version("0.0.1") 18 | kingpin.Parse() 19 | fmt.Printf("Would ping: %s with timeout %s and count %d", *ip, *timeout, *count) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/_examples/ping/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "gopkg.in/alecthomas/kingpin.v2" 7 | ) 8 | 9 | var ( 10 | debug = kingpin.Flag("debug", "Enable debug mode.").Bool() 11 | timeout = kingpin.Flag("timeout", "Timeout waiting for ping.").OverrideDefaultFromEnvar("PING_TIMEOUT").Required().Short('t').Duration() 12 | ip = kingpin.Arg("ip", "IP address to ping.").Required().IP() 13 | count = kingpin.Arg("count", "Number of packets to send").Int() 14 | ) 15 | 16 | func main() { 17 | kingpin.Version("0.0.1") 18 | kingpin.Parse() 19 | fmt.Printf("Would ping: %s with timeout %s and count %d", *ip, *timeout, *count) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/docker-compose-integration.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | etcd: 4 | image: quay.io/coreos/etcd 5 | ports: 6 | - "2379:2379" 7 | command: /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001" 8 | consul: 9 | image: progrium/consul 10 | ports: 11 | - "8500:8500" 12 | command: -server -bootstrap 13 | zk: 14 | image: zookeeper 15 | ports: 16 | - "2181:2181" 17 | eureka: 18 | image: springcloud/eureka 19 | environment: 20 | eureka.server.responseCacheUpdateIntervalMs: 1000 21 | ports: 22 | - "8761:8761" 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/factory.go: -------------------------------------------------------------------------------- 1 | package sd 2 | 3 | import ( 4 | "io" 5 | 6 | "github.com/go-kit/kit/endpoint" 7 | ) 8 | 9 | // Factory is a function that converts an instance string (e.g. host:port) to a 10 | // specific endpoint. Instances that provide multiple endpoints require multiple 11 | // factories. A factory also returns an io.Closer that's invoked when the 12 | // instance goes away and needs to be cleaned up. Factories may return nil 13 | // closers. 14 | // 15 | // Users are expected to provide their own factory functions that assume 16 | // specific transports, or can deduce transports by parsing the instance string. 17 | type Factory func(instance string) (endpoint.Endpoint, io.Closer, error) 18 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/lint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | if [ ! $(command -v gometalinter) ] 8 | then 9 | go get github.com/alecthomas/gometalinter 10 | gometalinter --update --install 11 | fi 12 | 13 | time gometalinter \ 14 | --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ 15 | --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ 16 | --exclude='/thrift/' \ 17 | --exclude='/pb/' \ 18 | --exclude='no args in Log call \(vet\)' \ 19 | --disable=dupl \ 20 | --disable=aligncheck \ 21 | --disable=gotype \ 22 | --cyclo-over=20 \ 23 | --tests \ 24 | --concurrency=2 \ 25 | --deadline=300s \ 26 | ./... 27 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/tracking/endpoint.go: -------------------------------------------------------------------------------- 1 | package tracking 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/go-kit/kit/endpoint" 7 | ) 8 | 9 | type trackCargoRequest struct { 10 | ID string 11 | } 12 | 13 | type trackCargoResponse struct { 14 | Cargo *Cargo `json:"cargo,omitempty"` 15 | Err error `json:"error,omitempty"` 16 | } 17 | 18 | func (r trackCargoResponse) error() error { return r.Err } 19 | 20 | func makeTrackCargoEndpoint(ts Service) endpoint.Endpoint { 21 | return func(ctx context.Context, request interface{}) (interface{}, error) { 22 | req := request.(trackCargoRequest) 23 | c, err := ts.Track(req.ID) 24 | return trackCargoResponse{Cargo: &c, Err: err}, nil 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker_test.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker_test 2 | 3 | import ( 4 | "testing" 5 | 6 | handybreaker "github.com/streadway/handy/breaker" 7 | 8 | "github.com/go-kit/kit/circuitbreaker" 9 | ) 10 | 11 | func TestHandyBreaker(t *testing.T) { 12 | var ( 13 | failureRatio = 0.05 14 | breaker = circuitbreaker.HandyBreaker(handybreaker.NewBreaker(failureRatio)) 15 | primeWith = handybreaker.DefaultMinObservations * 10 16 | shouldPass = func(n int) bool { return (float64(n) / float64(primeWith+n)) <= failureRatio } 17 | openCircuitError = handybreaker.ErrCircuitOpen.Error() 18 | ) 19 | testFailingEndpoint(t, breaker, primeWith, shouldPass, 0, openCircuitError) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/coveralls.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! type -P gover 4 | then 5 | echo gover missing: go get github.com/modocache/gover 6 | exit 1 7 | fi 8 | 9 | if ! type -P goveralls 10 | then 11 | echo goveralls missing: go get github.com/mattn/goveralls 12 | exit 1 13 | fi 14 | 15 | if [[ "$COVERALLS_TOKEN" == "" ]] 16 | then 17 | echo COVERALLS_TOKEN not set 18 | exit 1 19 | fi 20 | 21 | go list ./... | grep -v '/examples/' | cut -d'/' -f 4- | while read d 22 | do 23 | cd $d 24 | go test -covermode count -coverprofile coverage.coverprofile 25 | cd - 26 | done 27 | 28 | gover 29 | goveralls -coverprofile gover.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN 30 | find . -name '*.coverprofile' -delete 31 | 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/term.go: -------------------------------------------------------------------------------- 1 | // Package term provides tools for logging to a terminal. 2 | package term 3 | 4 | import ( 5 | "io" 6 | 7 | "github.com/go-kit/kit/log" 8 | ) 9 | 10 | // NewLogger returns a Logger that takes advantage of terminal features if 11 | // possible. Log events are formatted by the Logger returned by newLogger. If 12 | // w is a terminal each log event is colored according to the color function. 13 | func NewLogger(w io.Writer, newLogger func(io.Writer) log.Logger, color func(keyvals ...interface{}) FgBgColor) log.Logger { 14 | if !IsTerminal(w) { 15 | return newLogger(w) 16 | } 17 | return NewColorLogger(NewColorWriter(w), newLogger, color) 18 | } 19 | 20 | type fder interface { 21 | Fd() uintptr 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_notwindows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build linux,!appengine darwin freebsd openbsd 7 | 8 | package term 9 | 10 | import ( 11 | "io" 12 | "syscall" 13 | "unsafe" 14 | ) 15 | 16 | // IsTerminal returns true if w writes to a terminal. 17 | func IsTerminal(w io.Writer) bool { 18 | fw, ok := w.(fder) 19 | if !ok { 20 | return false 21 | } 22 | var termios syscall.Termios 23 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fw.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 24 | return err == 0 25 | } 26 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/_examples/modular/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "gopkg.in/alecthomas/kingpin.v2" 8 | ) 9 | 10 | // Context for "ls" command 11 | type LsCommand struct { 12 | All bool 13 | } 14 | 15 | func (l *LsCommand) run(c *kingpin.ParseContext) error { 16 | fmt.Printf("all=%v\n", l.All) 17 | return nil 18 | } 19 | 20 | func configureLsCommand(app *kingpin.Application) { 21 | c := &LsCommand{} 22 | ls := app.Command("ls", "List files.").Action(c.run) 23 | ls.Flag("all", "List all files.").Short('a').BoolVar(&c.All) 24 | } 25 | 26 | func main() { 27 | app := kingpin.New("modular", "My modular application.") 28 | configureLsCommand(app) 29 | kingpin.MustParse(app.Parse(os.Args[1:])) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/lb/random.go: -------------------------------------------------------------------------------- 1 | package lb 2 | 3 | import ( 4 | "math/rand" 5 | 6 | "github.com/go-kit/kit/endpoint" 7 | "github.com/go-kit/kit/sd" 8 | ) 9 | 10 | // NewRandom returns a load balancer that selects services randomly. 11 | func NewRandom(s sd.Endpointer, seed int64) Balancer { 12 | return &random{ 13 | s: s, 14 | r: rand.New(rand.NewSource(seed)), 15 | } 16 | } 17 | 18 | type random struct { 19 | s sd.Endpointer 20 | r *rand.Rand 21 | } 22 | 23 | func (r *random) Endpoint() (endpoint.Endpoint, error) { 24 | endpoints, err := r.s.Endpoints() 25 | if err != nil { 26 | return nil, err 27 | } 28 | if len(endpoints) <= 0 { 29 | return nil, ErrNoEndpoints 30 | } 31 | return endpoints[r.r.Intn(len(endpoints))], nil 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/internal/lv/labelvalues_test.go: -------------------------------------------------------------------------------- 1 | package lv 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | ) 7 | 8 | func TestWith(t *testing.T) { 9 | var a LabelValues 10 | b := a.With("a", "1") 11 | c := a.With("b", "2", "c", "3") 12 | 13 | if want, have := "", strings.Join(a, ""); want != have { 14 | t.Errorf("With appears to mutate the original LabelValues: want %q, have %q", want, have) 15 | } 16 | if want, have := "a1", strings.Join(b, ""); want != have { 17 | t.Errorf("With does not appear to return the right thing: want %q, have %q", want, have) 18 | } 19 | if want, have := "b2c3", strings.Join(c, ""); want != have { 20 | t.Errorf("With does not appear to return the right thing: want %q, have %q", want, have) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/benchmark_test.go: -------------------------------------------------------------------------------- 1 | package sd 2 | 3 | import ( 4 | "io" 5 | "testing" 6 | 7 | "github.com/go-kit/kit/endpoint" 8 | "github.com/go-kit/kit/log" 9 | ) 10 | 11 | func BenchmarkEndpoints(b *testing.B) { 12 | var ( 13 | ca = make(closer) 14 | cb = make(closer) 15 | cmap = map[string]io.Closer{"a": ca, "b": cb} 16 | factory = func(instance string) (endpoint.Endpoint, io.Closer, error) { return endpoint.Nop, cmap[instance], nil } 17 | c = newEndpointCache(factory, log.NewNopLogger(), endpointerOptions{}) 18 | ) 19 | 20 | b.ReportAllocs() 21 | 22 | c.Update(Event{Instances: []string{"a", "b"}}) 23 | 24 | b.RunParallel(func(pb *testing.PB) { 25 | for pb.Next() { 26 | c.Endpoints() 27 | } 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/consul/registrar_test.go: -------------------------------------------------------------------------------- 1 | package consul 2 | 3 | import ( 4 | "testing" 5 | 6 | stdconsul "github.com/hashicorp/consul/api" 7 | 8 | "github.com/go-kit/kit/log" 9 | ) 10 | 11 | func TestRegistrar(t *testing.T) { 12 | client := newTestClient([]*stdconsul.ServiceEntry{}) 13 | p := NewRegistrar(client, testRegistration, log.NewNopLogger()) 14 | if want, have := 0, len(client.entries); want != have { 15 | t.Errorf("want %d, have %d", want, have) 16 | } 17 | 18 | p.Register() 19 | if want, have := 1, len(client.entries); want != have { 20 | t.Errorf("want %d, have %d", want, have) 21 | } 22 | 23 | p.Deregister() 24 | if want, have := 0, len(client.entries); want != have { 25 | t.Errorf("want %d, have %d", want, have) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/units/si.go: -------------------------------------------------------------------------------- 1 | package units 2 | 3 | // SI units. 4 | type SI int64 5 | 6 | // SI unit multiples. 7 | const ( 8 | Kilo SI = 1000 9 | Mega = Kilo * 1000 10 | Giga = Mega * 1000 11 | Tera = Giga * 1000 12 | Peta = Tera * 1000 13 | Exa = Peta * 1000 14 | ) 15 | 16 | func MakeUnitMap(suffix, shortSuffix string, scale int64) map[string]float64 { 17 | return map[string]float64{ 18 | shortSuffix: 1, 19 | "K" + suffix: float64(scale), 20 | "M" + suffix: float64(scale * scale), 21 | "G" + suffix: float64(scale * scale * scale), 22 | "T" + suffix: float64(scale * scale * scale * scale), 23 | "P" + suffix: float64(scale * scale * scale * scale * scale), 24 | "E" + suffix: float64(scale * scale * scale * scale * scale * scale), 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/zk/logwrapper.go: -------------------------------------------------------------------------------- 1 | package zk 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/samuel/go-zookeeper/zk" 7 | 8 | "github.com/go-kit/kit/log" 9 | ) 10 | 11 | // wrapLogger wraps a Go kit logger so we can use it as the logging service for 12 | // the ZooKeeper library, which expects a Printf method to be available. 13 | type wrapLogger struct { 14 | log.Logger 15 | } 16 | 17 | func (logger wrapLogger) Printf(format string, args ...interface{}) { 18 | logger.Log("msg", fmt.Sprintf(format, args...)) 19 | } 20 | 21 | // withLogger replaces the ZooKeeper library's default logging service with our 22 | // own Go kit logger. 23 | func withLogger(logger log.Logger) func(c *zk.Conn) { 24 | return func(c *zk.Conn) { 25 | c.SetLogger(wrapLogger{logger}) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/update_deps.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script updates each non-stdlib, non-Go-kit dependency to its most recent 4 | # commit. It can be invoked to aid in debugging after a dependency-related 5 | # failure on continuous integration. 6 | 7 | function deps { 8 | go list -f '{{join .Deps "\n"}}' ./... 9 | } 10 | 11 | function not_stdlib { 12 | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' 13 | } 14 | 15 | function not_gokit { 16 | grep -v 'go-kit/kit' 17 | } 18 | 19 | function go_get_update { 20 | while read d 21 | do 22 | echo $d 23 | go get -u $d || echo "failed, trying again with master" && cd $GOPATH/src/$d && git checkout master && go get -u $d 24 | done 25 | } 26 | 27 | deps | not_stdlib | not_gokit | go_get_update 28 | 29 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/level/example_test.go: -------------------------------------------------------------------------------- 1 | package level_test 2 | 3 | import ( 4 | "errors" 5 | "os" 6 | 7 | "github.com/go-kit/kit/log" 8 | "github.com/go-kit/kit/log/level" 9 | ) 10 | 11 | func Example_basic() { 12 | // setup logger with level filter 13 | logger := log.NewLogfmtLogger(os.Stdout) 14 | logger = level.NewFilter(logger, level.AllowInfo()) 15 | logger = log.With(logger, "caller", log.DefaultCaller) 16 | 17 | // use level helpers to log at different levels 18 | level.Error(logger).Log("err", errors.New("bad data")) 19 | level.Info(logger).Log("event", "data saved") 20 | level.Debug(logger).Log("next item", 17) // filtered 21 | 22 | // Output: 23 | // level=error caller=example_test.go:18 err="bad data" 24 | // level=info caller=example_test.go:19 event="data saved" 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/lb/round_robin.go: -------------------------------------------------------------------------------- 1 | package lb 2 | 3 | import ( 4 | "sync/atomic" 5 | 6 | "github.com/go-kit/kit/endpoint" 7 | "github.com/go-kit/kit/sd" 8 | ) 9 | 10 | // NewRoundRobin returns a load balancer that returns services in sequence. 11 | func NewRoundRobin(s sd.Endpointer) Balancer { 12 | return &roundRobin{ 13 | s: s, 14 | c: 0, 15 | } 16 | } 17 | 18 | type roundRobin struct { 19 | s sd.Endpointer 20 | c uint64 21 | } 22 | 23 | func (rr *roundRobin) Endpoint() (endpoint.Endpoint, error) { 24 | endpoints, err := rr.s.Endpoints() 25 | if err != nil { 26 | return nil, err 27 | } 28 | if len(endpoints) <= 0 { 29 | return nil, ErrNoEndpoints 30 | } 31 | old := atomic.AddUint64(&rr.c, 1) - 1 32 | idx := old % uint64(len(endpoints)) 33 | return endpoints[idx], nil 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc3/service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | ) 7 | 8 | // StringService provides operations on strings. 9 | type StringService interface { 10 | Uppercase(string) (string, error) 11 | Count(string) int 12 | } 13 | 14 | type stringService struct{} 15 | 16 | func (stringService) Uppercase(s string) (string, error) { 17 | if s == "" { 18 | return "", ErrEmpty 19 | } 20 | return strings.ToUpper(s), nil 21 | } 22 | 23 | func (stringService) Count(s string) int { 24 | return len(s) 25 | } 26 | 27 | // ErrEmpty is returned when an input string is empty. 28 | var ErrEmpty = errors.New("empty string") 29 | 30 | // ServiceMiddleware is a chainable behavior modifier for StringService. 31 | type ServiceMiddleware func(StringService) StringService 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/gobreaker.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/sony/gobreaker" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | ) 10 | 11 | // Gobreaker returns an endpoint.Middleware that implements the circuit 12 | // breaker pattern using the sony/gobreaker package. Only errors returned by 13 | // the wrapped endpoint count against the circuit breaker's error count. 14 | // 15 | // See http://godoc.org/github.com/sony/gobreaker for more information. 16 | func Gobreaker(cb *gobreaker.CircuitBreaker) endpoint.Middleware { 17 | return func(next endpoint.Endpoint) endpoint.Endpoint { 18 | return func(ctx context.Context, request interface{}) (interface{}, error) { 19 | return cb.Execute(func() (interface{}, error) { return next(ctx, request) }) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/location/sample_locations.go: -------------------------------------------------------------------------------- 1 | package location 2 | 3 | // Sample UN locodes. 4 | var ( 5 | SESTO UNLocode = "SESTO" 6 | AUMEL UNLocode = "AUMEL" 7 | CNHKG UNLocode = "CNHKG" 8 | USNYC UNLocode = "USNYC" 9 | USCHI UNLocode = "USCHI" 10 | JNTKO UNLocode = "JNTKO" 11 | DEHAM UNLocode = "DEHAM" 12 | NLRTM UNLocode = "NLRTM" 13 | FIHEL UNLocode = "FIHEL" 14 | ) 15 | 16 | // Sample locations. 17 | var ( 18 | Stockholm = &Location{SESTO, "Stockholm"} 19 | Melbourne = &Location{AUMEL, "Melbourne"} 20 | Hongkong = &Location{CNHKG, "Hongkong"} 21 | NewYork = &Location{USNYC, "New York"} 22 | Chicago = &Location{USCHI, "Chicago"} 23 | Tokyo = &Location{JNTKO, "Tokyo"} 24 | Hamburg = &Location{DEHAM, "Hamburg"} 25 | Rotterdam = &Location{NLRTM, "Rotterdam"} 26 | Helsinki = &Location{FIHEL, "Helsinki"} 27 | ) 28 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/mux/context_native_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package mux 4 | 5 | import ( 6 | "context" 7 | "net/http" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | func TestNativeContextMiddleware(t *testing.T) { 13 | withTimeout := func(h http.Handler) http.Handler { 14 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 15 | ctx, cancel := context.WithTimeout(r.Context(), time.Minute) 16 | defer cancel() 17 | h.ServeHTTP(w, r.WithContext(ctx)) 18 | }) 19 | } 20 | 21 | r := NewRouter() 22 | r.Handle("/path/{foo}", withTimeout(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 23 | vars := Vars(r) 24 | if vars["foo"] != "bar" { 25 | t.Fatal("Expected foo var to be set") 26 | } 27 | }))) 28 | 29 | rec := NewRecorder() 30 | req := newRequest("GET", "/path/bar") 31 | r.ServeHTTP(rec, req) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/concurrency_test.go: -------------------------------------------------------------------------------- 1 | package log_test 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | 7 | "github.com/go-kit/kit/log" 8 | ) 9 | 10 | // These test are designed to be run with the race detector. 11 | 12 | func testConcurrency(t *testing.T, logger log.Logger, total int) { 13 | n := int(math.Sqrt(float64(total))) 14 | share := total / n 15 | 16 | errC := make(chan error, n) 17 | 18 | for i := 0; i < n; i++ { 19 | go func() { 20 | errC <- spam(logger, share) 21 | }() 22 | } 23 | 24 | for i := 0; i < n; i++ { 25 | err := <-errC 26 | if err != nil { 27 | t.Fatalf("concurrent logging error: %v", err) 28 | } 29 | } 30 | } 31 | 32 | func spam(logger log.Logger, count int) error { 33 | for i := 0; i < count; i++ { 34 | err := logger.Log("key", i) 35 | if err != nil { 36 | return err 37 | } 38 | } 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/pb/addsvc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pb; 4 | 5 | // The Add service definition. 6 | service Add { 7 | // Sums two integers. 8 | rpc Sum (SumRequest) returns (SumReply) {} 9 | 10 | // Concatenates two strings 11 | rpc Concat (ConcatRequest) returns (ConcatReply) {} 12 | } 13 | 14 | // The sum request contains two parameters. 15 | message SumRequest { 16 | int64 a = 1; 17 | int64 b = 2; 18 | } 19 | 20 | // The sum response contains the result of the calculation. 21 | message SumReply { 22 | int64 v = 1; 23 | string err = 2; 24 | } 25 | 26 | // The Concat request contains two parameters. 27 | message ConcatRequest { 28 | string a = 1; 29 | string b = 2; 30 | } 31 | 32 | // The Concat response contains the result of the concatenation. 33 | message ConcatReply { 34 | string v = 1; 35 | string err = 2; 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/request_response.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/go-kit/kit/transport/grpc/_grpc_test/pb" 7 | ) 8 | 9 | func encodeRequest(ctx context.Context, req interface{}) (interface{}, error) { 10 | r := req.(TestRequest) 11 | return &pb.TestRequest{A: r.A, B: r.B}, nil 12 | } 13 | 14 | func decodeRequest(ctx context.Context, req interface{}) (interface{}, error) { 15 | r := req.(*pb.TestRequest) 16 | return TestRequest{A: r.A, B: r.B}, nil 17 | } 18 | 19 | func encodeResponse(ctx context.Context, resp interface{}) (interface{}, error) { 20 | r := resp.(*TestResponse) 21 | return &pb.TestResponse{V: r.V}, nil 22 | } 23 | 24 | func decodeResponse(ctx context.Context, resp interface{}) (interface{}, error) { 25 | r := resp.(*pb.TestResponse) 26 | return &TestResponse{V: r.V, Ctx: ctx}, nil 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/discard.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/discard" 6 | ) 7 | 8 | type discardProvider struct{} 9 | 10 | // NewDiscardProvider returns a provider that produces no-op metrics via the 11 | // discarding backend. 12 | func NewDiscardProvider() Provider { return discardProvider{} } 13 | 14 | // NewCounter implements Provider. 15 | func (discardProvider) NewCounter(string) metrics.Counter { return discard.NewCounter() } 16 | 17 | // NewGauge implements Provider. 18 | func (discardProvider) NewGauge(string) metrics.Gauge { return discard.NewGauge() } 19 | 20 | // NewHistogram implements Provider. 21 | func (discardProvider) NewHistogram(string, int) metrics.Histogram { return discard.NewHistogram() } 22 | 23 | // Stop implements Provider. 24 | func (discardProvider) Stop() {} 25 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | 2 | # Gopkg.toml example 3 | # 4 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 5 | # for detailed Gopkg.toml documentation. 6 | # 7 | # required = ["github.com/user/thing/cmd/thing"] 8 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 9 | # 10 | # [[constraint]] 11 | # name = "github.com/user/project" 12 | # version = "1.0.0" 13 | # 14 | # [[constraint]] 15 | # name = "github.com/user/project2" 16 | # branch = "dev" 17 | # source = "github.com/myfork/project2" 18 | # 19 | # [[override]] 20 | # name = "github.com/x/y" 21 | # version = "2.4.0" 22 | 23 | 24 | [[constraint]] 25 | branch = "master" 26 | name = "github.com/aybabtme/log" 27 | 28 | [[constraint]] 29 | name = "github.com/gorilla/mux" 30 | version = "1.6.0" 31 | 32 | [[constraint]] 33 | name = "gopkg.in/alecthomas/kingpin.v2" 34 | version = "2.2.5" 35 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/.gitignore: -------------------------------------------------------------------------------- 1 | examples/addsvc/addsvc 2 | examples/addsvc/client/client 3 | examples/apigateway/apigateway 4 | examples/profilesvc/profilesvc 5 | examples/stringsvc1/stringsvc1 6 | examples/stringsvc2/stringsvc2 7 | examples/stringsvc3/stringsvc3 8 | *.coverprofile 9 | 10 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 11 | *.o 12 | *.a 13 | *.so 14 | 15 | # Folders 16 | _obj 17 | _test 18 | _old* 19 | 20 | # Architecture specific extensions/prefixes 21 | *.[568vq] 22 | [568vq].out 23 | 24 | *.cgo1.go 25 | *.cgo2.c 26 | _cgo_defun.c 27 | _cgo_gotypes.go 28 | _cgo_export.* 29 | 30 | _testmain.go 31 | 32 | *.exe 33 | 34 | # https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 35 | # swap 36 | [._]*.s[a-w][a-z] 37 | [._]s[a-w][a-z] 38 | # session 39 | Session.vim 40 | # temporary 41 | .netrwhist 42 | *~ 43 | # auto-generated tag files 44 | tags 45 | 46 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/http/request_response_funcs_test.go: -------------------------------------------------------------------------------- 1 | package http_test 2 | 3 | import ( 4 | "context" 5 | "net/http/httptest" 6 | "testing" 7 | 8 | httptransport "github.com/go-kit/kit/transport/http" 9 | ) 10 | 11 | func TestSetHeader(t *testing.T) { 12 | const ( 13 | key = "X-Foo" 14 | val = "12345" 15 | ) 16 | r := httptest.NewRecorder() 17 | httptransport.SetResponseHeader(key, val)(context.Background(), r) 18 | if want, have := val, r.Header().Get(key); want != have { 19 | t.Errorf("want %q, have %q", want, have) 20 | } 21 | } 22 | 23 | func TestSetContentType(t *testing.T) { 24 | const contentType = "application/json" 25 | r := httptest.NewRecorder() 26 | httptransport.SetContentType(contentType)(context.Background(), r) 27 | if want, have := contentType, r.Header().Get("Content-Type"); want != have { 28 | t.Errorf("want %q, have %q", want, have) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc2/logging.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/log" 7 | ) 8 | 9 | type loggingMiddleware struct { 10 | logger log.Logger 11 | next StringService 12 | } 13 | 14 | func (mw loggingMiddleware) Uppercase(s string) (output string, err error) { 15 | defer func(begin time.Time) { 16 | _ = mw.logger.Log( 17 | "method", "uppercase", 18 | "input", s, 19 | "output", output, 20 | "err", err, 21 | "took", time.Since(begin), 22 | ) 23 | }(time.Now()) 24 | 25 | output, err = mw.next.Uppercase(s) 26 | return 27 | } 28 | 29 | func (mw loggingMiddleware) Count(s string) (n int) { 30 | defer func(begin time.Time) { 31 | _ = mw.logger.Log( 32 | "method", "count", 33 | "input", s, 34 | "n", n, 35 | "took", time.Since(begin), 36 | ) 37 | }(time.Now()) 38 | 39 | n = mw.next.Count(s) 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/tracking/instrumenting.go: -------------------------------------------------------------------------------- 1 | package tracking 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/metrics" 7 | ) 8 | 9 | type instrumentingService struct { 10 | requestCount metrics.Counter 11 | requestLatency metrics.Histogram 12 | Service 13 | } 14 | 15 | // NewInstrumentingService returns an instance of an instrumenting Service. 16 | func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { 17 | return &instrumentingService{ 18 | requestCount: counter, 19 | requestLatency: latency, 20 | Service: s, 21 | } 22 | } 23 | 24 | func (s *instrumentingService) Track(id string) (Cargo, error) { 25 | defer func(begin time.Time) { 26 | s.requestCount.With("method", "track").Add(1) 27 | s.requestLatency.With("method", "track").Observe(time.Since(begin).Seconds()) 28 | }(time.Now()) 29 | 30 | return s.Service.Track(id) 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | First, thank you for contributing! We love and encourage pull requests from everyone. 4 | 5 | Before submitting major changes, here are a few guidelines to follow: 6 | 7 | 1. Check the [open issues][issues] and [pull requests][prs] for existing discussions. 8 | 1. Open an [issue][issues] first, to discuss a new feature or enhancement. 9 | 1. Write tests, and make sure the test suite passes locally and on CI. 10 | 1. Open a pull request, and reference the relevant issue(s). 11 | 1. After receiving feedback, [squash your commits][squash] and add a [great commit message][message]. 12 | 1. Have fun! 13 | 14 | [issues]: https://github.com/go-kit/kit/issues 15 | [prs]: https://github.com/go-kit/kit/pulls 16 | [squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html 17 | [message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 18 | 19 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth_unix.go: -------------------------------------------------------------------------------- 1 | // +build !appengine,linux freebsd darwin dragonfly netbsd openbsd 2 | 3 | package kingpin 4 | 5 | import ( 6 | "io" 7 | "os" 8 | "strconv" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | func guessWidth(w io.Writer) int { 14 | // check if COLUMNS env is set to comply with 15 | // http://pubs.opengroup.org/onlinepubs/009604499/basedefs/xbd_chap08.html 16 | colsStr := os.Getenv("COLUMNS") 17 | if colsStr != "" { 18 | if cols, err := strconv.Atoi(colsStr); err == nil { 19 | return cols 20 | } 21 | } 22 | 23 | if t, ok := w.(*os.File); ok { 24 | fd := t.Fd() 25 | var dimensions [4]uint16 26 | 27 | if _, _, err := syscall.Syscall6( 28 | syscall.SYS_IOCTL, 29 | uintptr(fd), 30 | uintptr(syscall.TIOCGWINSZ), 31 | uintptr(unsafe.Pointer(&dimensions)), 32 | 0, 0, 0, 33 | ); err == 0 { 34 | return int(dimensions[1]) 35 | } 36 | } 37 | return 80 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/location/location.go: -------------------------------------------------------------------------------- 1 | // Package location provides the Location aggregate. 2 | package location 3 | 4 | import ( 5 | "errors" 6 | ) 7 | 8 | // UNLocode is the United Nations location code that uniquely identifies a 9 | // particular location. 10 | // 11 | // http://www.unece.org/cefact/locode/ 12 | // http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE 13 | type UNLocode string 14 | 15 | // Location is a location is our model is stops on a journey, such as cargo 16 | // origin or destination, or carrier movement endpoints. 17 | type Location struct { 18 | UNLocode UNLocode 19 | Name string 20 | } 21 | 22 | // ErrUnknown is used when a location could not be found. 23 | var ErrUnknown = errors.New("unknown location") 24 | 25 | // Repository provides access a location store. 26 | type Repository interface { 27 | Find(locode UNLocode) (*Location, error) 28 | FindAll() []*Location 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/expvar.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/expvar" 6 | ) 7 | 8 | type expvarProvider struct{} 9 | 10 | // NewExpvarProvider returns a Provider that produces expvar metrics. 11 | func NewExpvarProvider() Provider { 12 | return expvarProvider{} 13 | } 14 | 15 | // NewCounter implements Provider. 16 | func (p expvarProvider) NewCounter(name string) metrics.Counter { 17 | return expvar.NewCounter(name) 18 | } 19 | 20 | // NewGauge implements Provider. 21 | func (p expvarProvider) NewGauge(name string) metrics.Gauge { 22 | return expvar.NewGauge(name) 23 | } 24 | 25 | // NewHistogram implements Provider. 26 | func (p expvarProvider) NewHistogram(name string, buckets int) metrics.Histogram { 27 | return expvar.NewHistogram(name, buckets) 28 | } 29 | 30 | // Stop implements Provider, but is a no-op. 31 | func (p expvarProvider) Stop() {} 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/metrics.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | // Counter describes a metric that accumulates values monotonically. 4 | // An example of a counter is the number of received HTTP requests. 5 | type Counter interface { 6 | With(labelValues ...string) Counter 7 | Add(delta float64) 8 | } 9 | 10 | // Gauge describes a metric that takes specific values over time. 11 | // An example of a gauge is the current depth of a job queue. 12 | type Gauge interface { 13 | With(labelValues ...string) Gauge 14 | Set(value float64) 15 | Add(delta float64) 16 | } 17 | 18 | // Histogram describes a metric that takes repeated observations of the same 19 | // kind of thing, and produces a statistical summary of those observations, 20 | // typically expressed as quantiles or buckets. An example of a histogram is 21 | // HTTP request latencies. 22 | type Histogram interface { 23 | With(labelValues ...string) Histogram 24 | Observe(value float64) 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/auth/basic/README.md: -------------------------------------------------------------------------------- 1 | This package provides a Basic Authentication middleware. 2 | 3 | It'll try to compare credentials from Authentication request header to a username/password pair in middleware constructor. 4 | 5 | More details about this type of authentication can be found in [Mozilla article](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). 6 | 7 | ## Usage 8 | 9 | ```go 10 | import httptransport "github.com/go-kit/kit/transport/http" 11 | 12 | httptransport.NewServer( 13 | AuthMiddleware(cfg.auth.user, cfg.auth.password, "Example Realm")(makeUppercaseEndpoint()), 14 | decodeMappingsRequest, 15 | httptransport.EncodeJSONResponse, 16 | httptransport.ServerBefore(httptransport.PopulateRequestContext), 17 | ) 18 | ``` 19 | 20 | For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like ```httptransport.ServerBefore(httptransport.PopulateRequestContext)```. -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/netrpc/README.md: -------------------------------------------------------------------------------- 1 | # net/rpc 2 | 3 | [net/rpc](https://golang.org/pkg/net/rpc) is an RPC transport that's part of the Go standard library. 4 | It's a simple and fast transport that's appropriate when all of your services are written in Go. 5 | 6 | Using net/rpc with Go kit is very simple. 7 | Just write a simple binding from your service definition to the net/rpc definition. 8 | See [netrpc_binding.go](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/netrpc_binding.go) for an example. 9 | 10 | That's it! 11 | The net/rpc binding can be registered to a name, and bound to an HTTP handler, the same as any other net/rpc endpoint. 12 | And within your service, you can use standard Go kit components and idioms. 13 | See [addsvc](https://github.com/go-kit/kit/tree/master/examples/addsvc) for a complete working example with net/rpc support. 14 | And remember: Go kit services can support multiple transports simultaneously. 15 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/hystrix.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/afex/hystrix-go/hystrix" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | ) 10 | 11 | // Hystrix returns an endpoint.Middleware that implements the circuit 12 | // breaker pattern using the afex/hystrix-go package. 13 | // 14 | // When using this circuit breaker, please configure your commands separately. 15 | // 16 | // See https://godoc.org/github.com/afex/hystrix-go/hystrix for more 17 | // information. 18 | func Hystrix(commandName string) endpoint.Middleware { 19 | return func(next endpoint.Endpoint) endpoint.Endpoint { 20 | return func(ctx context.Context, request interface{}) (response interface{}, err error) { 21 | var resp interface{} 22 | if err := hystrix.Do(commandName, func() (err error) { 23 | resp, err = next(ctx, request) 24 | return err 25 | }, nil); err != nil { 26 | return nil, err 27 | } 28 | return resp, nil 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/timer.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import "time" 4 | 5 | // Timer acts as a stopwatch, sending observations to a wrapped histogram. 6 | // It's a bit of helpful syntax sugar for h.Observe(time.Since(x)). 7 | type Timer struct { 8 | h Histogram 9 | t time.Time 10 | u time.Duration 11 | } 12 | 13 | // NewTimer wraps the given histogram and records the current time. 14 | func NewTimer(h Histogram) *Timer { 15 | return &Timer{ 16 | h: h, 17 | t: time.Now(), 18 | u: time.Second, 19 | } 20 | } 21 | 22 | // ObserveDuration captures the number of seconds since the timer was 23 | // constructed, and forwards that observation to the histogram. 24 | func (t *Timer) ObserveDuration() { 25 | d := float64(time.Since(t.t).Nanoseconds()) / float64(t.u) 26 | if d < 0 { 27 | d = 0 28 | } 29 | t.h.Observe(d) 30 | } 31 | 32 | // Unit sets the unit of the float64 emitted by the timer. 33 | // By default, the timer emits seconds. 34 | func (t *Timer) Unit(u time.Duration) { 35 | t.u = u 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/level/doc.go: -------------------------------------------------------------------------------- 1 | // Package level implements leveled logging on top of package log. To use the 2 | // level package, create a logger as per normal in your func main, and wrap it 3 | // with level.NewFilter. 4 | // 5 | // var logger log.Logger 6 | // logger = log.NewLogfmtLogger(os.Stderr) 7 | // logger = level.NewFilter(logger, level.AllowInfoAndAbove()) // <-- 8 | // logger = log.With(logger, "ts", log.DefaultTimestampUTC) 9 | // 10 | // Then, at the callsites, use one of the level.Debug, Info, Warn, or Error 11 | // helper methods to emit leveled log events. 12 | // 13 | // logger.Log("foo", "bar") // as normal, no level 14 | // level.Debug(logger).Log("request_id", reqID, "trace_data", trace.Get()) 15 | // if value > 100 { 16 | // level.Error(logger).Log("value", value) 17 | // } 18 | // 19 | // NewFilter allows precise control over what happens when a log event is 20 | // emitted without a level key, or if a squelched level is used. Check the 21 | // Option functions for details. 22 | package level 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc3/logging.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/log" 7 | ) 8 | 9 | func loggingMiddleware(logger log.Logger) ServiceMiddleware { 10 | return func(next StringService) StringService { 11 | return logmw{logger, next} 12 | } 13 | } 14 | 15 | type logmw struct { 16 | logger log.Logger 17 | StringService 18 | } 19 | 20 | func (mw logmw) Uppercase(s string) (output string, err error) { 21 | defer func(begin time.Time) { 22 | _ = mw.logger.Log( 23 | "method", "uppercase", 24 | "input", s, 25 | "output", output, 26 | "err", err, 27 | "took", time.Since(begin), 28 | ) 29 | }(time.Now()) 30 | 31 | output, err = mw.StringService.Uppercase(s) 32 | return 33 | } 34 | 35 | func (mw logmw) Count(s string) (n int) { 36 | defer func(begin time.Time) { 37 | _ = mw.logger.Log( 38 | "method", "count", 39 | "input", s, 40 | "n", n, 41 | "took", time.Since(begin), 42 | ) 43 | }(time.Now()) 44 | 45 | n = mw.StringService.Count(s) 46 | return 47 | } 48 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/endpoint/endpoint.go: -------------------------------------------------------------------------------- 1 | package endpoint 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | // Endpoint is the fundamental building block of servers and clients. 8 | // It represents a single RPC method. 9 | type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error) 10 | 11 | // Nop is an endpoint that does nothing and returns a nil error. 12 | // Useful for tests. 13 | func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil } 14 | 15 | // Middleware is a chainable behavior modifier for endpoints. 16 | type Middleware func(Endpoint) Endpoint 17 | 18 | // Chain is a helper function for composing middlewares. Requests will 19 | // traverse them in the order they're declared. That is, the first middleware 20 | // is treated as the outermost middleware. 21 | func Chain(outer Middleware, others ...Middleware) Middleware { 22 | return func(next Endpoint) Endpoint { 23 | for i := len(others) - 1; i >= 0; i-- { // reverse 24 | next = others[i](next) 25 | } 26 | return outer(next) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/mux/context_gorilla_test.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package mux 4 | 5 | import ( 6 | "net/http" 7 | "testing" 8 | 9 | "github.com/gorilla/context" 10 | ) 11 | 12 | // Tests that the context is cleared or not cleared properly depending on 13 | // the configuration of the router 14 | func TestKeepContext(t *testing.T) { 15 | func1 := func(w http.ResponseWriter, r *http.Request) {} 16 | 17 | r := NewRouter() 18 | r.HandleFunc("/", func1).Name("func1") 19 | 20 | req, _ := http.NewRequest("GET", "http://localhost/", nil) 21 | context.Set(req, "t", 1) 22 | 23 | res := new(http.ResponseWriter) 24 | r.ServeHTTP(*res, req) 25 | 26 | if _, ok := context.GetOk(req, "t"); ok { 27 | t.Error("Context should have been cleared at end of request") 28 | } 29 | 30 | r.KeepContext = true 31 | 32 | req, _ = http.NewRequest("GET", "http://localhost/", nil) 33 | context.Set(req, "t", 1) 34 | 35 | r.ServeHTTP(*res, req) 36 | if _, ok := context.GetOk(req, "t"); !ok { 37 | t.Error("Context should NOT have been cleared at end of request") 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/completions.go: -------------------------------------------------------------------------------- 1 | package kingpin 2 | 3 | // HintAction is a function type who is expected to return a slice of possible 4 | // command line arguments. 5 | type HintAction func() []string 6 | type completionsMixin struct { 7 | hintActions []HintAction 8 | builtinHintActions []HintAction 9 | } 10 | 11 | func (a *completionsMixin) addHintAction(action HintAction) { 12 | a.hintActions = append(a.hintActions, action) 13 | } 14 | 15 | // Allow adding of HintActions which are added internally, ie, EnumVar 16 | func (a *completionsMixin) addHintActionBuiltin(action HintAction) { 17 | a.builtinHintActions = append(a.builtinHintActions, action) 18 | } 19 | 20 | func (a *completionsMixin) resolveCompletions() []string { 21 | var hints []string 22 | 23 | options := a.builtinHintActions 24 | if len(a.hintActions) > 0 { 25 | // User specified their own hintActions. Use those instead. 26 | options = a.hintActions 27 | } 28 | 29 | for _, hintAction := range options { 30 | hints = append(hints, hintAction()...) 31 | } 32 | return hints 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/README.md: -------------------------------------------------------------------------------- 1 | # addsvc 2 | 3 | addsvc is an example microservice which takes full advantage of most of Go 4 | kit's features, including both service- and transport-level middlewares, 5 | speaking multiple transports simultaneously, distributed tracing, and rich 6 | error definitions. The server binary is available in cmd/addsvc. The client 7 | binary is available in cmd/addcli. 8 | 9 | Finally, the addtransport package provides both server and clients for each 10 | supported transport. The client structs bake-in certain middlewares, in order to 11 | demonstrate the _client library pattern_. But beware: client libraries are 12 | generally a bad idea, because they easily lead to the 13 | [distributed monolith antipattern](https://www.microservices.com/talks/dont-build-a-distributed-monolith/). 14 | If you don't _know_ you need to use one in your organization, it's probably best 15 | avoided: prefer moving that logic to consumers, and relying on 16 | [contract testing](https://docs.pact.io/best_practices/contract_tests_not_functional_tests.html) 17 | to detect incompatibilities. 18 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/endpoint/endpoint_example_test.go: -------------------------------------------------------------------------------- 1 | package endpoint_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/go-kit/kit/endpoint" 8 | ) 9 | 10 | func ExampleChain() { 11 | e := endpoint.Chain( 12 | annotate("first"), 13 | annotate("second"), 14 | annotate("third"), 15 | )(myEndpoint) 16 | 17 | if _, err := e(ctx, req); err != nil { 18 | panic(err) 19 | } 20 | 21 | // Output: 22 | // first pre 23 | // second pre 24 | // third pre 25 | // my endpoint! 26 | // third post 27 | // second post 28 | // first post 29 | } 30 | 31 | var ( 32 | ctx = context.Background() 33 | req = struct{}{} 34 | ) 35 | 36 | func annotate(s string) endpoint.Middleware { 37 | return func(next endpoint.Endpoint) endpoint.Endpoint { 38 | return func(ctx context.Context, request interface{}) (interface{}, error) { 39 | fmt.Println(s, "pre") 40 | defer fmt.Println(s, "post") 41 | return next(ctx, request) 42 | } 43 | } 44 | } 45 | 46 | func myEndpoint(context.Context, interface{}) (interface{}, error) { 47 | fmt.Println("my endpoint!") 48 | return struct{}{}, nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/envar.go: -------------------------------------------------------------------------------- 1 | package kingpin 2 | 3 | import ( 4 | "os" 5 | "regexp" 6 | ) 7 | 8 | var ( 9 | envVarValuesSeparator = "\r?\n" 10 | envVarValuesTrimmer = regexp.MustCompile(envVarValuesSeparator + "$") 11 | envVarValuesSplitter = regexp.MustCompile(envVarValuesSeparator) 12 | ) 13 | 14 | type envarMixin struct { 15 | envar string 16 | noEnvar bool 17 | } 18 | 19 | func (e *envarMixin) HasEnvarValue() bool { 20 | return e.GetEnvarValue() != "" 21 | } 22 | 23 | func (e *envarMixin) GetEnvarValue() string { 24 | if e.noEnvar || e.envar == "" { 25 | return "" 26 | } 27 | return os.Getenv(e.envar) 28 | } 29 | 30 | func (e *envarMixin) GetSplitEnvarValue() []string { 31 | values := make([]string, 0) 32 | 33 | envarValue := e.GetEnvarValue() 34 | if envarValue == "" { 35 | return values 36 | } 37 | 38 | // Split by new line to extract multiple values, if any. 39 | trimmed := envVarValuesTrimmer.ReplaceAllString(envarValue, "") 40 | for _, value := range envVarValuesSplitter.Split(trimmed, -1) { 41 | values = append(values, value) 42 | } 43 | 44 | return values 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/handling/endpoint.go: -------------------------------------------------------------------------------- 1 | package handling 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/go-kit/kit/endpoint" 8 | 9 | "github.com/go-kit/kit/examples/shipping/cargo" 10 | "github.com/go-kit/kit/examples/shipping/location" 11 | "github.com/go-kit/kit/examples/shipping/voyage" 12 | ) 13 | 14 | type registerIncidentRequest struct { 15 | ID cargo.TrackingID 16 | Location location.UNLocode 17 | Voyage voyage.Number 18 | EventType cargo.HandlingEventType 19 | CompletionTime time.Time 20 | } 21 | 22 | type registerIncidentResponse struct { 23 | Err error `json:"error,omitempty"` 24 | } 25 | 26 | func (r registerIncidentResponse) error() error { return r.Err } 27 | 28 | func makeRegisterIncidentEndpoint(hs Service) endpoint.Endpoint { 29 | return func(ctx context.Context, request interface{}) (interface{}, error) { 30 | req := request.(registerIncidentRequest) 31 | err := hs.RegisterHandlingEvent(req.CompletionTime, req.ID, req.Voyage, req.Location, req.EventType) 32 | return registerIncidentResponse{Err: err}, nil 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/units/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Alec Thomas 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/handy_breaker.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/streadway/handy/breaker" 8 | 9 | "github.com/go-kit/kit/endpoint" 10 | ) 11 | 12 | // HandyBreaker returns an endpoint.Middleware that implements the circuit 13 | // breaker pattern using the streadway/handy/breaker package. Only errors 14 | // returned by the wrapped endpoint count against the circuit breaker's error 15 | // count. 16 | // 17 | // See http://godoc.org/github.com/streadway/handy/breaker for more 18 | // information. 19 | func HandyBreaker(cb breaker.Breaker) endpoint.Middleware { 20 | return func(next endpoint.Endpoint) endpoint.Endpoint { 21 | return func(ctx context.Context, request interface{}) (response interface{}, err error) { 22 | if !cb.Allow() { 23 | return nil, breaker.ErrCircuitOpen 24 | } 25 | 26 | defer func(begin time.Time) { 27 | if err == nil { 28 | cb.Success(time.Since(begin)) 29 | } else { 30 | cb.Failure(time.Since(begin)) 31 | } 32 | }(time.Now()) 33 | 34 | response, err = next(ctx, request) 35 | return 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Alec Thomas 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc2/instrumenting.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/go-kit/kit/metrics" 8 | ) 9 | 10 | type instrumentingMiddleware struct { 11 | requestCount metrics.Counter 12 | requestLatency metrics.Histogram 13 | countResult metrics.Histogram 14 | next StringService 15 | } 16 | 17 | func (mw instrumentingMiddleware) Uppercase(s string) (output string, err error) { 18 | defer func(begin time.Time) { 19 | lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} 20 | mw.requestCount.With(lvs...).Add(1) 21 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) 22 | }(time.Now()) 23 | 24 | output, err = mw.next.Uppercase(s) 25 | return 26 | } 27 | 28 | func (mw instrumentingMiddleware) Count(s string) (n int) { 29 | defer func(begin time.Time) { 30 | lvs := []string{"method", "count", "error", "false"} 31 | mw.requestCount.With(lvs...).Add(1) 32 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) 33 | mw.countResult.Observe(float64(n)) 34 | }(time.Now()) 35 | 36 | n = mw.next.Count(s) 37 | return 38 | } 39 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/actions.go: -------------------------------------------------------------------------------- 1 | package kingpin 2 | 3 | // Action callback executed at various stages after all values are populated. 4 | // The application, commands, arguments and flags all have corresponding 5 | // actions. 6 | type Action func(*ParseContext) error 7 | 8 | type actionMixin struct { 9 | actions []Action 10 | preActions []Action 11 | } 12 | 13 | type actionApplier interface { 14 | applyActions(*ParseContext) error 15 | applyPreActions(*ParseContext) error 16 | } 17 | 18 | func (a *actionMixin) addAction(action Action) { 19 | a.actions = append(a.actions, action) 20 | } 21 | 22 | func (a *actionMixin) addPreAction(action Action) { 23 | a.preActions = append(a.preActions, action) 24 | } 25 | 26 | func (a *actionMixin) applyActions(context *ParseContext) error { 27 | for _, action := range a.actions { 28 | if err := action(context); err != nil { 29 | return err 30 | } 31 | } 32 | return nil 33 | } 34 | 35 | func (a *actionMixin) applyPreActions(context *ParseContext) error { 36 | for _, preAction := range a.preActions { 37 | if err := preAction(context); err != nil { 38 | return err 39 | } 40 | } 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Peter Bourgon 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 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Chris Hines 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/aybabtme/log/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Antoine Grondin 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 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 go-logfmt 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 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/bench_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package errors 4 | 5 | import ( 6 | "fmt" 7 | "testing" 8 | 9 | stderrors "errors" 10 | ) 11 | 12 | func noErrors(at, depth int) error { 13 | if at >= depth { 14 | return stderrors.New("no error") 15 | } 16 | return noErrors(at+1, depth) 17 | } 18 | func yesErrors(at, depth int) error { 19 | if at >= depth { 20 | return New("ye error") 21 | } 22 | return yesErrors(at+1, depth) 23 | } 24 | 25 | func BenchmarkErrors(b *testing.B) { 26 | var toperr error 27 | type run struct { 28 | stack int 29 | std bool 30 | } 31 | runs := []run{ 32 | {10, false}, 33 | {10, true}, 34 | {100, false}, 35 | {100, true}, 36 | {1000, false}, 37 | {1000, true}, 38 | } 39 | for _, r := range runs { 40 | part := "pkg/errors" 41 | if r.std { 42 | part = "errors" 43 | } 44 | name := fmt.Sprintf("%s-stack-%d", part, r.stack) 45 | b.Run(name, func(b *testing.B) { 46 | var err error 47 | f := yesErrors 48 | if r.std { 49 | f = noErrors 50 | } 51 | b.ReportAllocs() 52 | for i := 0; i < b.N; i++ { 53 | err = f(0, r.stack) 54 | } 55 | b.StopTimer() 56 | toperr = err 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/handling/logging.go: -------------------------------------------------------------------------------- 1 | package handling 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/log" 7 | 8 | "github.com/go-kit/kit/examples/shipping/cargo" 9 | "github.com/go-kit/kit/examples/shipping/location" 10 | "github.com/go-kit/kit/examples/shipping/voyage" 11 | ) 12 | 13 | type loggingService struct { 14 | logger log.Logger 15 | Service 16 | } 17 | 18 | // NewLoggingService returns a new instance of a logging Service. 19 | func NewLoggingService(logger log.Logger, s Service) Service { 20 | return &loggingService{logger, s} 21 | } 22 | 23 | func (s *loggingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, 24 | unLocode location.UNLocode, eventType cargo.HandlingEventType) (err error) { 25 | defer func(begin time.Time) { 26 | s.logger.Log( 27 | "method", "register_incident", 28 | "tracking_id", id, 29 | "location", unLocode, 30 | "voyage", voyageNumber, 31 | "event_type", eventType, 32 | "completion_time", completed, 33 | "took", time.Since(begin), 34 | "err", err, 35 | ) 36 | }(time.Now()) 37 | return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, unLocode, eventType) 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/internal/ratemap/ratemap.go: -------------------------------------------------------------------------------- 1 | // Package ratemap implements a goroutine-safe map of string to float64. It can 2 | // be embedded in implementations whose metrics support fixed sample rates, so 3 | // that an additional parameter doesn't have to be tracked through the e.g. 4 | // lv.Space object. 5 | package ratemap 6 | 7 | import "sync" 8 | 9 | // RateMap is a simple goroutine-safe map of string to float64. 10 | type RateMap struct { 11 | mtx sync.RWMutex 12 | m map[string]float64 13 | } 14 | 15 | // New returns a new RateMap. 16 | func New() *RateMap { 17 | return &RateMap{ 18 | m: map[string]float64{}, 19 | } 20 | } 21 | 22 | // Set writes the given name/rate pair to the map. 23 | // Set is safe for concurrent access by multiple goroutines. 24 | func (m *RateMap) Set(name string, rate float64) { 25 | m.mtx.Lock() 26 | defer m.mtx.Unlock() 27 | m.m[name] = rate 28 | } 29 | 30 | // Get retrieves the rate for the given name, or 1.0 if none is set. 31 | // Get is safe for concurrent access by multiple goroutines. 32 | func (m *RateMap) Get(name string) float64 { 33 | m.mtx.RLock() 34 | defer m.mtx.RUnlock() 35 | f, ok := m.m[name] 36 | if !ok { 37 | f = 1.0 38 | } 39 | return f 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | pre: 3 | - curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 4 | - sudo rm -rf /usr/local/go 5 | - curl -sSL https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz | sudo tar xz -C /usr/local 6 | services: 7 | - docker 8 | 9 | dependencies: 10 | pre: 11 | - sudo curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose 12 | - sudo chmod +x /usr/local/bin/docker-compose 13 | - docker-compose -f docker-compose-integration.yml up -d --force-recreate 14 | 15 | test: 16 | pre: 17 | - mkdir -p /home/ubuntu/.go_workspace/src/github.com/go-kit 18 | - mv /home/ubuntu/kit /home/ubuntu/.go_workspace/src/github.com/go-kit 19 | - ln -s /home/ubuntu/.go_workspace/src/github.com/go-kit/kit /home/ubuntu/kit 20 | - go get -t github.com/go-kit/kit/... 21 | override: 22 | - go test -v -race -tags integration github.com/go-kit/kit/...: 23 | environment: 24 | ETCD_ADDR: http://localhost:2379 25 | CONSUL_ADDR: localhost:8500 26 | ZK_ADDR: localhost:2181 27 | EUREKA_ADDR: http://localhost:8761/eureka 28 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/profilesvc/cmd/profilesvc/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "net/http" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | 11 | "github.com/go-kit/kit/examples/profilesvc" 12 | "github.com/go-kit/kit/log" 13 | ) 14 | 15 | func main() { 16 | var ( 17 | httpAddr = flag.String("http.addr", ":8080", "HTTP listen address") 18 | ) 19 | flag.Parse() 20 | 21 | var logger log.Logger 22 | { 23 | logger = log.NewLogfmtLogger(os.Stderr) 24 | logger = log.With(logger, "ts", log.DefaultTimestampUTC) 25 | logger = log.With(logger, "caller", log.DefaultCaller) 26 | } 27 | 28 | var s profilesvc.Service 29 | { 30 | s = profilesvc.NewInmemService() 31 | s = profilesvc.LoggingMiddleware(logger)(s) 32 | } 33 | 34 | var h http.Handler 35 | { 36 | h = profilesvc.MakeHTTPHandler(s, log.With(logger, "component", "HTTP")) 37 | } 38 | 39 | errs := make(chan error) 40 | go func() { 41 | c := make(chan os.Signal) 42 | signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) 43 | errs <- fmt.Errorf("%s", <-c) 44 | }() 45 | 46 | go func() { 47 | logger.Log("transport", "HTTP", "addr", *httpAddr) 48 | errs <- http.ListenAndServe(*httpAddr, h) 49 | }() 50 | 51 | logger.Log("exit", <-errs) 52 | } 53 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/_examples/chat2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | 7 | "gopkg.in/alecthomas/kingpin.v2" 8 | ) 9 | 10 | var ( 11 | app = kingpin.New("chat", "A command-line chat application.") 12 | debug = app.Flag("debug", "Enable debug mode.").Bool() 13 | serverIP = app.Flag("server", "Server address.").Default("127.0.0.1").IP() 14 | 15 | register = app.Command("register", "Register a new user.") 16 | registerNick = register.Arg("nick", "Nickname for user.").Required().String() 17 | registerName = register.Arg("name", "Name of user.").Required().String() 18 | 19 | post = app.Command("post", "Post a message to a channel.") 20 | postImage = post.Flag("image", "Image to post.").File() 21 | postChannel = post.Arg("channel", "Channel to post to.").Required().String() 22 | postText = post.Arg("text", "Text to post.").Strings() 23 | ) 24 | 25 | func main() { 26 | switch kingpin.MustParse(app.Parse(os.Args[1:])) { 27 | // Register user 28 | case register.FullCommand(): 29 | println(*registerNick) 30 | 31 | // Post message 32 | case post.FullCommand(): 33 | if *postImage != nil { 34 | } 35 | text := strings.Join(*postText, " ") 36 | println("Post:", text) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/discard/discard.go: -------------------------------------------------------------------------------- 1 | // Package discard provides a no-op metrics backend. 2 | package discard 3 | 4 | import "github.com/go-kit/kit/metrics" 5 | 6 | type counter struct{} 7 | 8 | // NewCounter returns a new no-op counter. 9 | func NewCounter() metrics.Counter { return counter{} } 10 | 11 | // With implements Counter. 12 | func (c counter) With(labelValues ...string) metrics.Counter { return c } 13 | 14 | // Add implements Counter. 15 | func (c counter) Add(delta float64) {} 16 | 17 | type gauge struct{} 18 | 19 | // NewGauge returns a new no-op gauge. 20 | func NewGauge() metrics.Gauge { return gauge{} } 21 | 22 | // With implements Gauge. 23 | func (g gauge) With(labelValues ...string) metrics.Gauge { return g } 24 | 25 | // Set implements Gauge. 26 | func (g gauge) Set(value float64) {} 27 | 28 | // Add implements metrics.Gauge. 29 | func (g gauge) Add(delta float64) {} 30 | 31 | type histogram struct{} 32 | 33 | // NewHistogram returns a new no-op histogram. 34 | func NewHistogram() metrics.Histogram { return histogram{} } 35 | 36 | // With implements Histogram. 37 | func (h histogram) With(labelValues ...string) metrics.Histogram { return h } 38 | 39 | // Observe implements histogram. 40 | func (h histogram) Observe(value float64) {} 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/influx.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/influx" 6 | ) 7 | 8 | type influxProvider struct { 9 | in *influx.Influx 10 | stop func() 11 | } 12 | 13 | // NewInfluxProvider takes the given Influx object and stop func, and returns 14 | // a Provider that produces Influx metrics. 15 | func NewInfluxProvider(in *influx.Influx, stop func()) Provider { 16 | return &influxProvider{ 17 | in: in, 18 | stop: stop, 19 | } 20 | } 21 | 22 | // NewCounter implements Provider. Per-metric tags are not supported. 23 | func (p *influxProvider) NewCounter(name string) metrics.Counter { 24 | return p.in.NewCounter(name) 25 | } 26 | 27 | // NewGauge implements Provider. Per-metric tags are not supported. 28 | func (p *influxProvider) NewGauge(name string) metrics.Gauge { 29 | return p.in.NewGauge(name) 30 | } 31 | 32 | // NewHistogram implements Provider. Per-metric tags are not supported. 33 | func (p *influxProvider) NewHistogram(name string, buckets int) metrics.Histogram { 34 | return p.in.NewHistogram(name) 35 | } 36 | 37 | // Stop implements Provider, invoking the stop function passed at construction. 38 | func (p *influxProvider) Stop() { 39 | p.stop() 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/voyage/voyage.go: -------------------------------------------------------------------------------- 1 | // Package voyage provides the Voyage aggregate. 2 | package voyage 3 | 4 | import ( 5 | "errors" 6 | "time" 7 | 8 | "github.com/go-kit/kit/examples/shipping/location" 9 | ) 10 | 11 | // Number uniquely identifies a particular Voyage. 12 | type Number string 13 | 14 | // Voyage is a uniquely identifiable series of carrier movements. 15 | type Voyage struct { 16 | Number Number 17 | Schedule Schedule 18 | } 19 | 20 | // New creates a voyage with a voyage number and a provided schedule. 21 | func New(n Number, s Schedule) *Voyage { 22 | return &Voyage{Number: n, Schedule: s} 23 | } 24 | 25 | // Schedule describes a voyage schedule. 26 | type Schedule struct { 27 | CarrierMovements []CarrierMovement 28 | } 29 | 30 | // CarrierMovement is a vessel voyage from one location to another. 31 | type CarrierMovement struct { 32 | DepartureLocation location.UNLocode 33 | ArrivalLocation location.UNLocode 34 | DepartureTime time.Time 35 | ArrivalTime time.Time 36 | } 37 | 38 | // ErrUnknown is used when a voyage could not be found. 39 | var ErrUnknown = errors.New("unknown voyage") 40 | 41 | // Repository provides access a voyage store. 42 | type Repository interface { 43 | Find(Number) (*Voyage, error) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/http/example_test.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "net/http/httptest" 8 | ) 9 | 10 | func ExamplePopulateRequestContext() { 11 | handler := NewServer( 12 | func(ctx context.Context, request interface{}) (response interface{}, err error) { 13 | fmt.Println("Method", ctx.Value(ContextKeyRequestMethod).(string)) 14 | fmt.Println("RequestPath", ctx.Value(ContextKeyRequestPath).(string)) 15 | fmt.Println("RequestURI", ctx.Value(ContextKeyRequestURI).(string)) 16 | fmt.Println("X-Request-ID", ctx.Value(ContextKeyRequestXRequestID).(string)) 17 | return struct{}{}, nil 18 | }, 19 | func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil }, 20 | func(context.Context, http.ResponseWriter, interface{}) error { return nil }, 21 | ServerBefore(PopulateRequestContext), 22 | ) 23 | 24 | server := httptest.NewServer(handler) 25 | defer server.Close() 26 | 27 | req, _ := http.NewRequest("PATCH", fmt.Sprintf("%s/search?q=sympatico", server.URL), nil) 28 | req.Header.Set("X-Request-Id", "a1b2c3d4e5") 29 | http.DefaultClient.Do(req) 30 | 31 | // Output: 32 | // Method PATCH 33 | // RequestPath /search 34 | // RequestURI /search?q=sympatico 35 | // X-Request-ID a1b2c3d4e5 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/kr/logfmt/Readme: -------------------------------------------------------------------------------- 1 | Go package for parsing (and, eventually, generating) 2 | log lines in the logfmt style. 3 | 4 | See http://godoc.org/github.com/kr/logfmt for format, and other documentation and examples. 5 | 6 | Copyright (C) 2013 Keith Rarick, Blake Mizerany 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/graphite.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/graphite" 6 | ) 7 | 8 | type graphiteProvider struct { 9 | g *graphite.Graphite 10 | stop func() 11 | } 12 | 13 | // NewGraphiteProvider wraps the given Graphite object and stop func and returns 14 | // a Provider that produces Graphite metrics. A typical stop function would be 15 | // ticker.Stop from the ticker passed to the SendLoop helper method. 16 | func NewGraphiteProvider(g *graphite.Graphite, stop func()) Provider { 17 | return &graphiteProvider{ 18 | g: g, 19 | stop: stop, 20 | } 21 | } 22 | 23 | // NewCounter implements Provider. 24 | func (p *graphiteProvider) NewCounter(name string) metrics.Counter { 25 | return p.g.NewCounter(name) 26 | } 27 | 28 | // NewGauge implements Provider. 29 | func (p *graphiteProvider) NewGauge(name string) metrics.Gauge { 30 | return p.g.NewGauge(name) 31 | } 32 | 33 | // NewHistogram implements Provider. 34 | func (p *graphiteProvider) NewHistogram(name string, buckets int) metrics.Histogram { 35 | return p.g.NewHistogram(name, buckets) 36 | } 37 | 38 | // Stop implements Provider, invoking the stop function passed at construction. 39 | func (p *graphiteProvider) Stop() { 40 | p.stop() 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/handling/instrumenting.go: -------------------------------------------------------------------------------- 1 | package handling 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/go-kit/kit/metrics" 7 | 8 | "github.com/go-kit/kit/examples/shipping/cargo" 9 | "github.com/go-kit/kit/examples/shipping/location" 10 | "github.com/go-kit/kit/examples/shipping/voyage" 11 | ) 12 | 13 | type instrumentingService struct { 14 | requestCount metrics.Counter 15 | requestLatency metrics.Histogram 16 | Service 17 | } 18 | 19 | // NewInstrumentingService returns an instance of an instrumenting Service. 20 | func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service { 21 | return &instrumentingService{ 22 | requestCount: counter, 23 | requestLatency: latency, 24 | Service: s, 25 | } 26 | } 27 | 28 | func (s *instrumentingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number, 29 | loc location.UNLocode, eventType cargo.HandlingEventType) error { 30 | 31 | defer func(begin time.Time) { 32 | s.requestCount.With("method", "register_incident").Add(1) 33 | s.requestLatency.With("method", "register_incident").Observe(time.Since(begin).Seconds()) 34 | }(time.Now()) 35 | 36 | return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, loc, eventType) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/client.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "context" 5 | 6 | "google.golang.org/grpc" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | grpctransport "github.com/go-kit/kit/transport/grpc" 10 | "github.com/go-kit/kit/transport/grpc/_grpc_test/pb" 11 | ) 12 | 13 | type clientBinding struct { 14 | test endpoint.Endpoint 15 | } 16 | 17 | func (c *clientBinding) Test(ctx context.Context, a string, b int64) (context.Context, string, error) { 18 | response, err := c.test(ctx, TestRequest{A: a, B: b}) 19 | if err != nil { 20 | return nil, "", err 21 | } 22 | r := response.(*TestResponse) 23 | return r.Ctx, r.V, nil 24 | } 25 | 26 | func NewClient(cc *grpc.ClientConn) Service { 27 | return &clientBinding{ 28 | test: grpctransport.NewClient( 29 | cc, 30 | "pb.Test", 31 | "Test", 32 | encodeRequest, 33 | decodeResponse, 34 | &pb.TestResponse{}, 35 | grpctransport.ClientBefore( 36 | injectCorrelationID, 37 | ), 38 | grpctransport.ClientBefore( 39 | displayClientRequestHeaders, 40 | ), 41 | grpctransport.ClientAfter( 42 | displayClientResponseHeaders, 43 | displayClientResponseTrailers, 44 | ), 45 | grpctransport.ClientAfter( 46 | extractConsumedCorrelationID, 47 | ), 48 | ).Endpoint(), 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/kr/logfmt/bench_test.go: -------------------------------------------------------------------------------- 1 | package logfmt 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func BenchmarkScanner(b *testing.B) { 9 | b.StopTimer() 10 | data := []byte("measure.test=1 measure.foo=bar measure.time=2h measure=\"foo\"") 11 | h := new(nopHandler) 12 | b.SetBytes(int64(len(data))) 13 | b.StartTimer() 14 | for i := 0; i < b.N; i++ { 15 | if err := gotoScanner(data, h); err != nil { 16 | panic(err) 17 | } 18 | } 19 | } 20 | 21 | type nopHandler struct { 22 | called bool 23 | } 24 | 25 | func (h *nopHandler) HandleLogfmt(key, val []byte) error { 26 | h.called = true 27 | return nil 28 | } 29 | 30 | func BenchmarkDecodeCustom(b *testing.B) { 31 | data := []byte(`a=foo b=10ms c=cat E="123" d foo= emp=`) 32 | 33 | h := new(nopHandler) 34 | for i := 0; i < b.N; i++ { 35 | if err := Unmarshal(data, h); err != nil { 36 | panic(err) 37 | } 38 | } 39 | if !h.called { 40 | panic("handler not called") 41 | } 42 | } 43 | 44 | func BenchmarkDecodeDefault(b *testing.B) { 45 | data := []byte(`a=foo b=10ms c=cat E="123" d foo= emp=`) 46 | var g struct { 47 | A string 48 | B time.Duration 49 | C *string 50 | E string 51 | D bool 52 | } 53 | 54 | for i := 0; i < b.N; i++ { 55 | if err := Unmarshal(data, &g); err != nil { 56 | panic(err) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/examples_test.go: -------------------------------------------------------------------------------- 1 | package kingpin 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "strings" 7 | ) 8 | 9 | type HTTPHeaderValue http.Header 10 | 11 | func (h *HTTPHeaderValue) Set(value string) error { 12 | parts := strings.SplitN(value, ":", 2) 13 | if len(parts) != 2 { 14 | return fmt.Errorf("expected HEADER:VALUE got '%s'", value) 15 | } 16 | (*http.Header)(h).Add(parts[0], parts[1]) 17 | return nil 18 | } 19 | 20 | func (h *HTTPHeaderValue) Get() interface{} { 21 | return (http.Header)(*h) 22 | } 23 | 24 | func (h *HTTPHeaderValue) String() string { 25 | return "" 26 | } 27 | 28 | func HTTPHeader(s Settings) (target *http.Header) { 29 | target = new(http.Header) 30 | s.SetValue((*HTTPHeaderValue)(target)) 31 | return 32 | } 33 | 34 | // This example ilustrates how to define custom parsers. HTTPHeader 35 | // cumulatively parses each encountered --header flag into a http.Header struct. 36 | func ExampleValue() { 37 | var ( 38 | curl = New("curl", "transfer a URL") 39 | headers = HTTPHeader(curl.Flag("headers", "Add HTTP headers to the request.").Short('H').PlaceHolder("HEADER:VALUE")) 40 | ) 41 | 42 | curl.Parse([]string{"-H Content-Type:application/octet-stream"}) 43 | for key, value := range *headers { 44 | fmt.Printf("%s = %s\n", key, value) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/example_test.go: -------------------------------------------------------------------------------- 1 | package logfmt_test 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "os" 7 | "strings" 8 | "time" 9 | 10 | "github.com/go-logfmt/logfmt" 11 | ) 12 | 13 | func ExampleEncoder() { 14 | check := func(err error) { 15 | if err != nil { 16 | panic(err) 17 | } 18 | } 19 | 20 | e := logfmt.NewEncoder(os.Stdout) 21 | 22 | check(e.EncodeKeyval("id", 1)) 23 | check(e.EncodeKeyval("dur", time.Second+time.Millisecond)) 24 | check(e.EndRecord()) 25 | 26 | check(e.EncodeKeyval("id", 1)) 27 | check(e.EncodeKeyval("path", "/path/to/file")) 28 | check(e.EncodeKeyval("err", errors.New("file not found"))) 29 | check(e.EndRecord()) 30 | 31 | // Output: 32 | // id=1 dur=1.001s 33 | // id=1 path=/path/to/file err="file not found" 34 | } 35 | 36 | func ExampleDecoder() { 37 | in := ` 38 | id=1 dur=1.001s 39 | id=1 path=/path/to/file err="file not found" 40 | ` 41 | 42 | d := logfmt.NewDecoder(strings.NewReader(in)) 43 | for d.ScanRecord() { 44 | for d.ScanKeyval() { 45 | fmt.Printf("k: %s v: %s\n", d.Key(), d.Value()) 46 | } 47 | fmt.Println() 48 | } 49 | if d.Err() != nil { 50 | panic(d.Err()) 51 | } 52 | 53 | // Output: 54 | // k: id v: 1 55 | // k: dur v: 1.001s 56 | // 57 | // k: id v: 1 58 | // k: path v: /path/to/file 59 | // k: err v: file not found 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/consul/registrar.go: -------------------------------------------------------------------------------- 1 | package consul 2 | 3 | import ( 4 | "fmt" 5 | 6 | stdconsul "github.com/hashicorp/consul/api" 7 | 8 | "github.com/go-kit/kit/log" 9 | ) 10 | 11 | // Registrar registers service instance liveness information to Consul. 12 | type Registrar struct { 13 | client Client 14 | registration *stdconsul.AgentServiceRegistration 15 | logger log.Logger 16 | } 17 | 18 | // NewRegistrar returns a Consul Registrar acting on the provided catalog 19 | // registration. 20 | func NewRegistrar(client Client, r *stdconsul.AgentServiceRegistration, logger log.Logger) *Registrar { 21 | return &Registrar{ 22 | client: client, 23 | registration: r, 24 | logger: log.With(logger, "service", r.Name, "tags", fmt.Sprint(r.Tags), "address", r.Address), 25 | } 26 | } 27 | 28 | // Register implements sd.Registrar interface. 29 | func (p *Registrar) Register() { 30 | if err := p.client.Register(p.registration); err != nil { 31 | p.logger.Log("err", err) 32 | } else { 33 | p.logger.Log("action", "register") 34 | } 35 | } 36 | 37 | // Deregister implements sd.Registrar interface. 38 | func (p *Registrar) Deregister() { 39 | if err := p.client.Deregister(p.registration); err != nil { 40 | p.logger.Log("err", err) 41 | } else { 42 | p.logger.Log("action", "deregister") 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/circuitbreaker/hystrix_test.go: -------------------------------------------------------------------------------- 1 | package circuitbreaker_test 2 | 3 | import ( 4 | "io/ioutil" 5 | stdlog "log" 6 | "testing" 7 | "time" 8 | 9 | "github.com/afex/hystrix-go/hystrix" 10 | 11 | "github.com/go-kit/kit/circuitbreaker" 12 | ) 13 | 14 | func TestHystrix(t *testing.T) { 15 | stdlog.SetOutput(ioutil.Discard) 16 | 17 | const ( 18 | commandName = "my-endpoint" 19 | errorPercent = 5 20 | maxConcurrent = 1000 21 | ) 22 | hystrix.ConfigureCommand(commandName, hystrix.CommandConfig{ 23 | ErrorPercentThreshold: errorPercent, 24 | MaxConcurrentRequests: maxConcurrent, 25 | }) 26 | 27 | var ( 28 | breaker = circuitbreaker.Hystrix(commandName) 29 | primeWith = hystrix.DefaultVolumeThreshold * 2 30 | shouldPass = func(n int) bool { return (float64(n) / float64(primeWith+n)) <= (float64(errorPercent-1) / 100.0) } 31 | openCircuitError = hystrix.ErrCircuitOpen.Error() 32 | ) 33 | 34 | // hystrix-go uses buffered channels to receive reports on request success/failure, 35 | // and so is basically impossible to test deterministically. We have to make sure 36 | // the report buffer is emptied, by injecting a sleep between each invocation. 37 | requestDelay := 5 * time.Millisecond 38 | 39 | testFailingEndpoint(t, breaker, primeWith, shouldPass, requestDelay, openCircuitError) 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/consul/client.go: -------------------------------------------------------------------------------- 1 | package consul 2 | 3 | import ( 4 | consul "github.com/hashicorp/consul/api" 5 | ) 6 | 7 | // Client is a wrapper around the Consul API. 8 | type Client interface { 9 | // Register a service with the local agent. 10 | Register(r *consul.AgentServiceRegistration) error 11 | 12 | // Deregister a service with the local agent. 13 | Deregister(r *consul.AgentServiceRegistration) error 14 | 15 | // Service 16 | Service(service, tag string, passingOnly bool, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) 17 | } 18 | 19 | type client struct { 20 | consul *consul.Client 21 | } 22 | 23 | // NewClient returns an implementation of the Client interface, wrapping a 24 | // concrete Consul client. 25 | func NewClient(c *consul.Client) Client { 26 | return &client{consul: c} 27 | } 28 | 29 | func (c *client) Register(r *consul.AgentServiceRegistration) error { 30 | return c.consul.Agent().ServiceRegister(r) 31 | } 32 | 33 | func (c *client) Deregister(r *consul.AgentServiceRegistration) error { 34 | return c.consul.Agent().ServiceDeregister(r.ID) 35 | } 36 | 37 | func (c *client) Service(service, tag string, passingOnly bool, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) { 38 | return c.consul.Health().Service(service, tag, passingOnly, queryOpts) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/statsd.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/statsd" 6 | ) 7 | 8 | type statsdProvider struct { 9 | s *statsd.Statsd 10 | stop func() 11 | } 12 | 13 | // NewStatsdProvider wraps the given Statsd object and stop func and returns a 14 | // Provider that produces Statsd metrics. A typical stop function would be 15 | // ticker.Stop from the ticker passed to the SendLoop helper method. 16 | func NewStatsdProvider(s *statsd.Statsd, stop func()) Provider { 17 | return &statsdProvider{ 18 | s: s, 19 | stop: stop, 20 | } 21 | } 22 | 23 | // NewCounter implements Provider. 24 | func (p *statsdProvider) NewCounter(name string) metrics.Counter { 25 | return p.s.NewCounter(name, 1.0) 26 | } 27 | 28 | // NewGauge implements Provider. 29 | func (p *statsdProvider) NewGauge(name string) metrics.Gauge { 30 | return p.s.NewGauge(name) 31 | } 32 | 33 | // NewHistogram implements Provider, returning a StatsD Timing that accepts 34 | // observations in milliseconds. The sample rate is fixed at 1.0. The bucket 35 | // parameter is ignored. 36 | func (p *statsdProvider) NewHistogram(name string, _ int) metrics.Histogram { 37 | return p.s.NewTiming(name, 1.0) 38 | } 39 | 40 | // Stop implements Provider, invoking the stop function passed at construction. 41 | func (p *statsdProvider) Stop() { 42 | p.stop() 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/kr/logfmt/example_test.go: -------------------------------------------------------------------------------- 1 | package logfmt_test 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "github.com/kr/logfmt" 7 | "log" 8 | "strconv" 9 | ) 10 | 11 | type Measurement struct { 12 | Key string 13 | Val float64 14 | Unit string // (e.g. ms, MB, etc) 15 | } 16 | 17 | type Measurements []*Measurement 18 | 19 | var measurePrefix = []byte("measure.") 20 | 21 | func (mm *Measurements) HandleLogfmt(key, val []byte) error { 22 | if !bytes.HasPrefix(key, measurePrefix) { 23 | return nil 24 | } 25 | i := bytes.LastIndexFunc(val, isDigit) 26 | v, err := strconv.ParseFloat(string(val[:i+1]), 10) 27 | if err != nil { 28 | return err 29 | } 30 | m := &Measurement{ 31 | Key: string(key[len(measurePrefix):]), 32 | Val: v, 33 | Unit: string(val[i+1:]), 34 | } 35 | *mm = append(*mm, m) 36 | return nil 37 | } 38 | 39 | // return true if r is an ASCII digit only, as opposed to unicode.IsDigit. 40 | func isDigit(r rune) bool { 41 | return '0' <= r && r <= '9' 42 | } 43 | 44 | func Example_customHandler() { 45 | var data = []byte("measure.a=1ms measure.b=10 measure.c=100MB measure.d=1s garbage") 46 | 47 | mm := make(Measurements, 0) 48 | if err := logfmt.Unmarshal(data, &mm); err != nil { 49 | log.Fatalf("err=%q", err) 50 | } 51 | for _, m := range mm { 52 | fmt.Printf("%v\n", *m) 53 | } 54 | // Output: 55 | // {a 1 ms} 56 | // {b 10 } 57 | // {c 100 MB} 58 | // {d 1 s} 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 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 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * 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 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc3/instrumenting.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/go-kit/kit/metrics" 8 | ) 9 | 10 | func instrumentingMiddleware( 11 | requestCount metrics.Counter, 12 | requestLatency metrics.Histogram, 13 | countResult metrics.Histogram, 14 | ) ServiceMiddleware { 15 | return func(next StringService) StringService { 16 | return instrmw{requestCount, requestLatency, countResult, next} 17 | } 18 | } 19 | 20 | type instrmw struct { 21 | requestCount metrics.Counter 22 | requestLatency metrics.Histogram 23 | countResult metrics.Histogram 24 | StringService 25 | } 26 | 27 | func (mw instrmw) Uppercase(s string) (output string, err error) { 28 | defer func(begin time.Time) { 29 | lvs := []string{"method", "uppercase", "error", fmt.Sprint(err != nil)} 30 | mw.requestCount.With(lvs...).Add(1) 31 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) 32 | }(time.Now()) 33 | 34 | output, err = mw.StringService.Uppercase(s) 35 | return 36 | } 37 | 38 | func (mw instrmw) Count(s string) (n int) { 39 | defer func(begin time.Time) { 40 | lvs := []string{"method", "count", "error", "false"} 41 | mw.requestCount.With(lvs...).Add(1) 42 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) 43 | mw.countResult.Observe(float64(n)) 44 | }(time.Now()) 45 | 46 | n = mw.StringService.Count(s) 47 | return 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/expvar/expvar_test.go: -------------------------------------------------------------------------------- 1 | package expvar 2 | 3 | import ( 4 | "strconv" 5 | "testing" 6 | 7 | "github.com/go-kit/kit/metrics/teststat" 8 | ) 9 | 10 | func TestCounter(t *testing.T) { 11 | counter := NewCounter("expvar_counter").With("label values", "not supported").(*Counter) 12 | value := func() float64 { f, _ := strconv.ParseFloat(counter.f.String(), 64); return f } 13 | if err := teststat.TestCounter(counter, value); err != nil { 14 | t.Fatal(err) 15 | } 16 | } 17 | 18 | func TestGauge(t *testing.T) { 19 | gauge := NewGauge("expvar_gauge").With("label values", "not supported").(*Gauge) 20 | value := func() float64 { f, _ := strconv.ParseFloat(gauge.f.String(), 64); return f } 21 | if err := teststat.TestGauge(gauge, value); err != nil { 22 | t.Fatal(err) 23 | } 24 | } 25 | 26 | func TestHistogram(t *testing.T) { 27 | histogram := NewHistogram("expvar_histogram", 50).With("label values", "not supported").(*Histogram) 28 | quantiles := func() (float64, float64, float64, float64) { 29 | p50, _ := strconv.ParseFloat(histogram.p50.String(), 64) 30 | p90, _ := strconv.ParseFloat(histogram.p90.String(), 64) 31 | p95, _ := strconv.ParseFloat(histogram.p95.String(), 64) 32 | p99, _ := strconv.ParseFloat(histogram.p99.String(), 64) 33 | return p50, p90, p95, p99 34 | } 35 | if err := teststat.TestHistogram(histogram, quantiles, 0.01); err != nil { 36 | t.Fatal(err) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/lb/random_test.go: -------------------------------------------------------------------------------- 1 | package lb 2 | 3 | import ( 4 | "context" 5 | "math" 6 | "testing" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | "github.com/go-kit/kit/sd" 10 | ) 11 | 12 | func TestRandom(t *testing.T) { 13 | var ( 14 | n = 7 15 | endpoints = make([]endpoint.Endpoint, n) 16 | counts = make([]int, n) 17 | seed = int64(12345) 18 | iterations = 1000000 19 | want = iterations / n 20 | tolerance = want / 100 // 1% 21 | ) 22 | 23 | for i := 0; i < n; i++ { 24 | i0 := i 25 | endpoints[i] = func(context.Context, interface{}) (interface{}, error) { counts[i0]++; return struct{}{}, nil } 26 | } 27 | 28 | endpointer := sd.FixedEndpointer(endpoints) 29 | balancer := NewRandom(endpointer, seed) 30 | 31 | for i := 0; i < iterations; i++ { 32 | endpoint, _ := balancer.Endpoint() 33 | endpoint(context.Background(), struct{}{}) 34 | } 35 | 36 | for i, have := range counts { 37 | delta := int(math.Abs(float64(want - have))) 38 | if delta > tolerance { 39 | t.Errorf("%d: want %d, have %d, delta %d > %d tolerance", i, want, have, delta, tolerance) 40 | } 41 | } 42 | } 43 | 44 | func TestRandomNoEndpoints(t *testing.T) { 45 | endpointer := sd.FixedEndpointer{} 46 | balancer := NewRandom(endpointer, 1415926) 47 | _, err := balancer.Endpoint() 48 | if want, have := ErrNoEndpoints, err; want != have { 49 | t.Errorf("want %v, have %v", want, have) 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/dogstatsd.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/go-kit/kit/metrics" 5 | "github.com/go-kit/kit/metrics/dogstatsd" 6 | ) 7 | 8 | type dogstatsdProvider struct { 9 | d *dogstatsd.Dogstatsd 10 | stop func() 11 | } 12 | 13 | // NewDogstatsdProvider wraps the given Dogstatsd object and stop func and 14 | // returns a Provider that produces Dogstatsd metrics. A typical stop function 15 | // would be ticker.Stop from the ticker passed to the SendLoop helper method. 16 | func NewDogstatsdProvider(d *dogstatsd.Dogstatsd, stop func()) Provider { 17 | return &dogstatsdProvider{ 18 | d: d, 19 | stop: stop, 20 | } 21 | } 22 | 23 | // NewCounter implements Provider, returning a new Dogstatsd Counter with a 24 | // sample rate of 1.0. 25 | func (p *dogstatsdProvider) NewCounter(name string) metrics.Counter { 26 | return p.d.NewCounter(name, 1.0) 27 | } 28 | 29 | // NewGauge implements Provider. 30 | func (p *dogstatsdProvider) NewGauge(name string) metrics.Gauge { 31 | return p.d.NewGauge(name) 32 | } 33 | 34 | // NewHistogram implements Provider, returning a new Dogstatsd Histogram (note: 35 | // not a Timing) with a sample rate of 1.0. The buckets argument is ignored. 36 | func (p *dogstatsdProvider) NewHistogram(name string, _ int) metrics.Histogram { 37 | return p.d.NewHistogram(name, 1.0) 38 | } 39 | 40 | // Stop implements Provider, invoking the stop function passed at construction. 41 | func (p *dogstatsdProvider) Stop() { 42 | p.stop() 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/aybabtme/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "io" 5 | "os" 6 | "time" 7 | 8 | "github.com/go-kit/kit/log" 9 | ) 10 | 11 | var logger = newLog(os.Stderr) 12 | 13 | type Log struct{ ctx log.Logger } 14 | 15 | func newLog(w io.Writer) *Log { 16 | return &Log{ctx: log.NewJSONLogger(w)} 17 | } 18 | 19 | func (l *Log) KV(k string, v interface{}) *Log { 20 | switch s := v.(type) { 21 | case interface { 22 | String() string 23 | }: 24 | v = s.String() 25 | case interface { 26 | GoString() string 27 | }: 28 | v = s.GoString() 29 | } 30 | 31 | return &Log{ctx: log.With(l.ctx, k, v)} 32 | } 33 | 34 | func (l *Log) Err(err error) *Log { return l.KV("err", err) } 35 | func (l *Log) Error(msg string) { l.log("error", msg) } 36 | func (l *Log) Info(msg string) { l.log("info", msg) } 37 | func (l *Log) Fatal(msg string) { l.log("fatal", msg); os.Exit(1) } 38 | 39 | func (l *Log) log(lvl, msg string) { 40 | err := l.ctx.Log( 41 | "level", lvl, 42 | "msg", msg, 43 | "src", log.DefaultCaller(), 44 | "time", time.Now().UTC().Format(time.RFC3339Nano), 45 | ) 46 | if err != nil { 47 | panic(err) 48 | } 49 | } 50 | 51 | func Err(err error) *Log { return logger.Err(err) } 52 | func Error(msg string) { logger.log("error", msg) } 53 | func Info(msg string) { logger.log("info", msg) } 54 | func Fatal(msg string) { logger.log("fatal", msg); os.Exit(1) } 55 | func KV(k string, v interface{}) *Log { return logger.KV(k, v) } 56 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/wiring_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "net/http" 6 | "net/http/httptest" 7 | "strings" 8 | "testing" 9 | 10 | "github.com/opentracing/opentracing-go" 11 | 12 | "github.com/go-kit/kit/log" 13 | "github.com/go-kit/kit/metrics/discard" 14 | 15 | "github.com/go-kit/kit/examples/addsvc/pkg/addendpoint" 16 | "github.com/go-kit/kit/examples/addsvc/pkg/addservice" 17 | "github.com/go-kit/kit/examples/addsvc/pkg/addtransport" 18 | ) 19 | 20 | func TestHTTP(t *testing.T) { 21 | svc := addservice.New(log.NewNopLogger(), discard.NewCounter(), discard.NewCounter()) 22 | eps := addendpoint.New(svc, log.NewNopLogger(), discard.NewHistogram(), opentracing.GlobalTracer()) 23 | mux := addtransport.NewHTTPHandler(eps, opentracing.GlobalTracer(), log.NewNopLogger()) 24 | srv := httptest.NewServer(mux) 25 | defer srv.Close() 26 | 27 | for _, testcase := range []struct { 28 | method, url, body, want string 29 | }{ 30 | {"GET", srv.URL + "/concat", `{"a":"1","b":"2"}`, `{"v":"12"}`}, 31 | {"GET", srv.URL + "/sum", `{"a":1,"b":2}`, `{"v":3}`}, 32 | } { 33 | req, _ := http.NewRequest(testcase.method, testcase.url, strings.NewReader(testcase.body)) 34 | resp, _ := http.DefaultClient.Do(req) 35 | body, _ := ioutil.ReadAll(resp.Body) 36 | if want, have := testcase.want, strings.TrimSpace(string(body)); want != have { 37 | t.Errorf("%s %s %s: want %q, have %q", testcase.method, testcase.url, testcase.body, want, have) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/voyage/sample_voyages.go: -------------------------------------------------------------------------------- 1 | package voyage 2 | 3 | import "github.com/go-kit/kit/examples/shipping/location" 4 | 5 | // A set of sample voyages. 6 | var ( 7 | V100 = New("V100", Schedule{ 8 | []CarrierMovement{ 9 | {DepartureLocation: location.CNHKG, ArrivalLocation: location.JNTKO}, 10 | {DepartureLocation: location.JNTKO, ArrivalLocation: location.USNYC}, 11 | }, 12 | }) 13 | 14 | V300 = New("V300", Schedule{ 15 | []CarrierMovement{ 16 | {DepartureLocation: location.JNTKO, ArrivalLocation: location.NLRTM}, 17 | {DepartureLocation: location.NLRTM, ArrivalLocation: location.DEHAM}, 18 | {DepartureLocation: location.DEHAM, ArrivalLocation: location.AUMEL}, 19 | {DepartureLocation: location.AUMEL, ArrivalLocation: location.JNTKO}, 20 | }, 21 | }) 22 | 23 | V400 = New("V400", Schedule{ 24 | []CarrierMovement{ 25 | {DepartureLocation: location.DEHAM, ArrivalLocation: location.SESTO}, 26 | {DepartureLocation: location.SESTO, ArrivalLocation: location.FIHEL}, 27 | {DepartureLocation: location.FIHEL, ArrivalLocation: location.DEHAM}, 28 | }, 29 | }) 30 | ) 31 | 32 | // These voyages are hard-coded into the current pathfinder. Make sure 33 | // they exist. 34 | var ( 35 | V0100S = New("0100S", Schedule{[]CarrierMovement{}}) 36 | V0200T = New("0200T", Schedule{[]CarrierMovement{}}) 37 | V0300A = New("0300A", Schedule{[]CarrierMovement{}}) 38 | V0301S = New("0301S", Schedule{[]CarrierMovement{}}) 39 | V0400S = New("0400S", Schedule{[]CarrierMovement{}}) 40 | ) 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/cmd/addsvc/pact_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "strings" 8 | "testing" 9 | 10 | "github.com/pact-foundation/pact-go/dsl" 11 | ) 12 | 13 | func TestPactStringsvcUppercase(t *testing.T) { 14 | if os.Getenv("WRITE_PACTS") == "" { 15 | t.Skip("skipping Pact contracts; set WRITE_PACTS environment variable to enable") 16 | } 17 | 18 | pact := dsl.Pact{ 19 | Port: 6666, 20 | Consumer: "addsvc", 21 | Provider: "stringsvc", 22 | } 23 | defer pact.Teardown() 24 | 25 | pact.AddInteraction(). 26 | UponReceiving("stringsvc uppercase"). 27 | WithRequest(dsl.Request{ 28 | Headers: map[string]string{"Content-Type": "application/json; charset=utf-8"}, 29 | Method: "POST", 30 | Path: "/uppercase", 31 | Body: `{"s":"foo"}`, 32 | }). 33 | WillRespondWith(dsl.Response{ 34 | Status: 200, 35 | Headers: map[string]string{"Content-Type": "application/json; charset=utf-8"}, 36 | Body: `{"v":"FOO"}`, 37 | }) 38 | 39 | if err := pact.Verify(func() error { 40 | u := fmt.Sprintf("http://localhost:%d/uppercase", pact.Server.Port) 41 | req, err := http.NewRequest("POST", u, strings.NewReader(`{"s":"foo"}`)) 42 | if err != nil { 43 | return err 44 | } 45 | req.Header.Set("Content-Type", "application/json; charset=utf-8") 46 | if _, err = http.DefaultClient.Do(req); err != nil { 47 | return err 48 | } 49 | return nil 50 | }); err != nil { 51 | t.Fatal(err) 52 | } 53 | 54 | pact.WritePact() 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/units/bytes_test.go: -------------------------------------------------------------------------------- 1 | package units 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestBase2BytesString(t *testing.T) { 10 | assert.Equal(t, Base2Bytes(0).String(), "0B") 11 | assert.Equal(t, Base2Bytes(1025).String(), "1KiB1B") 12 | assert.Equal(t, Base2Bytes(1048577).String(), "1MiB1B") 13 | } 14 | 15 | func TestParseBase2Bytes(t *testing.T) { 16 | n, err := ParseBase2Bytes("0B") 17 | assert.NoError(t, err) 18 | assert.Equal(t, 0, int(n)) 19 | n, err = ParseBase2Bytes("1KB") 20 | assert.NoError(t, err) 21 | assert.Equal(t, 1024, int(n)) 22 | n, err = ParseBase2Bytes("1MB1KB25B") 23 | assert.NoError(t, err) 24 | assert.Equal(t, 1049625, int(n)) 25 | n, err = ParseBase2Bytes("1.5MB") 26 | assert.NoError(t, err) 27 | assert.Equal(t, 1572864, int(n)) 28 | } 29 | 30 | func TestMetricBytesString(t *testing.T) { 31 | assert.Equal(t, MetricBytes(0).String(), "0B") 32 | assert.Equal(t, MetricBytes(1001).String(), "1KB1B") 33 | assert.Equal(t, MetricBytes(1001025).String(), "1MB1KB25B") 34 | } 35 | 36 | func TestParseMetricBytes(t *testing.T) { 37 | n, err := ParseMetricBytes("0B") 38 | assert.NoError(t, err) 39 | assert.Equal(t, 0, int(n)) 40 | n, err = ParseMetricBytes("1KB1B") 41 | assert.NoError(t, err) 42 | assert.Equal(t, 1001, int(n)) 43 | n, err = ParseMetricBytes("1MB1KB25B") 44 | assert.NoError(t, err) 45 | assert.Equal(t, 1001025, int(n)) 46 | n, err = ParseMetricBytes("1.5MB") 47 | assert.NoError(t, err) 48 | assert.Equal(t, 1500000, int(n)) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/pkg/addendpoint/middleware.go: -------------------------------------------------------------------------------- 1 | package addendpoint 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "time" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | "github.com/go-kit/kit/log" 10 | "github.com/go-kit/kit/metrics" 11 | ) 12 | 13 | // InstrumentingMiddleware returns an endpoint middleware that records 14 | // the duration of each invocation to the passed histogram. The middleware adds 15 | // a single field: "success", which is "true" if no error is returned, and 16 | // "false" otherwise. 17 | func InstrumentingMiddleware(duration metrics.Histogram) endpoint.Middleware { 18 | return func(next endpoint.Endpoint) endpoint.Endpoint { 19 | return func(ctx context.Context, request interface{}) (response interface{}, err error) { 20 | 21 | defer func(begin time.Time) { 22 | duration.With("success", fmt.Sprint(err == nil)).Observe(time.Since(begin).Seconds()) 23 | }(time.Now()) 24 | return next(ctx, request) 25 | 26 | } 27 | } 28 | } 29 | 30 | // LoggingMiddleware returns an endpoint middleware that logs the 31 | // duration of each invocation, and the resulting error, if any. 32 | func LoggingMiddleware(logger log.Logger) endpoint.Middleware { 33 | return func(next endpoint.Endpoint) endpoint.Endpoint { 34 | return func(ctx context.Context, request interface{}) (response interface{}, err error) { 35 | 36 | defer func(begin time.Time) { 37 | logger.Log("transport_error", err, "took", time.Since(begin)) 38 | }(time.Now()) 39 | return next(ctx, request) 40 | 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/client_test.go: -------------------------------------------------------------------------------- 1 | package grpc_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net" 7 | "testing" 8 | 9 | "google.golang.org/grpc" 10 | 11 | test "github.com/go-kit/kit/transport/grpc/_grpc_test" 12 | "github.com/go-kit/kit/transport/grpc/_grpc_test/pb" 13 | ) 14 | 15 | const ( 16 | hostPort string = "localhost:8002" 17 | ) 18 | 19 | func TestGRPCClient(t *testing.T) { 20 | var ( 21 | server = grpc.NewServer() 22 | service = test.NewService() 23 | ) 24 | 25 | sc, err := net.Listen("tcp", hostPort) 26 | if err != nil { 27 | t.Fatalf("unable to listen: %+v", err) 28 | } 29 | defer server.GracefulStop() 30 | 31 | go func() { 32 | pb.RegisterTestServer(server, test.NewBinding(service)) 33 | _ = server.Serve(sc) 34 | }() 35 | 36 | cc, err := grpc.Dial(hostPort, grpc.WithInsecure()) 37 | if err != nil { 38 | t.Fatalf("unable to Dial: %+v", err) 39 | } 40 | 41 | client := test.NewClient(cc) 42 | 43 | var ( 44 | a = "the answer to life the universe and everything" 45 | b = int64(42) 46 | cID = "request-1" 47 | ctx = test.SetCorrelationID(context.Background(), cID) 48 | ) 49 | 50 | responseCTX, v, err := client.Test(ctx, a, b) 51 | if err != nil { 52 | t.Fatalf("unable to Test: %+v", err) 53 | } 54 | if want, have := fmt.Sprintf("%s = %d", a, b), v; want != have { 55 | t.Fatalf("want %q, have %q", want, have) 56 | } 57 | 58 | if want, have := cID, test.GetConsumedCorrelationID(responseCTX); want != have { 59 | t.Fatalf("want %q, have %q", want, have) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/context/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Moraes. 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/gorilla/mux/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Moraes. 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/go-kit/kit/examples/shipping/inspection/inspection.go: -------------------------------------------------------------------------------- 1 | // Package inspection provides means to inspect cargos. 2 | package inspection 3 | 4 | import ( 5 | "github.com/go-kit/kit/examples/shipping/cargo" 6 | ) 7 | 8 | // EventHandler provides means of subscribing to inspection events. 9 | type EventHandler interface { 10 | CargoWasMisdirected(*cargo.Cargo) 11 | CargoHasArrived(*cargo.Cargo) 12 | } 13 | 14 | // Service provides cargo inspection operations. 15 | type Service interface { 16 | // InspectCargo inspects cargo and send relevant notifications to 17 | // interested parties, for example if a cargo has been misdirected, or 18 | // unloaded at the final destination. 19 | InspectCargo(id cargo.TrackingID) 20 | } 21 | 22 | type service struct { 23 | cargos cargo.Repository 24 | events cargo.HandlingEventRepository 25 | handler EventHandler 26 | } 27 | 28 | // TODO: Should be transactional 29 | func (s *service) InspectCargo(id cargo.TrackingID) { 30 | c, err := s.cargos.Find(id) 31 | if err != nil { 32 | return 33 | } 34 | 35 | h := s.events.QueryHandlingHistory(id) 36 | 37 | c.DeriveDeliveryProgress(h) 38 | 39 | if c.Delivery.IsMisdirected { 40 | s.handler.CargoWasMisdirected(c) 41 | } 42 | 43 | if c.Delivery.IsUnloadedAtDestination { 44 | s.handler.CargoHasArrived(c) 45 | } 46 | 47 | s.cargos.Store(c) 48 | } 49 | 50 | // NewService creates a inspection service with necessary dependencies. 51 | func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository, handler EventHandler) Service { 52 | return &service{cargos, events, handler} 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 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/github.com/gorilla/mux/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Gorilla 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 mux 6 | 7 | import ( 8 | "net/http" 9 | "net/http/httptest" 10 | "testing" 11 | ) 12 | 13 | func BenchmarkMux(b *testing.B) { 14 | router := new(Router) 15 | handler := func(w http.ResponseWriter, r *http.Request) {} 16 | router.HandleFunc("/v1/{v1}", handler) 17 | 18 | request, _ := http.NewRequest("GET", "/v1/anything", nil) 19 | for i := 0; i < b.N; i++ { 20 | router.ServeHTTP(nil, request) 21 | } 22 | } 23 | 24 | func BenchmarkMuxAlternativeInRegexp(b *testing.B) { 25 | router := new(Router) 26 | handler := func(w http.ResponseWriter, r *http.Request) {} 27 | router.HandleFunc("/v1/{v1:(?:a|b)}", handler) 28 | 29 | requestA, _ := http.NewRequest("GET", "/v1/a", nil) 30 | requestB, _ := http.NewRequest("GET", "/v1/b", nil) 31 | for i := 0; i < b.N; i++ { 32 | router.ServeHTTP(nil, requestA) 33 | router.ServeHTTP(nil, requestB) 34 | } 35 | } 36 | 37 | func BenchmarkManyPathVariables(b *testing.B) { 38 | router := new(Router) 39 | handler := func(w http.ResponseWriter, r *http.Request) {} 40 | router.HandleFunc("/v1/{v1}/{v2}/{v3}/{v4}/{v5}", handler) 41 | 42 | matchingRequest, _ := http.NewRequest("GET", "/v1/1/2/3/4/5", nil) 43 | notMatchingRequest, _ := http.NewRequest("GET", "/v1/1/2/3/4", nil) 44 | recorder := httptest.NewRecorder() 45 | for i := 0; i < b.N; i++ { 46 | router.ServeHTTP(nil, matchingRequest) 47 | router.ServeHTTP(recorder, notMatchingRequest) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/zk/registrar.go: -------------------------------------------------------------------------------- 1 | package zk 2 | 3 | import "github.com/go-kit/kit/log" 4 | 5 | // Registrar registers service instance liveness information to ZooKeeper. 6 | type Registrar struct { 7 | client Client 8 | service Service 9 | logger log.Logger 10 | } 11 | 12 | // Service holds the root path, service name and instance identifying data you 13 | // want to publish to ZooKeeper. 14 | type Service struct { 15 | Path string // discovery namespace, example: /myorganization/myplatform/ 16 | Name string // service name, example: addscv 17 | Data []byte // instance data to store for discovery, example: 10.0.2.10:80 18 | node string // Client will record the ephemeral node name so we can deregister 19 | } 20 | 21 | // NewRegistrar returns a ZooKeeper Registrar acting on the provided catalog 22 | // registration. 23 | func NewRegistrar(client Client, service Service, logger log.Logger) *Registrar { 24 | return &Registrar{ 25 | client: client, 26 | service: service, 27 | logger: log.With(logger, 28 | "service", service.Name, 29 | "path", service.Path, 30 | "data", string(service.Data), 31 | ), 32 | } 33 | } 34 | 35 | // Register implements sd.Registrar interface. 36 | func (r *Registrar) Register() { 37 | if err := r.client.Register(&r.service); err != nil { 38 | r.logger.Log("err", err) 39 | } else { 40 | r.logger.Log("action", "register") 41 | } 42 | } 43 | 44 | // Deregister implements sd.Registrar interface. 45 | func (r *Registrar) Deregister() { 46 | if err := r.client.Deregister(&r.service); err != nil { 47 | r.logger.Log("err", err) 48 | } else { 49 | r.logger.Log("action", "deregister") 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/kr/logfmt/scanner_test.go: -------------------------------------------------------------------------------- 1 | package logfmt 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestScannerSimple(t *testing.T) { 9 | type T struct { 10 | k string 11 | v string 12 | } 13 | 14 | tests := []struct { 15 | data string 16 | want []T 17 | }{ 18 | { 19 | `a=1 b="bar" ƒ=2h3s r="esc\t" d x=sf `, 20 | []T{ 21 | {"a", "1"}, 22 | {"b", "bar"}, 23 | {"ƒ", "2h3s"}, 24 | {"r", "esc\t"}, 25 | {"d", ""}, 26 | {"x", "sf"}, 27 | }, 28 | }, 29 | {`x= `, []T{{"x", ""}}}, 30 | {`y=`, []T{{"y", ""}}}, 31 | {`y`, []T{{"y", ""}}}, 32 | {`y=f`, []T{{"y", "f"}}}, 33 | } 34 | 35 | for _, test := range tests { 36 | var got []T 37 | h := func(key, val []byte) error { 38 | got = append(got, T{string(key), string(val)}) 39 | return nil 40 | } 41 | gotoScanner([]byte(test.data), HandlerFunc(h)) 42 | if !reflect.DeepEqual(test.want, got) { 43 | t.Errorf("want %q, got %q", test.want, got) 44 | } 45 | } 46 | 47 | var called bool 48 | h := func(key, val []byte) error { called = true; return nil } 49 | err := gotoScanner([]byte(`foo="b`), HandlerFunc(h)) 50 | if err != ErrUnterminatedString { 51 | t.Errorf("want %v, got %v", ErrUnterminatedString, err) 52 | } 53 | if called { 54 | t.Error("did not expect call to handler") 55 | } 56 | } 57 | 58 | func TestScannerAllocs(t *testing.T) { 59 | data := []byte(`a=1 b="bar" ƒ=2h3s r="esc\t" d x=sf `) 60 | h := func(key, val []byte) error { return nil } 61 | allocs := testing.AllocsPerRun(1000, func() { 62 | gotoScanner(data, HandlerFunc(h)) 63 | }) 64 | if allocs > 1 { 65 | t.Errorf("got %f, want <=1", allocs) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/logfmt_logger.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "sync" 7 | 8 | "github.com/go-logfmt/logfmt" 9 | ) 10 | 11 | type logfmtEncoder struct { 12 | *logfmt.Encoder 13 | buf bytes.Buffer 14 | } 15 | 16 | func (l *logfmtEncoder) Reset() { 17 | l.Encoder.Reset() 18 | l.buf.Reset() 19 | } 20 | 21 | var logfmtEncoderPool = sync.Pool{ 22 | New: func() interface{} { 23 | var enc logfmtEncoder 24 | enc.Encoder = logfmt.NewEncoder(&enc.buf) 25 | return &enc 26 | }, 27 | } 28 | 29 | type logfmtLogger struct { 30 | w io.Writer 31 | } 32 | 33 | // NewLogfmtLogger returns a logger that encodes keyvals to the Writer in 34 | // logfmt format. Each log event produces no more than one call to w.Write. 35 | // The passed Writer must be safe for concurrent use by multiple goroutines if 36 | // the returned Logger will be used concurrently. 37 | func NewLogfmtLogger(w io.Writer) Logger { 38 | return &logfmtLogger{w} 39 | } 40 | 41 | func (l logfmtLogger) Log(keyvals ...interface{}) error { 42 | enc := logfmtEncoderPool.Get().(*logfmtEncoder) 43 | enc.Reset() 44 | defer logfmtEncoderPool.Put(enc) 45 | 46 | if err := enc.EncodeKeyvals(keyvals...); err != nil { 47 | return err 48 | } 49 | 50 | // Add newline to the end of the buffer 51 | if err := enc.EndRecord(); err != nil { 52 | return err 53 | } 54 | 55 | // The Logger interface requires implementations to be safe for concurrent 56 | // use by multiple goroutines. For this implementation that means making 57 | // only one call to l.w.Write() for each call to Log. 58 | if _, err := l.w.Write(enc.buf.Bytes()); err != nil { 59 | return err 60 | } 61 | return nil 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/example_test.go: -------------------------------------------------------------------------------- 1 | package term_test 2 | 3 | import ( 4 | "errors" 5 | "os" 6 | 7 | "github.com/go-kit/kit/log" 8 | "github.com/go-kit/kit/log/term" 9 | ) 10 | 11 | func ExampleNewLogger_redErrors() { 12 | // Color errors red 13 | colorFn := func(keyvals ...interface{}) term.FgBgColor { 14 | for i := 1; i < len(keyvals); i += 2 { 15 | if _, ok := keyvals[i].(error); ok { 16 | return term.FgBgColor{Fg: term.White, Bg: term.Red} 17 | } 18 | } 19 | return term.FgBgColor{} 20 | } 21 | 22 | logger := term.NewLogger(os.Stdout, log.NewLogfmtLogger, colorFn) 23 | 24 | logger.Log("msg", "default color", "err", nil) 25 | logger.Log("msg", "colored because of error", "err", errors.New("coloring error")) 26 | } 27 | 28 | func ExampleNewLogger_levelColors() { 29 | // Color by level value 30 | colorFn := func(keyvals ...interface{}) term.FgBgColor { 31 | for i := 0; i < len(keyvals)-1; i += 2 { 32 | if keyvals[i] != "level" { 33 | continue 34 | } 35 | switch keyvals[i+1] { 36 | case "debug": 37 | return term.FgBgColor{Fg: term.DarkGray} 38 | case "info": 39 | return term.FgBgColor{Fg: term.Gray} 40 | case "warn": 41 | return term.FgBgColor{Fg: term.Yellow} 42 | case "error": 43 | return term.FgBgColor{Fg: term.Red} 44 | case "crit": 45 | return term.FgBgColor{Fg: term.Gray, Bg: term.DarkRed} 46 | default: 47 | return term.FgBgColor{} 48 | } 49 | } 50 | return term.FgBgColor{} 51 | } 52 | 53 | logger := term.NewLogger(os.Stdout, log.NewJSONLogger, colorFn) 54 | 55 | logger.Log("level", "warn", "msg", "yellow") 56 | logger.Log("level", "debug", "msg", "dark gray") 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/timer_test.go: -------------------------------------------------------------------------------- 1 | package metrics_test 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | 7 | "time" 8 | 9 | "github.com/go-kit/kit/metrics" 10 | "github.com/go-kit/kit/metrics/generic" 11 | ) 12 | 13 | func TestTimerFast(t *testing.T) { 14 | h := generic.NewSimpleHistogram() 15 | metrics.NewTimer(h).ObserveDuration() 16 | 17 | tolerance := 0.050 18 | if want, have := 0.000, h.ApproximateMovingAverage(); math.Abs(want-have) > tolerance { 19 | t.Errorf("want %.3f, have %.3f", want, have) 20 | } 21 | } 22 | 23 | func TestTimerSlow(t *testing.T) { 24 | h := generic.NewSimpleHistogram() 25 | timer := metrics.NewTimer(h) 26 | time.Sleep(250 * time.Millisecond) 27 | timer.ObserveDuration() 28 | 29 | tolerance := 0.050 30 | if want, have := 0.250, h.ApproximateMovingAverage(); math.Abs(want-have) > tolerance { 31 | t.Errorf("want %.3f, have %.3f", want, have) 32 | } 33 | } 34 | 35 | func TestTimerUnit(t *testing.T) { 36 | for _, tc := range []struct { 37 | name string 38 | unit time.Duration 39 | tolerance float64 40 | want float64 41 | }{ 42 | {"Seconds", time.Second, 0.010, 0.100}, 43 | {"Milliseconds", time.Millisecond, 10, 100}, 44 | {"Nanoseconds", time.Nanosecond, 10000000, 100000000}, 45 | } { 46 | t.Run(tc.name, func(t *testing.T) { 47 | h := generic.NewSimpleHistogram() 48 | timer := metrics.NewTimer(h) 49 | time.Sleep(100 * time.Millisecond) 50 | timer.Unit(tc.unit) 51 | timer.ObserveDuration() 52 | 53 | if want, have := tc.want, h.ApproximateMovingAverage(); math.Abs(want-have) > tc.tolerance { 54 | t.Errorf("want %.3f, have %.3f", want, have) 55 | } 56 | }) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/etcd/instancer_test.go: -------------------------------------------------------------------------------- 1 | package etcd 2 | 3 | import ( 4 | "errors" 5 | "testing" 6 | 7 | stdetcd "github.com/coreos/etcd/client" 8 | 9 | "github.com/go-kit/kit/log" 10 | "github.com/go-kit/kit/sd" 11 | ) 12 | 13 | var _ sd.Instancer = (*Instancer)(nil) // API check 14 | 15 | var ( 16 | node = &stdetcd.Node{ 17 | Key: "/foo", 18 | Nodes: []*stdetcd.Node{ 19 | {Key: "/foo/1", Value: "1:1"}, 20 | {Key: "/foo/2", Value: "1:2"}, 21 | }, 22 | } 23 | fakeResponse = &stdetcd.Response{ 24 | Node: node, 25 | } 26 | ) 27 | 28 | var _ sd.Instancer = &Instancer{} // API check 29 | 30 | func TestInstancer(t *testing.T) { 31 | client := &fakeClient{ 32 | responses: map[string]*stdetcd.Response{"/foo": fakeResponse}, 33 | } 34 | 35 | s, err := NewInstancer(client, "/foo", log.NewNopLogger()) 36 | if err != nil { 37 | t.Fatal(err) 38 | } 39 | defer s.Stop() 40 | 41 | if state := s.cache.State(); state.Err != nil { 42 | t.Fatal(state.Err) 43 | } 44 | } 45 | 46 | type fakeClient struct { 47 | responses map[string]*stdetcd.Response 48 | } 49 | 50 | func (c *fakeClient) GetEntries(prefix string) ([]string, error) { 51 | response, ok := c.responses[prefix] 52 | if !ok { 53 | return nil, errors.New("key not exist") 54 | } 55 | 56 | entries := make([]string, len(response.Node.Nodes)) 57 | for i, node := range response.Node.Nodes { 58 | entries[i] = node.Value 59 | } 60 | return entries, nil 61 | } 62 | 63 | func (c *fakeClient) WatchPrefix(prefix string, ch chan struct{}) {} 64 | 65 | func (c *fakeClient) Register(Service) error { 66 | return nil 67 | } 68 | func (c *fakeClient) Deregister(Service) error { 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/logfmt_logger_test.go: -------------------------------------------------------------------------------- 1 | package log_test 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "io/ioutil" 7 | "testing" 8 | 9 | "github.com/go-kit/kit/log" 10 | "github.com/go-logfmt/logfmt" 11 | ) 12 | 13 | func TestLogfmtLogger(t *testing.T) { 14 | t.Parallel() 15 | buf := &bytes.Buffer{} 16 | logger := log.NewLogfmtLogger(buf) 17 | 18 | if err := logger.Log("hello", "world"); err != nil { 19 | t.Fatal(err) 20 | } 21 | if want, have := "hello=world\n", buf.String(); want != have { 22 | t.Errorf("want %#v, have %#v", want, have) 23 | } 24 | 25 | buf.Reset() 26 | if err := logger.Log("a", 1, "err", errors.New("error")); err != nil { 27 | t.Fatal(err) 28 | } 29 | if want, have := "a=1 err=error\n", buf.String(); want != have { 30 | t.Errorf("want %#v, have %#v", want, have) 31 | } 32 | 33 | buf.Reset() 34 | if err := logger.Log("std_map", map[int]int{1: 2}, "my_map", mymap{0: 0}); err != nil { 35 | t.Fatal(err) 36 | } 37 | if want, have := "std_map=\""+logfmt.ErrUnsupportedValueType.Error()+"\" my_map=special_behavior\n", buf.String(); want != have { 38 | t.Errorf("want %#v, have %#v", want, have) 39 | } 40 | } 41 | 42 | func BenchmarkLogfmtLoggerSimple(b *testing.B) { 43 | benchmarkRunner(b, log.NewLogfmtLogger(ioutil.Discard), baseMessage) 44 | } 45 | 46 | func BenchmarkLogfmtLoggerContextual(b *testing.B) { 47 | benchmarkRunner(b, log.NewLogfmtLogger(ioutil.Discard), withMessage) 48 | } 49 | 50 | func TestLogfmtLoggerConcurrency(t *testing.T) { 51 | t.Parallel() 52 | testConcurrency(t, log.NewLogfmtLogger(ioutil.Discard), 10000) 53 | } 54 | 55 | type mymap map[int]int 56 | 57 | func (m mymap) String() string { return "special_behavior" } 58 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/encode_decode.go: -------------------------------------------------------------------------------- 1 | package grpc 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | // DecodeRequestFunc extracts a user-domain request object from a gRPC request. 8 | // It's designed to be used in gRPC servers, for server-side endpoints. One 9 | // straightforward DecodeRequestFunc could be something that decodes from the 10 | // gRPC request message to the concrete request type. 11 | type DecodeRequestFunc func(context.Context, interface{}) (request interface{}, err error) 12 | 13 | // EncodeRequestFunc encodes the passed request object into the gRPC request 14 | // object. It's designed to be used in gRPC clients, for client-side endpoints. 15 | // One straightforward EncodeRequestFunc could something that encodes the object 16 | // directly to the gRPC request message. 17 | type EncodeRequestFunc func(context.Context, interface{}) (request interface{}, err error) 18 | 19 | // EncodeResponseFunc encodes the passed response object to the gRPC response 20 | // message. It's designed to be used in gRPC servers, for server-side endpoints. 21 | // One straightforward EncodeResponseFunc could be something that encodes the 22 | // object directly to the gRPC response message. 23 | type EncodeResponseFunc func(context.Context, interface{}) (response interface{}, err error) 24 | 25 | // DecodeResponseFunc extracts a user-domain response object from a gRPC 26 | // response object. It's designed to be used in gRPC clients, for client-side 27 | // endpoints. One straightforward DecodeResponseFunc could be something that 28 | // decodes from the gRPC response message to the concrete response type. 29 | type DecodeResponseFunc func(context.Context, interface{}) (response interface{}, err error) 30 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/http/encode_decode.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | ) 7 | 8 | // DecodeRequestFunc extracts a user-domain request object from an HTTP 9 | // request object. It's designed to be used in HTTP servers, for server-side 10 | // endpoints. One straightforward DecodeRequestFunc could be something that 11 | // JSON decodes from the request body to the concrete response type. 12 | type DecodeRequestFunc func(context.Context, *http.Request) (request interface{}, err error) 13 | 14 | // EncodeRequestFunc encodes the passed request object into the HTTP request 15 | // object. It's designed to be used in HTTP clients, for client-side 16 | // endpoints. One straightforward EncodeRequestFunc could something that JSON 17 | // encodes the object directly to the request body. 18 | type EncodeRequestFunc func(context.Context, *http.Request, interface{}) error 19 | 20 | // EncodeResponseFunc encodes the passed response object to the HTTP response 21 | // writer. It's designed to be used in HTTP servers, for server-side 22 | // endpoints. One straightforward EncodeResponseFunc could be something that 23 | // JSON encodes the object directly to the response body. 24 | type EncodeResponseFunc func(context.Context, http.ResponseWriter, interface{}) error 25 | 26 | // DecodeResponseFunc extracts a user-domain response object from an HTTP 27 | // response object. It's designed to be used in HTTP clients, for client-side 28 | // endpoints. One straightforward DecodeResponseFunc could be something that 29 | // JSON decodes from the response body to the concrete response type. 30 | type DecodeResponseFunc func(context.Context, *http.Response) (response interface{}, err error) 31 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/README.md: -------------------------------------------------------------------------------- 1 | [![GoDoc](https://godoc.org/github.com/go-stack/stack?status.svg)](https://godoc.org/github.com/go-stack/stack) 2 | [![Go Report Card](https://goreportcard.com/badge/go-stack/stack)](https://goreportcard.com/report/go-stack/stack) 3 | [![TravisCI](https://travis-ci.org/go-stack/stack.svg?branch=master)](https://travis-ci.org/go-stack/stack) 4 | [![Coverage Status](https://coveralls.io/repos/github/go-stack/stack/badge.svg?branch=master)](https://coveralls.io/github/go-stack/stack?branch=master) 5 | 6 | # stack 7 | 8 | Package stack implements utilities to capture, manipulate, and format call 9 | stacks. It provides a simpler API than package runtime. 10 | 11 | The implementation takes care of the minutia and special cases of interpreting 12 | the program counter (pc) values returned by runtime.Callers. 13 | 14 | ## Versioning 15 | 16 | Package stack publishes releases via [semver](http://semver.org/) compatible Git 17 | tags prefixed with a single 'v'. The master branch always contains the latest 18 | release. The develop branch contains unreleased commits. 19 | 20 | ## Formatting 21 | 22 | Package stack's types implement fmt.Formatter, which provides a simple and 23 | flexible way to declaratively configure formatting when used with logging or 24 | error tracking packages. 25 | 26 | ```go 27 | func DoTheThing() { 28 | c := stack.Caller(0) 29 | log.Print(c) // "source.go:10" 30 | log.Printf("%+v", c) // "pkg/path/source.go:10" 31 | log.Printf("%n", c) // "DoTheThing" 32 | 33 | s := stack.Trace().TrimRuntime() 34 | log.Print(s) // "[source.go:15 caller.go:42 main.go:14]" 35 | } 36 | ``` 37 | 38 | See the docs for all of the supported formatting options. 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/decode-bench_test.go: -------------------------------------------------------------------------------- 1 | package logfmt 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "testing" 7 | 8 | kr "github.com/kr/logfmt" 9 | ) 10 | 11 | func BenchmarkDecodeKeyval(b *testing.B) { 12 | const rows = 10000 13 | data := []byte{} 14 | for i := 0; i < rows; i++ { 15 | data = append(data, "a=1 b=\"bar\" ƒ=2h3s r=\"esc\\tmore stuff\" d x=sf \n"...) 16 | } 17 | 18 | b.SetBytes(int64(len(data))) 19 | b.ResetTimer() 20 | for i := 0; i < b.N; i++ { 21 | var ( 22 | dec = NewDecoder(bytes.NewReader(data)) 23 | j = 0 24 | ) 25 | for dec.ScanRecord() { 26 | for dec.ScanKeyval() { 27 | } 28 | j++ 29 | } 30 | if err := dec.Err(); err != nil { 31 | b.Errorf("got %v, want %v", err, nil) 32 | } 33 | if j != rows { 34 | b.Errorf("got %v, want %v", j, rows) 35 | } 36 | } 37 | } 38 | 39 | func BenchmarkKRDecode(b *testing.B) { 40 | const rows = 10000 41 | data := []byte{} 42 | for i := 0; i < rows; i++ { 43 | data = append(data, "a=1 b=\"bar\" ƒ=2h3s r=\"esc\\tmore stuff\" d x=sf \n"...) 44 | } 45 | 46 | b.SetBytes(int64(len(data))) 47 | b.ResetTimer() 48 | for i := 0; i < b.N; i++ { 49 | var ( 50 | s = bufio.NewScanner(bytes.NewReader(data)) 51 | err error 52 | j = 0 53 | dh discardHandler 54 | ) 55 | for err == nil && s.Scan() { 56 | err = kr.Unmarshal(s.Bytes(), &dh) 57 | j++ 58 | } 59 | if err == nil { 60 | err = s.Err() 61 | } 62 | if err != nil { 63 | b.Errorf("got %v, want %v", err, nil) 64 | } 65 | if j != rows { 66 | b.Errorf("got %v, want %v", j, rows) 67 | } 68 | } 69 | } 70 | 71 | type discardHandler struct{} 72 | 73 | func (discardHandler) HandleLogfmt(key, val []byte) error { 74 | return nil 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/httprp/server.go: -------------------------------------------------------------------------------- 1 | package httprp 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "net/http/httputil" 7 | "net/url" 8 | ) 9 | 10 | // RequestFunc may take information from an HTTP request and put it into a 11 | // request context. BeforeFuncs are executed prior to invoking the 12 | // endpoint. 13 | type RequestFunc func(context.Context, *http.Request) context.Context 14 | 15 | // Server is a proxying request handler. 16 | type Server struct { 17 | proxy http.Handler 18 | before []RequestFunc 19 | errorEncoder func(w http.ResponseWriter, err error) 20 | } 21 | 22 | // NewServer constructs a new server that implements http.Server and will proxy 23 | // requests to the given base URL using its scheme, host, and base path. 24 | // If the target's path is "/base" and the incoming request was for "/dir", 25 | // the target request will be for /base/dir. 26 | func NewServer( 27 | baseURL *url.URL, 28 | options ...ServerOption, 29 | ) *Server { 30 | s := &Server{ 31 | proxy: httputil.NewSingleHostReverseProxy(baseURL), 32 | } 33 | for _, option := range options { 34 | option(s) 35 | } 36 | return s 37 | } 38 | 39 | // ServerOption sets an optional parameter for servers. 40 | type ServerOption func(*Server) 41 | 42 | // ServerBefore functions are executed on the HTTP request object before the 43 | // request is decoded. 44 | func ServerBefore(before ...RequestFunc) ServerOption { 45 | return func(s *Server) { s.before = append(s.before, before...) } 46 | } 47 | 48 | // ServeHTTP implements http.Handler. 49 | func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { 50 | ctx := r.Context() 51 | 52 | for _, f := range s.before { 53 | ctx = f(ctx, r) 54 | } 55 | 56 | s.proxy.ServeHTTP(w, r) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/provider/provider.go: -------------------------------------------------------------------------------- 1 | // Package provider provides a factory-like abstraction for metrics backends. 2 | // This package is provided specifically for the needs of the NY Times framework 3 | // Gizmo. Most normal Go kit users shouldn't need to use it. 4 | // 5 | // Normally, if your microservice needs to support different metrics backends, 6 | // you can simply do different construction based on a flag. For example, 7 | // 8 | // var latency metrics.Histogram 9 | // var requests metrics.Counter 10 | // switch *metricsBackend { 11 | // case "prometheus": 12 | // latency = prometheus.NewSummaryVec(...) 13 | // requests = prometheus.NewCounterVec(...) 14 | // case "statsd": 15 | // s := statsd.New(...) 16 | // t := time.NewTicker(5*time.Second) 17 | // go s.SendLoop(t.C, "tcp", "statsd.local:8125") 18 | // latency = s.NewHistogram(...) 19 | // requests = s.NewCounter(...) 20 | // default: 21 | // log.Fatal("unsupported metrics backend %q", *metricsBackend) 22 | // } 23 | // 24 | package provider 25 | 26 | import ( 27 | "github.com/go-kit/kit/metrics" 28 | ) 29 | 30 | // Provider abstracts over constructors and lifecycle management functions for 31 | // each supported metrics backend. It should only be used by those who need to 32 | // swap out implementations dynamically. 33 | // 34 | // This is primarily useful for intermediating frameworks, and is likely 35 | // unnecessary for most Go kit services. See the package-level doc comment for 36 | // more typical usage instructions. 37 | type Provider interface { 38 | NewCounter(name string) metrics.Counter 39 | NewGauge(name string) metrics.Gauge 40 | NewHistogram(name string, buckets int) metrics.Histogram 41 | Stop() 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/instancer.go: -------------------------------------------------------------------------------- 1 | package sd 2 | 3 | // Event represents a push notification generated from the underlying service discovery 4 | // implementation. It contains either a full set of available resource instances, or 5 | // an error indicating some issue with obtaining information from discovery backend. 6 | // Examples of errors may include loosing connection to the discovery backend, or 7 | // trying to look up resource instances using an incorrectly formatted key. 8 | // After receiving an Event with an error the listenter should treat previously discovered 9 | // resource instances as stale (although it may choose to continue using them). 10 | // If the Instancer is able to restore connection to the discovery backend it must push 11 | // another Event with the current set of resource instances. 12 | type Event struct { 13 | Instances []string 14 | Err error 15 | } 16 | 17 | // Instancer listens to a service discovery system and notifies registered 18 | // observers of changes in the resource instances. Every event sent to the channels 19 | // contains a complete set of instances known to the Instancer. That complete set is 20 | // sent immediately upon registering the channel, and on any future updates from 21 | // discovery system. 22 | type Instancer interface { 23 | Register(chan<- Event) 24 | Deregister(chan<- Event) 25 | Stop() 26 | } 27 | 28 | // FixedInstancer yields a fixed set of instances. 29 | type FixedInstancer []string 30 | 31 | // Register implements Instancer. 32 | func (d FixedInstancer) Register(ch chan<- Event) { ch <- Event{Instances: d} } 33 | 34 | // Deregister implements Instancer. 35 | func (d FixedInstancer) Deregister(ch chan<- Event) {} 36 | 37 | // Stop implements Instancer. 38 | func (d FixedInstancer) Stop() {} 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-logfmt/logfmt/README.md: -------------------------------------------------------------------------------- 1 | [![GoDoc](https://godoc.org/github.com/go-logfmt/logfmt?status.svg)](https://godoc.org/github.com/go-logfmt/logfmt) 2 | [![Go Report Card](https://goreportcard.com/badge/go-logfmt/logfmt)](https://goreportcard.com/report/go-logfmt/logfmt) 3 | [![TravisCI](https://travis-ci.org/go-logfmt/logfmt.svg?branch=master)](https://travis-ci.org/go-logfmt/logfmt) 4 | [![Coverage Status](https://coveralls.io/repos/github/go-logfmt/logfmt/badge.svg?branch=master)](https://coveralls.io/github/go-logfmt/logfmt?branch=master) 5 | 6 | # logfmt 7 | 8 | Package logfmt implements utilities to marshal and unmarshal data in the [logfmt 9 | format](https://brandur.org/logfmt). It provides an API similar to 10 | [encoding/json](http://golang.org/pkg/encoding/json/) and 11 | [encoding/xml](http://golang.org/pkg/encoding/xml/). 12 | 13 | The logfmt format was first documented by Brandur Leach in [this 14 | article](https://brandur.org/logfmt). The format has not been formally 15 | standardized. The most authoritative public specification to date has been the 16 | documentation of a Go Language [package](http://godoc.org/github.com/kr/logfmt) 17 | written by Blake Mizerany and Keith Rarick. 18 | 19 | ## Goals 20 | 21 | This project attempts to conform as closely as possible to the prior art, while 22 | also removing ambiguity where necessary to provide well behaved encoder and 23 | decoder implementations. 24 | 25 | ## Non-goals 26 | 27 | This project does not attempt to formally standardize the logfmt format. In the 28 | event that logfmt is standardized this project would take conforming to the 29 | standard as a goal. 30 | 31 | ## Versioning 32 | 33 | Package logfmt publishes releases via [semver](http://semver.org/) compatible Git tags prefixed with a single 'v'. 34 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/stack-go19_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.9 2 | 3 | package stack_test 4 | 5 | import ( 6 | "runtime" 7 | "testing" 8 | 9 | "github.com/go-stack/stack" 10 | ) 11 | 12 | func TestCallerInlinedPanic(t *testing.T) { 13 | t.Parallel() 14 | 15 | var line int 16 | 17 | defer func() { 18 | if recover() != nil { 19 | var pcs [32]uintptr 20 | n := runtime.Callers(1, pcs[:]) 21 | frames := runtime.CallersFrames(pcs[:n]) 22 | // count frames to runtime.sigpanic 23 | panicIdx := 0 24 | for { 25 | f, more := frames.Next() 26 | if f.Function == "runtime.sigpanic" { 27 | break 28 | } 29 | panicIdx++ 30 | if !more { 31 | t.Fatal("no runtime.sigpanic entry on the stack") 32 | } 33 | } 34 | 35 | c := stack.Caller(panicIdx) 36 | if got, want := c.Frame().Function, "runtime.sigpanic"; got != want { 37 | t.Errorf("sigpanic frame: got name == %v, want name == %v", got, want) 38 | } 39 | 40 | c1 := stack.Caller(panicIdx + 1) 41 | if got, want := c1.Frame().Function, "github.com/go-stack/stack_test.inlinablePanic"; got != want { 42 | t.Errorf("TestCallerInlinedPanic frame: got name == %v, want name == %v", got, want) 43 | } 44 | if got, want := c1.Frame().Line, line; got != want { 45 | t.Errorf("TestCallerInlinedPanic frame: got line == %v, want line == %v", got, want) 46 | } 47 | } 48 | }() 49 | 50 | doPanic(t, &line) 51 | t.Fatal("failed to panic") 52 | } 53 | 54 | func doPanic(t *testing.T, panicLine *int) { 55 | _, _, line, ok := runtime.Caller(0) 56 | *panicLine = line + 11 // adjust to match line of panic below 57 | if !ok { 58 | t.Fatal("runtime.Caller(0) failed") 59 | } 60 | inlinablePanic() 61 | } 62 | 63 | func inlinablePanic() { 64 | // Initiate a sigpanic. 65 | var x *uintptr 66 | _ = *x 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc2/transport.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "net/http" 7 | 8 | "github.com/go-kit/kit/endpoint" 9 | ) 10 | 11 | func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint { 12 | return func(ctx context.Context, request interface{}) (interface{}, error) { 13 | req := request.(uppercaseRequest) 14 | v, err := svc.Uppercase(req.S) 15 | if err != nil { 16 | return uppercaseResponse{v, err.Error()}, nil 17 | } 18 | return uppercaseResponse{v, ""}, nil 19 | } 20 | } 21 | 22 | func makeCountEndpoint(svc StringService) endpoint.Endpoint { 23 | return func(ctx context.Context, request interface{}) (interface{}, error) { 24 | req := request.(countRequest) 25 | v := svc.Count(req.S) 26 | return countResponse{v}, nil 27 | } 28 | } 29 | 30 | func decodeUppercaseRequest(_ context.Context, r *http.Request) (interface{}, error) { 31 | var request uppercaseRequest 32 | if err := json.NewDecoder(r.Body).Decode(&request); err != nil { 33 | return nil, err 34 | } 35 | return request, nil 36 | } 37 | 38 | func decodeCountRequest(_ context.Context, r *http.Request) (interface{}, error) { 39 | var request countRequest 40 | if err := json.NewDecoder(r.Body).Decode(&request); err != nil { 41 | return nil, err 42 | } 43 | return request, nil 44 | } 45 | 46 | func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error { 47 | return json.NewEncoder(w).Encode(response) 48 | } 49 | 50 | type uppercaseRequest struct { 51 | S string `json:"s"` 52 | } 53 | 54 | type uppercaseResponse struct { 55 | V string `json:"v"` 56 | Err string `json:"err,omitempty"` 57 | } 58 | 59 | type countRequest struct { 60 | S string `json:"s"` 61 | } 62 | 63 | type countResponse struct { 64 | V int `json:"v"` 65 | } 66 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/usage_test.go: -------------------------------------------------------------------------------- 1 | package kingpin 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "testing" 7 | 8 | "github.com/alecthomas/assert" 9 | ) 10 | 11 | func TestFormatTwoColumns(t *testing.T) { 12 | buf := bytes.NewBuffer(nil) 13 | formatTwoColumns(buf, 2, 2, 20, [][2]string{ 14 | {"--hello", "Hello world help with something that is cool."}, 15 | }) 16 | expected := ` --hello Hello 17 | world 18 | help with 19 | something 20 | that is 21 | cool. 22 | ` 23 | assert.Equal(t, expected, buf.String()) 24 | } 25 | 26 | func TestFormatTwoColumnsWide(t *testing.T) { 27 | samples := [][2]string{ 28 | {strings.Repeat("x", 29), "29 chars"}, 29 | {strings.Repeat("x", 30), "30 chars"}} 30 | buf := bytes.NewBuffer(nil) 31 | formatTwoColumns(buf, 0, 0, 200, samples) 32 | expected := `xxxxxxxxxxxxxxxxxxxxxxxxxxxxx29 chars 33 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 34 | 30 chars 35 | ` 36 | assert.Equal(t, expected, buf.String()) 37 | } 38 | 39 | func TestHiddenCommand(t *testing.T) { 40 | templates := []struct{ name, template string }{ 41 | {"default", DefaultUsageTemplate}, 42 | {"Compact", CompactUsageTemplate}, 43 | {"Long", LongHelpTemplate}, 44 | {"Man", ManPageTemplate}, 45 | } 46 | 47 | var buf bytes.Buffer 48 | t.Log("1") 49 | 50 | a := New("test", "Test").Writer(&buf).Terminate(nil) 51 | a.Command("visible", "visible") 52 | a.Command("hidden", "hidden").Hidden() 53 | 54 | for _, tp := range templates { 55 | buf.Reset() 56 | a.UsageTemplate(tp.template) 57 | a.Parse(nil) 58 | // a.Parse([]string{"--help"}) 59 | usage := buf.String() 60 | t.Logf("Usage for %s is:\n%s\n", tp.name, usage) 61 | 62 | assert.NotContains(t, usage, "hidden") 63 | assert.Contains(t, usage, "visible") 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/examplefunc_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 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 template_test 6 | 7 | import ( 8 | "log" 9 | "os" 10 | "strings" 11 | 12 | "github.com/alecthomas/template" 13 | ) 14 | 15 | // This example demonstrates a custom function to process template text. 16 | // It installs the strings.Title function and uses it to 17 | // Make Title Text Look Good In Our Template's Output. 18 | func ExampleTemplate_func() { 19 | // First we create a FuncMap with which to register the function. 20 | funcMap := template.FuncMap{ 21 | // The name "title" is what the function will be called in the template text. 22 | "title": strings.Title, 23 | } 24 | 25 | // A simple template definition to test our function. 26 | // We print the input text several ways: 27 | // - the original 28 | // - title-cased 29 | // - title-cased and then printed with %q 30 | // - printed with %q and then title-cased. 31 | const templateText = ` 32 | Input: {{printf "%q" .}} 33 | Output 0: {{title .}} 34 | Output 1: {{title . | printf "%q"}} 35 | Output 2: {{printf "%q" . | title}} 36 | ` 37 | 38 | // Create a template, add the function map, and parse the text. 39 | tmpl, err := template.New("titleTest").Funcs(funcMap).Parse(templateText) 40 | if err != nil { 41 | log.Fatalf("parsing: %s", err) 42 | } 43 | 44 | // Run the template to verify the output. 45 | err = tmpl.Execute(os.Stdout, "the go programming language") 46 | if err != nil { 47 | log.Fatalf("execution: %s", err) 48 | } 49 | 50 | // Output: 51 | // Input: "the go programming language" 52 | // Output 0: The Go Programming Language 53 | // Output 1: "The Go Programming Language" 54 | // Output 2: "The Go Programming Language" 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/term/terminal_windows_test.go: -------------------------------------------------------------------------------- 1 | package term 2 | 3 | import ( 4 | "fmt" 5 | "syscall" 6 | "testing" 7 | ) 8 | 9 | // +build windows 10 | 11 | type myWriter struct { 12 | fd uintptr 13 | } 14 | 15 | func (w *myWriter) Write(p []byte) (int, error) { 16 | return 0, fmt.Errorf("not implemented") 17 | } 18 | 19 | func (w *myWriter) Fd() uintptr { 20 | return w.fd 21 | } 22 | 23 | var procGetStdHandle = kernel32.NewProc("GetStdHandle") 24 | 25 | const stdOutputHandle = ^uintptr(0) - 11 + 1 26 | 27 | func getConsoleHandle() syscall.Handle { 28 | ptr, err := syscall.UTF16PtrFromString("CONOUT$") 29 | 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | handle, err := syscall.CreateFile(ptr, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, 0, 0) 35 | 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | return handle 41 | } 42 | 43 | func TestIsTerminal(t *testing.T) { 44 | // This is necessary because depending on whether `go test` is called with 45 | // the `-v` option, stdout will or will not be bound, changing the behavior 46 | // of the test. So we refer to it directly to avoid flakyness. 47 | handle := getConsoleHandle() 48 | 49 | writer := &myWriter{ 50 | fd: uintptr(handle), 51 | } 52 | 53 | if !IsTerminal(writer) { 54 | t.Errorf("output is supposed to be a terminal") 55 | } 56 | } 57 | 58 | func TestIsConsole(t *testing.T) { 59 | // This is necessary because depending on whether `go test` is called with 60 | // the `-v` option, stdout will or will not be bound, changing the behavior 61 | // of the test. So we refer to it directly to avoid flakyness. 62 | handle := getConsoleHandle() 63 | 64 | writer := &myWriter{ 65 | fd: uintptr(handle), 66 | } 67 | 68 | if !IsConsole(writer) { 69 | t.Errorf("output is supposed to be a console") 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vendor/gopkg.in/alecthomas/kingpin.v2/values.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "bool", "parser": "strconv.ParseBool(s)"}, 3 | {"type": "string", "parser": "s, error(nil)", "format": "string(*f.v)", "plural": "Strings"}, 4 | {"type": "uint", "parser": "strconv.ParseUint(s, 0, 64)", "plural": "Uints"}, 5 | {"type": "uint8", "parser": "strconv.ParseUint(s, 0, 8)"}, 6 | {"type": "uint16", "parser": "strconv.ParseUint(s, 0, 16)"}, 7 | {"type": "uint32", "parser": "strconv.ParseUint(s, 0, 32)"}, 8 | {"type": "uint64", "parser": "strconv.ParseUint(s, 0, 64)"}, 9 | {"type": "int", "parser": "strconv.ParseFloat(s, 64)", "plural": "Ints"}, 10 | {"type": "int8", "parser": "strconv.ParseInt(s, 0, 8)"}, 11 | {"type": "int16", "parser": "strconv.ParseInt(s, 0, 16)"}, 12 | {"type": "int32", "parser": "strconv.ParseInt(s, 0, 32)"}, 13 | {"type": "int64", "parser": "strconv.ParseInt(s, 0, 64)"}, 14 | {"type": "float64", "parser": "strconv.ParseFloat(s, 64)"}, 15 | {"type": "float32", "parser": "strconv.ParseFloat(s, 32)"}, 16 | {"name": "Duration", "type": "time.Duration", "no_value_parser": true}, 17 | {"name": "IP", "type": "net.IP", "no_value_parser": true}, 18 | {"name": "TCPAddr", "Type": "*net.TCPAddr", "plural": "TCPList", "no_value_parser": true}, 19 | {"name": "ExistingFile", "Type": "string", "plural": "ExistingFiles", "no_value_parser": true}, 20 | {"name": "ExistingDir", "Type": "string", "plural": "ExistingDirs", "no_value_parser": true}, 21 | {"name": "ExistingFileOrDir", "Type": "string", "plural": "ExistingFilesOrDirs", "no_value_parser": true}, 22 | {"name": "Regexp", "Type": "*regexp.Regexp", "parser": "regexp.Compile(s)"}, 23 | {"name": "ResolvedIP", "Type": "net.IP", "parser": "resolveHost(s)", "help": "Resolve a hostname or IP to an IP."}, 24 | {"name": "HexBytes", "Type": "[]byte", "parser": "hex.DecodeString(s)", "help": "Bytes as a hex string."} 25 | ] 26 | -------------------------------------------------------------------------------- /vendor/github.com/alecthomas/template/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 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 template_test 6 | 7 | import ( 8 | "log" 9 | "os" 10 | 11 | "github.com/alecthomas/template" 12 | ) 13 | 14 | func ExampleTemplate() { 15 | // Define a template. 16 | const letter = ` 17 | Dear {{.Name}}, 18 | {{if .Attended}} 19 | It was a pleasure to see you at the wedding.{{else}} 20 | It is a shame you couldn't make it to the wedding.{{end}} 21 | {{with .Gift}}Thank you for the lovely {{.}}. 22 | {{end}} 23 | Best wishes, 24 | Josie 25 | ` 26 | 27 | // Prepare some data to insert into the template. 28 | type Recipient struct { 29 | Name, Gift string 30 | Attended bool 31 | } 32 | var recipients = []Recipient{ 33 | {"Aunt Mildred", "bone china tea set", true}, 34 | {"Uncle John", "moleskin pants", false}, 35 | {"Cousin Rodney", "", false}, 36 | } 37 | 38 | // Create a new template and parse the letter into it. 39 | t := template.Must(template.New("letter").Parse(letter)) 40 | 41 | // Execute the template for each recipient. 42 | for _, r := range recipients { 43 | err := t.Execute(os.Stdout, r) 44 | if err != nil { 45 | log.Println("executing template:", err) 46 | } 47 | } 48 | 49 | // Output: 50 | // Dear Aunt Mildred, 51 | // 52 | // It was a pleasure to see you at the wedding. 53 | // Thank you for the lovely bone china tea set. 54 | // 55 | // Best wishes, 56 | // Josie 57 | // 58 | // Dear Uncle John, 59 | // 60 | // It is a shame you couldn't make it to the wedding. 61 | // Thank you for the lovely moleskin pants. 62 | // 63 | // Best wishes, 64 | // Josie 65 | // 66 | // Dear Cousin Rodney, 67 | // 68 | // It is a shame you couldn't make it to the wedding. 69 | // 70 | // Best wishes, 71 | // Josie 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/grpc/_grpc_test/server.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | oldcontext "golang.org/x/net/context" 8 | 9 | "github.com/go-kit/kit/endpoint" 10 | grpctransport "github.com/go-kit/kit/transport/grpc" 11 | "github.com/go-kit/kit/transport/grpc/_grpc_test/pb" 12 | ) 13 | 14 | type service struct{} 15 | 16 | func (service) Test(ctx context.Context, a string, b int64) (context.Context, string, error) { 17 | return nil, fmt.Sprintf("%s = %d", a, b), nil 18 | } 19 | 20 | func NewService() Service { 21 | return service{} 22 | } 23 | 24 | func makeTestEndpoint(svc Service) endpoint.Endpoint { 25 | return func(ctx context.Context, request interface{}) (interface{}, error) { 26 | req := request.(TestRequest) 27 | newCtx, v, err := svc.Test(ctx, req.A, req.B) 28 | return &TestResponse{ 29 | V: v, 30 | Ctx: newCtx, 31 | }, err 32 | } 33 | } 34 | 35 | type serverBinding struct { 36 | test grpctransport.Handler 37 | } 38 | 39 | func (b *serverBinding) Test(ctx oldcontext.Context, req *pb.TestRequest) (*pb.TestResponse, error) { 40 | _, response, err := b.test.ServeGRPC(ctx, req) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return response.(*pb.TestResponse), nil 45 | } 46 | 47 | func NewBinding(svc Service) *serverBinding { 48 | return &serverBinding{ 49 | test: grpctransport.NewServer( 50 | makeTestEndpoint(svc), 51 | decodeRequest, 52 | encodeResponse, 53 | grpctransport.ServerBefore( 54 | extractCorrelationID, 55 | ), 56 | grpctransport.ServerBefore( 57 | displayServerRequestHeaders, 58 | ), 59 | grpctransport.ServerAfter( 60 | injectResponseHeader, 61 | injectResponseTrailer, 62 | injectConsumedCorrelationID, 63 | ), 64 | grpctransport.ServerAfter( 65 | displayServerResponseHeaders, 66 | displayServerResponseTrailers, 67 | ), 68 | ), 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/metrics/pcp/pcp_test.go: -------------------------------------------------------------------------------- 1 | package pcp 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/performancecopilot/speed" 7 | 8 | "github.com/go-kit/kit/metrics/teststat" 9 | ) 10 | 11 | func TestCounter(t *testing.T) { 12 | r, err := NewReporter("test_counter") 13 | if err != nil { 14 | t.Fatal(err) 15 | } 16 | 17 | counter, err := r.NewCounter("speed_counter") 18 | if err != nil { 19 | t.Fatal(err) 20 | } 21 | 22 | counter = counter.With("label values", "not supported").(*Counter) 23 | 24 | value := func() float64 { f := counter.c.Val(); return float64(f) } 25 | if err := teststat.TestCounter(counter, value); err != nil { 26 | t.Fatal(err) 27 | } 28 | } 29 | 30 | func TestGauge(t *testing.T) { 31 | r, err := NewReporter("test_gauge") 32 | if err != nil { 33 | t.Fatal(err) 34 | } 35 | 36 | gauge, err := r.NewGauge("speed_gauge") 37 | if err != nil { 38 | t.Fatal(err) 39 | } 40 | 41 | gauge = gauge.With("label values", "not supported").(*Gauge) 42 | 43 | value := func() float64 { f := gauge.g.Val(); return f } 44 | if err := teststat.TestGauge(gauge, value); err != nil { 45 | t.Fatal(err) 46 | } 47 | } 48 | 49 | func TestHistogram(t *testing.T) { 50 | r, err := NewReporter("test_histogram") 51 | if err != nil { 52 | t.Fatal(err) 53 | } 54 | 55 | histogram, err := r.NewHistogram("speed_histogram", 0, 3600000000, speed.OneUnit) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | 60 | histogram = histogram.With("label values", "not supported").(*Histogram) 61 | 62 | quantiles := func() (float64, float64, float64, float64) { 63 | p50 := float64(histogram.Percentile(50)) 64 | p90 := float64(histogram.Percentile(90)) 65 | p95 := float64(histogram.Percentile(95)) 66 | p99 := float64(histogram.Percentile(99)) 67 | return p50, p90, p95, p99 68 | } 69 | if err := teststat.TestHistogram(histogram, quantiles, 0.01); err != nil { 70 | t.Fatal(err) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/ratelimit/token_bucket_test.go: -------------------------------------------------------------------------------- 1 | package ratelimit_test 2 | 3 | import ( 4 | "context" 5 | "strings" 6 | "testing" 7 | "time" 8 | 9 | jujuratelimit "github.com/juju/ratelimit" 10 | "golang.org/x/time/rate" 11 | 12 | "github.com/go-kit/kit/endpoint" 13 | "github.com/go-kit/kit/ratelimit" 14 | ) 15 | 16 | var nopEndpoint = func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil } 17 | 18 | func TestTokenBucketLimiter(t *testing.T) { 19 | tb := jujuratelimit.NewBucket(time.Minute, 1) 20 | testSuccessThenFailure( 21 | t, 22 | ratelimit.NewTokenBucketLimiter(tb)(nopEndpoint), 23 | ratelimit.ErrLimited.Error()) 24 | } 25 | 26 | func TestTokenBucketThrottler(t *testing.T) { 27 | tb := jujuratelimit.NewBucket(time.Minute, 1) 28 | testSuccessThenFailure( 29 | t, 30 | ratelimit.NewTokenBucketThrottler(tb, nil)(nopEndpoint), 31 | "context deadline exceeded") 32 | } 33 | 34 | func TestXRateErroring(t *testing.T) { 35 | limit := rate.NewLimiter(rate.Every(time.Minute), 1) 36 | testSuccessThenFailure( 37 | t, 38 | ratelimit.NewErroringLimiter(limit)(nopEndpoint), 39 | ratelimit.ErrLimited.Error()) 40 | } 41 | 42 | func TestXRateDelaying(t *testing.T) { 43 | limit := rate.NewLimiter(rate.Every(time.Minute), 1) 44 | testSuccessThenFailure( 45 | t, 46 | ratelimit.NewDelayingLimiter(limit)(nopEndpoint), 47 | "exceed context deadline") 48 | } 49 | 50 | func testSuccessThenFailure(t *testing.T, e endpoint.Endpoint, failContains string) { 51 | ctx, cxl := context.WithTimeout(context.Background(), 500*time.Millisecond) 52 | defer cxl() 53 | 54 | // First request should succeed. 55 | if _, err := e(ctx, struct{}{}); err != nil { 56 | t.Errorf("unexpected: %v\n", err) 57 | } 58 | 59 | // Next request should fail. 60 | if _, err := e(ctx, struct{}{}); !strings.Contains(err.Error(), failContains) { 61 | t.Errorf("expected `%s`: %v\n", failContains, err) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/shipping/README.md: -------------------------------------------------------------------------------- 1 | # shipping 2 | 3 | This example demonstrates a more real-world application consisting of multiple services. 4 | 5 | ## Description 6 | 7 | The implementation is based on the container shipping domain from the [Domain Driven Design](http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215) book by Eric Evans, which was [originally](http://dddsample.sourceforge.net/) implemented in Java but has since been ported to Go. This example is a somewhat stripped down version to demonstrate the use of Go kit. The [original Go application](https://github.com/marcusolsson/goddd) is maintained separately and accompanied by an [AngularJS application](https://github.com/marcusolsson/dddelivery-angularjs) as well as a mock [routing service](https://github.com/marcusolsson/pathfinder). 8 | 9 | ### Organization 10 | 11 | The application consists of three application services, `booking`, `handling` and `tracking`. Each of these is an individual Go kit service as seen in previous examples. 12 | 13 | - __booking__ - used by the shipping company to book and route cargos. 14 | - __handling__ - used by our staff around the world to register whenever the cargo has been received, loaded etc. 15 | - __tracking__ - used by the customer to track the cargo along the route 16 | 17 | There are also a few pure domain packages that contain some intricate business-logic. They provide domain objects and services that are used by each application service to provide interesting use-cases for the user. 18 | 19 | `inmem` contains in-memory implementations for the repositories found in the domain packages. 20 | 21 | The `routing` package provides a _domain service_ that is used to query an external application for possible routes. 22 | 23 | ## Contributing 24 | 25 | As with all Go kit examples you are more than welcome to contribute. If you do however, please consider contributing back to the original project as well. 26 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/auth/basic/middleware_test.go: -------------------------------------------------------------------------------- 1 | package basic 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "fmt" 7 | "testing" 8 | 9 | httptransport "github.com/go-kit/kit/transport/http" 10 | ) 11 | 12 | func TestWithBasicAuth(t *testing.T) { 13 | requiredUser := "test-user" 14 | requiredPassword := "test-pass" 15 | realm := "test realm" 16 | 17 | type want struct { 18 | result interface{} 19 | err error 20 | } 21 | tests := []struct { 22 | name string 23 | authHeader interface{} 24 | want want 25 | }{ 26 | {"Isn't valid with nil header", nil, want{nil, AuthError{realm}}}, 27 | {"Isn't valid with non-string header", 42, want{nil, AuthError{realm}}}, 28 | {"Isn't valid without authHeader", "", want{nil, AuthError{realm}}}, 29 | {"Isn't valid for wrong user", makeAuthString("wrong-user", requiredPassword), want{nil, AuthError{realm}}}, 30 | {"Isn't valid for wrong password", makeAuthString(requiredUser, "wrong-password"), want{nil, AuthError{realm}}}, 31 | {"Is valid for correct creds", makeAuthString(requiredUser, requiredPassword), want{true, nil}}, 32 | } 33 | for _, tt := range tests { 34 | t.Run(tt.name, func(t *testing.T) { 35 | ctx := context.WithValue(context.TODO(), httptransport.ContextKeyRequestAuthorization, tt.authHeader) 36 | 37 | result, err := AuthMiddleware(requiredUser, requiredPassword, realm)(passedValidation)(ctx, nil) 38 | if result != tt.want.result || err != tt.want.err { 39 | t.Errorf("WithBasicAuth() = result: %v, err: %v, want result: %v, want error: %v", result, err, tt.want.result, tt.want.err) 40 | } 41 | }) 42 | } 43 | } 44 | 45 | func makeAuthString(user string, password string) string { 46 | data := []byte(fmt.Sprintf("%s:%s", user, password)) 47 | return fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString(data)) 48 | } 49 | 50 | func passedValidation(ctx context.Context, request interface{}) (response interface{}, err error) { 51 | return true, nil 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/level/benchmark_test.go: -------------------------------------------------------------------------------- 1 | package level_test 2 | 3 | import ( 4 | "io/ioutil" 5 | "testing" 6 | 7 | "github.com/go-kit/kit/log" 8 | "github.com/go-kit/kit/log/level" 9 | ) 10 | 11 | func Benchmark(b *testing.B) { 12 | contexts := []struct { 13 | name string 14 | context func(log.Logger) log.Logger 15 | }{ 16 | {"NoContext", func(l log.Logger) log.Logger { 17 | return l 18 | }}, 19 | {"TimeContext", func(l log.Logger) log.Logger { 20 | return log.With(l, "time", log.DefaultTimestampUTC) 21 | }}, 22 | {"CallerContext", func(l log.Logger) log.Logger { 23 | return log.With(l, "caller", log.DefaultCaller) 24 | }}, 25 | {"TimeCallerReqIDContext", func(l log.Logger) log.Logger { 26 | return log.With(l, "time", log.DefaultTimestampUTC, "caller", log.DefaultCaller, "reqID", 29) 27 | }}, 28 | } 29 | 30 | loggers := []struct { 31 | name string 32 | logger log.Logger 33 | }{ 34 | {"Nop", log.NewNopLogger()}, 35 | {"Logfmt", log.NewLogfmtLogger(ioutil.Discard)}, 36 | {"JSON", log.NewJSONLogger(ioutil.Discard)}, 37 | } 38 | 39 | filters := []struct { 40 | name string 41 | filter func(log.Logger) log.Logger 42 | }{ 43 | {"Baseline", func(l log.Logger) log.Logger { 44 | return l 45 | }}, 46 | {"DisallowedLevel", func(l log.Logger) log.Logger { 47 | return level.NewFilter(l, level.AllowInfo()) 48 | }}, 49 | {"AllowedLevel", func(l log.Logger) log.Logger { 50 | return level.NewFilter(l, level.AllowAll()) 51 | }}, 52 | } 53 | 54 | for _, c := range contexts { 55 | b.Run(c.name, func(b *testing.B) { 56 | for _, f := range filters { 57 | b.Run(f.name, func(b *testing.B) { 58 | for _, l := range loggers { 59 | b.Run(l.name, func(b *testing.B) { 60 | logger := c.context(f.filter(l.logger)) 61 | b.ResetTimer() 62 | b.ReportAllocs() 63 | for i := 0; i < b.N; i++ { 64 | level.Debug(logger).Log("foo", "bar") 65 | } 66 | }) 67 | } 68 | }) 69 | } 70 | }) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/stringsvc2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "os" 6 | 7 | stdprometheus "github.com/prometheus/client_golang/prometheus" 8 | "github.com/prometheus/client_golang/prometheus/promhttp" 9 | 10 | "github.com/go-kit/kit/log" 11 | kitprometheus "github.com/go-kit/kit/metrics/prometheus" 12 | httptransport "github.com/go-kit/kit/transport/http" 13 | ) 14 | 15 | func main() { 16 | logger := log.NewLogfmtLogger(os.Stderr) 17 | 18 | fieldKeys := []string{"method", "error"} 19 | requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ 20 | Namespace: "my_group", 21 | Subsystem: "string_service", 22 | Name: "request_count", 23 | Help: "Number of requests received.", 24 | }, fieldKeys) 25 | requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ 26 | Namespace: "my_group", 27 | Subsystem: "string_service", 28 | Name: "request_latency_microseconds", 29 | Help: "Total duration of requests in microseconds.", 30 | }, fieldKeys) 31 | countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ 32 | Namespace: "my_group", 33 | Subsystem: "string_service", 34 | Name: "count_result", 35 | Help: "The result of each count method.", 36 | }, []string{}) // no fields here 37 | 38 | var svc StringService 39 | svc = stringService{} 40 | svc = loggingMiddleware{logger, svc} 41 | svc = instrumentingMiddleware{requestCount, requestLatency, countResult, svc} 42 | 43 | uppercaseHandler := httptransport.NewServer( 44 | makeUppercaseEndpoint(svc), 45 | decodeUppercaseRequest, 46 | encodeResponse, 47 | ) 48 | 49 | countHandler := httptransport.NewServer( 50 | makeCountEndpoint(svc), 51 | decodeCountRequest, 52 | encodeResponse, 53 | ) 54 | 55 | http.Handle("/uppercase", uppercaseHandler) 56 | http.Handle("/count", countHandler) 57 | http.Handle("/metrics", promhttp.Handler()) 58 | logger.Log("msg", "HTTP", "addr", ":8080") 59 | logger.Log("err", http.ListenAndServe(":8080", nil)) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/deprecated_levels/levels_test.go: -------------------------------------------------------------------------------- 1 | package levels_test 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "testing" 7 | 8 | "github.com/go-kit/kit/log" 9 | levels "github.com/go-kit/kit/log/deprecated_levels" 10 | ) 11 | 12 | func TestDefaultLevels(t *testing.T) { 13 | buf := bytes.Buffer{} 14 | logger := levels.New(log.NewLogfmtLogger(&buf)) 15 | 16 | logger.Debug().Log("msg", "résumé") // of course you'd want to do this 17 | if want, have := "level=debug msg=résumé\n", buf.String(); want != have { 18 | t.Errorf("want %#v, have %#v", want, have) 19 | } 20 | 21 | buf.Reset() 22 | logger.Info().Log("msg", "Åhus") 23 | if want, have := "level=info msg=Åhus\n", buf.String(); want != have { 24 | t.Errorf("want %#v, have %#v", want, have) 25 | } 26 | 27 | buf.Reset() 28 | logger.Error().Log("msg", "© violation") 29 | if want, have := "level=error msg=\"© violation\"\n", buf.String(); want != have { 30 | t.Errorf("want %#v, have %#v", want, have) 31 | } 32 | 33 | buf.Reset() 34 | logger.Crit().Log("msg", " ") 35 | if want, have := "level=crit msg=\"\\t\"\n", buf.String(); want != have { 36 | t.Errorf("want %#v, have %#v", want, have) 37 | } 38 | } 39 | 40 | func TestModifiedLevels(t *testing.T) { 41 | buf := bytes.Buffer{} 42 | logger := levels.New( 43 | log.NewJSONLogger(&buf), 44 | levels.Key("l"), 45 | levels.DebugValue("dbg"), 46 | levels.InfoValue("nfo"), 47 | levels.WarnValue("wrn"), 48 | levels.ErrorValue("err"), 49 | levels.CritValue("crt"), 50 | ) 51 | logger.With("easter_island", "176°").Debug().Log("msg", "moai") 52 | if want, have := `{"easter_island":"176°","l":"dbg","msg":"moai"}`+"\n", buf.String(); want != have { 53 | t.Errorf("want %#v, have %#v", want, have) 54 | } 55 | } 56 | 57 | func ExampleLevels() { 58 | logger := levels.New(log.NewLogfmtLogger(os.Stdout)) 59 | logger.Debug().Log("msg", "hello") 60 | logger.With("context", "foo").Warn().Log("err", "error") 61 | 62 | // Output: 63 | // level=debug msg=hello 64 | // level=warn context=foo err=error 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/log/sync_test.go: -------------------------------------------------------------------------------- 1 | package log_test 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "os" 7 | "testing" 8 | 9 | "github.com/go-kit/kit/log" 10 | ) 11 | 12 | func TestSwapLogger(t *testing.T) { 13 | t.Parallel() 14 | var logger log.SwapLogger 15 | 16 | // Zero value does not panic or error. 17 | err := logger.Log("k", "v") 18 | if got, want := err, error(nil); got != want { 19 | t.Errorf("got %v, want %v", got, want) 20 | } 21 | 22 | buf := &bytes.Buffer{} 23 | json := log.NewJSONLogger(buf) 24 | logger.Swap(json) 25 | 26 | if err := logger.Log("k", "v"); err != nil { 27 | t.Error(err) 28 | } 29 | if got, want := buf.String(), `{"k":"v"}`+"\n"; got != want { 30 | t.Errorf("got %v, want %v", got, want) 31 | } 32 | 33 | buf.Reset() 34 | prefix := log.NewLogfmtLogger(buf) 35 | logger.Swap(prefix) 36 | 37 | if err := logger.Log("k", "v"); err != nil { 38 | t.Error(err) 39 | } 40 | if got, want := buf.String(), "k=v\n"; got != want { 41 | t.Errorf("got %v, want %v", got, want) 42 | } 43 | 44 | buf.Reset() 45 | logger.Swap(nil) 46 | 47 | if err := logger.Log("k", "v"); err != nil { 48 | t.Error(err) 49 | } 50 | if got, want := buf.String(), ""; got != want { 51 | t.Errorf("got %v, want %v", got, want) 52 | } 53 | } 54 | 55 | func TestSwapLoggerConcurrency(t *testing.T) { 56 | t.Parallel() 57 | testConcurrency(t, &log.SwapLogger{}, 10000) 58 | } 59 | 60 | func TestSyncLoggerConcurrency(t *testing.T) { 61 | var w io.Writer 62 | w = &bytes.Buffer{} 63 | logger := log.NewLogfmtLogger(w) 64 | logger = log.NewSyncLogger(logger) 65 | testConcurrency(t, logger, 10000) 66 | } 67 | 68 | func TestSyncWriterConcurrency(t *testing.T) { 69 | var w io.Writer 70 | w = &bytes.Buffer{} 71 | w = log.NewSyncWriter(w) 72 | testConcurrency(t, log.NewLogfmtLogger(w), 10000) 73 | } 74 | 75 | func TestSyncWriterFd(t *testing.T) { 76 | _, ok := log.NewSyncWriter(os.Stdout).(interface { 77 | Fd() uintptr 78 | }) 79 | 80 | if !ok { 81 | t.Error("NewSyncWriter does not pass through Fd method") 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/transport/thrift/README.md: -------------------------------------------------------------------------------- 1 | # Thrift 2 | 3 | [Thrift](https://thrift.apache.org/) is a large IDL and transport package from Apache, popularized by Facebook. 4 | Thrift is well-supported in Go kit, for organizations that already have significant Thrift investment. 5 | And using Thrift with Go kit is very simple. 6 | 7 | First, define your service in the Thrift IDL. 8 | The [Thrift IDL documentation](https://thrift.apache.org/docs/idl) provides more details. 9 | See [add.thrift](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/_thrift/add.thrift) for an example. 10 | Make sure the Thrift definition matches your service's Go kit (interface) definition. 11 | 12 | Next, [download Thrift](https://thrift.apache.org/download) and [install the compiler](https://thrift.apache.org/docs/install/). 13 | On a Mac, you may be able to `brew install thrift`. 14 | 15 | Then, compile your service definition, from .thrift to .go. 16 | You'll probably want to specify the package_prefix option to the --gen go flag. 17 | See [THRIFT-3021](https://issues.apache.org/jira/browse/THRIFT-3021) for more details. 18 | 19 | ``` 20 | thrift -r --gen go:package_prefix=github.com/my-org/my-repo/thrift/gen-go/ add.thrift 21 | ``` 22 | 23 | Finally, write a tiny binding from your service definition to the Thrift definition. 24 | It's a straightforward conversion from one domain to the other. 25 | See [thrift_binding.go](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/thrift_binding.go) for an example. 26 | 27 | That's it! 28 | The Thrift binding can be bound to a listener and serve normal Thrift requests. 29 | And within your service, you can use standard Go kit components and idioms. 30 | Unfortunately, setting up a Thrift listener is rather laborious and nonidiomatic in Go. 31 | Fortunately, [addsvc](https://github.com/go-kit/kit/tree/master/examples/addsvc) is a complete working example with Thrift support. 32 | And remember: Go kit services can support multiple transports simultaneously. 33 | -------------------------------------------------------------------------------- /cmd/subdomainr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "net/http" 7 | "os" 8 | "time" 9 | 10 | "github.com/aybabtme/log" 11 | "github.com/gorilla/mux" 12 | "github.com/pkg/errors" 13 | kingpin "gopkg.in/alecthomas/kingpin.v2" 14 | ) 15 | 16 | var ( 17 | DefaultDomain = "localhost" 18 | DefaultListenAddr = "0.0.0.0:8080" 19 | ) 20 | 21 | func main() { 22 | app := kingpin.New( 23 | "subdomainr", 24 | "test experiment around subdomains", 25 | ).DefaultEnvars() 26 | serveCmd(app.Command("serve", "serve up the server")) 27 | _, err := app.Parse(os.Args[1:]) 28 | if err != nil { 29 | log.Err(err).Fatal("failed to run") 30 | } 31 | } 32 | 33 | func serveCmd(cmd *kingpin.CmdClause) { 34 | var cfg = struct { 35 | Domain string 36 | ListenAddr string 37 | }{} 38 | 39 | cmd.Flag("listen.addr", "address where to listen.").Default(DefaultListenAddr).StringVar(&cfg.ListenAddr) 40 | cmd.Flag("domain.url", "domain of the application").Default(DefaultDomain).StringVar(&cfg.Domain) 41 | 42 | cmd.Action(func(*kingpin.ParseContext) error { 43 | wildcardDomain := "{subdomain:[\\w-]+}." + cfg.Domain 44 | r := mux.NewRouter() 45 | log.KV("domain", wildcardDomain).Info("debugging wildcard domain") 46 | s := r.Host(wildcardDomain).Subrouter() 47 | s.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 48 | fmt.Fprintf(w, "Hello from the current host: %s", r.Host) 49 | }) 50 | 51 | r.Host(cfg.Domain).PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 52 | fmt.Fprintf(w, "Hello from the base host: %s", r.Host) 53 | }) 54 | 55 | l, err := net.Listen("tcp", cfg.ListenAddr) 56 | if err != nil { 57 | return errors.Wrap(err, "creating listener") 58 | } 59 | 60 | actualAddr := l.Addr().String() 61 | 62 | srv := &http.Server{ 63 | Addr: actualAddr, 64 | Handler: r, 65 | WriteTimeout: 60 * time.Second, 66 | ReadTimeout: 60 * time.Second, 67 | } 68 | 69 | ll := log.KV("listen.addr", actualAddr) 70 | ll.Info("listening") 71 | 72 | return srv.Serve(l) 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/etcd/instancer.go: -------------------------------------------------------------------------------- 1 | package etcd 2 | 3 | import ( 4 | "github.com/go-kit/kit/log" 5 | "github.com/go-kit/kit/sd" 6 | "github.com/go-kit/kit/sd/internal/instance" 7 | ) 8 | 9 | // Instancer yields instances stored in a certain etcd keyspace. Any kind of 10 | // change in that keyspace is watched and will update the Instancer's Instancers. 11 | type Instancer struct { 12 | cache *instance.Cache 13 | client Client 14 | prefix string 15 | logger log.Logger 16 | quitc chan struct{} 17 | } 18 | 19 | // NewInstancer returns an etcd instancer. It will start watching the given 20 | // prefix for changes, and update the subscribers. 21 | func NewInstancer(c Client, prefix string, logger log.Logger) (*Instancer, error) { 22 | s := &Instancer{ 23 | client: c, 24 | prefix: prefix, 25 | cache: instance.NewCache(), 26 | logger: logger, 27 | quitc: make(chan struct{}), 28 | } 29 | 30 | instances, err := s.client.GetEntries(s.prefix) 31 | if err == nil { 32 | logger.Log("prefix", s.prefix, "instances", len(instances)) 33 | } else { 34 | logger.Log("prefix", s.prefix, "err", err) 35 | } 36 | s.cache.Update(sd.Event{Instances: instances, Err: err}) 37 | 38 | go s.loop() 39 | return s, nil 40 | } 41 | 42 | func (s *Instancer) loop() { 43 | ch := make(chan struct{}) 44 | go s.client.WatchPrefix(s.prefix, ch) 45 | for { 46 | select { 47 | case <-ch: 48 | instances, err := s.client.GetEntries(s.prefix) 49 | if err != nil { 50 | s.logger.Log("msg", "failed to retrieve entries", "err", err) 51 | s.cache.Update(sd.Event{Err: err}) 52 | continue 53 | } 54 | s.cache.Update(sd.Event{Instances: instances}) 55 | 56 | case <-s.quitc: 57 | return 58 | } 59 | } 60 | } 61 | 62 | // Stop terminates the Instancer. 63 | func (s *Instancer) Stop() { 64 | close(s.quitc) 65 | } 66 | 67 | // Register implements Instancer. 68 | func (s *Instancer) Register(ch chan<- sd.Event) { 69 | s.cache.Register(ch) 70 | } 71 | 72 | // Deregister implements Instancer. 73 | func (s *Instancer) Deregister(ch chan<- sd.Event) { 74 | s.cache.Deregister(ch) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/examples/addsvc/pkg/addservice/middleware.go: -------------------------------------------------------------------------------- 1 | package addservice 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/go-kit/kit/log" 7 | "github.com/go-kit/kit/metrics" 8 | ) 9 | 10 | // Middleware describes a service (as opposed to endpoint) middleware. 11 | type Middleware func(Service) Service 12 | 13 | // LoggingMiddleware takes a logger as a dependency 14 | // and returns a ServiceMiddleware. 15 | func LoggingMiddleware(logger log.Logger) Middleware { 16 | return func(next Service) Service { 17 | return loggingMiddleware{logger, next} 18 | } 19 | } 20 | 21 | type loggingMiddleware struct { 22 | logger log.Logger 23 | next Service 24 | } 25 | 26 | func (mw loggingMiddleware) Sum(ctx context.Context, a, b int) (v int, err error) { 27 | defer func() { 28 | mw.logger.Log("method", "Sum", "a", a, "b", b, "v", v, "err", err) 29 | }() 30 | return mw.next.Sum(ctx, a, b) 31 | } 32 | 33 | func (mw loggingMiddleware) Concat(ctx context.Context, a, b string) (v string, err error) { 34 | defer func() { 35 | mw.logger.Log("method", "Concat", "a", a, "b", b, "v", v, "err", err) 36 | }() 37 | return mw.next.Concat(ctx, a, b) 38 | } 39 | 40 | // InstrumentingMiddleware returns a service middleware that instruments 41 | // the number of integers summed and characters concatenated over the lifetime of 42 | // the service. 43 | func InstrumentingMiddleware(ints, chars metrics.Counter) Middleware { 44 | return func(next Service) Service { 45 | return instrumentingMiddleware{ 46 | ints: ints, 47 | chars: chars, 48 | next: next, 49 | } 50 | } 51 | } 52 | 53 | type instrumentingMiddleware struct { 54 | ints metrics.Counter 55 | chars metrics.Counter 56 | next Service 57 | } 58 | 59 | func (mw instrumentingMiddleware) Sum(ctx context.Context, a, b int) (int, error) { 60 | v, err := mw.next.Sum(ctx, a, b) 61 | mw.ints.Add(float64(v)) 62 | return v, err 63 | } 64 | 65 | func (mw instrumentingMiddleware) Concat(ctx context.Context, a, b string) (string, error) { 66 | v, err := mw.next.Concat(ctx, a, b) 67 | mw.chars.Add(float64(len(v))) 68 | return v, err 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/sd/internal/instance/cache.go: -------------------------------------------------------------------------------- 1 | package instance 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | "sync" 7 | 8 | "github.com/go-kit/kit/sd" 9 | ) 10 | 11 | // Cache keeps track of resource instances provided to it via Update method 12 | // and implements the Instancer interface 13 | type Cache struct { 14 | mtx sync.RWMutex 15 | state sd.Event 16 | reg registry 17 | } 18 | 19 | // NewCache creates a new Cache. 20 | func NewCache() *Cache { 21 | return &Cache{ 22 | reg: registry{}, 23 | } 24 | } 25 | 26 | // Update receives new instances from service discovery, stores them internally, 27 | // and notifies all registered listeners. 28 | func (c *Cache) Update(event sd.Event) { 29 | c.mtx.Lock() 30 | defer c.mtx.Unlock() 31 | 32 | sort.Strings(event.Instances) 33 | if reflect.DeepEqual(c.state, event) { 34 | return // no need to broadcast the same instances 35 | } 36 | 37 | c.state = event 38 | c.reg.broadcast(event) 39 | } 40 | 41 | // State returns the current state of discovery (instances or error) as sd.Event 42 | func (c *Cache) State() sd.Event { 43 | c.mtx.RLock() 44 | defer c.mtx.RUnlock() 45 | return c.state 46 | } 47 | 48 | // Stop implements Instancer. Since the cache is just a plain-old store of data, 49 | // Stop is a no-op. 50 | func (c *Cache) Stop() {} 51 | 52 | // Register implements Instancer. 53 | func (c *Cache) Register(ch chan<- sd.Event) { 54 | c.mtx.Lock() 55 | defer c.mtx.Unlock() 56 | c.reg.register(ch) 57 | // always push the current state to new channels 58 | ch <- c.state 59 | } 60 | 61 | // Deregister implements Instancer. 62 | func (c *Cache) Deregister(ch chan<- sd.Event) { 63 | c.mtx.Lock() 64 | defer c.mtx.Unlock() 65 | c.reg.deregister(ch) 66 | } 67 | 68 | // registry is not goroutine-safe. 69 | type registry map[chan<- sd.Event]struct{} 70 | 71 | func (r registry) broadcast(event sd.Event) { 72 | for c := range r { 73 | c <- event 74 | } 75 | } 76 | 77 | func (r registry) register(c chan<- sd.Event) { 78 | r[c] = struct{}{} 79 | } 80 | 81 | func (r registry) deregister(c chan<- sd.Event) { 82 | delete(r, c) 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/go-kit/kit/tracing/opentracing/endpoint.go: -------------------------------------------------------------------------------- 1 | package opentracing 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/opentracing/opentracing-go" 7 | otext "github.com/opentracing/opentracing-go/ext" 8 | 9 | "github.com/go-kit/kit/endpoint" 10 | ) 11 | 12 | // TraceServer returns a Middleware that wraps the `next` Endpoint in an 13 | // OpenTracing Span called `operationName`. 14 | // 15 | // If `ctx` already has a Span, it is re-used and the operation name is 16 | // overwritten. If `ctx` does not yet have a Span, one is created here. 17 | func TraceServer(tracer opentracing.Tracer, operationName string) endpoint.Middleware { 18 | return func(next endpoint.Endpoint) endpoint.Endpoint { 19 | return func(ctx context.Context, request interface{}) (interface{}, error) { 20 | serverSpan := opentracing.SpanFromContext(ctx) 21 | if serverSpan == nil { 22 | // All we can do is create a new root span. 23 | serverSpan = tracer.StartSpan(operationName) 24 | } else { 25 | serverSpan.SetOperationName(operationName) 26 | } 27 | defer serverSpan.Finish() 28 | otext.SpanKindRPCServer.Set(serverSpan) 29 | ctx = opentracing.ContextWithSpan(ctx, serverSpan) 30 | return next(ctx, request) 31 | } 32 | } 33 | } 34 | 35 | // TraceClient returns a Middleware that wraps the `next` Endpoint in an 36 | // OpenTracing Span called `operationName`. 37 | func TraceClient(tracer opentracing.Tracer, operationName string) endpoint.Middleware { 38 | return func(next endpoint.Endpoint) endpoint.Endpoint { 39 | return func(ctx context.Context, request interface{}) (interface{}, error) { 40 | var clientSpan opentracing.Span 41 | if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil { 42 | clientSpan = tracer.StartSpan( 43 | operationName, 44 | opentracing.ChildOf(parentSpan.Context()), 45 | ) 46 | } else { 47 | clientSpan = tracer.StartSpan(operationName) 48 | } 49 | defer clientSpan.Finish() 50 | otext.SpanKindRPCClient.Set(clientSpan) 51 | ctx = opentracing.ContextWithSpan(ctx, clientSpan) 52 | return next(ctx, request) 53 | } 54 | } 55 | } 56 | --------------------------------------------------------------------------------