├── .gitignore ├── synapse ├── haproxy_client_test.go ├── context.go ├── router_console.go ├── report_sort.go ├── router_haproxy_test.go ├── watcher.go └── report.go ├── vendor ├── github.com │ ├── gocarina │ │ └── gocsv │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── go.mod │ │ │ ├── safe_csv.go │ │ │ └── LICENSE │ ├── mgutz │ │ └── ansi │ │ │ ├── .gitignore │ │ │ ├── print.go │ │ │ ├── LICENSE │ │ │ ├── doc.go │ │ │ └── README.md │ ├── lib │ │ └── pq │ │ │ ├── .gitignore │ │ │ ├── oid │ │ │ ├── doc.go │ │ │ └── gen.go │ │ │ ├── user_posix.go │ │ │ ├── user_windows.go │ │ │ ├── LICENSE.md │ │ │ ├── CONTRIBUTING.md │ │ │ ├── url.go │ │ │ └── buf.go │ ├── matttproud │ │ └── golang_protobuf_extensions │ │ │ ├── pbutil │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── doc.go │ │ │ ├── encode.go │ │ │ └── decode.go │ │ │ └── NOTICE │ ├── prometheus │ │ ├── client_golang │ │ │ ├── prometheus │ │ │ │ ├── .gitignore │ │ │ │ ├── fnv.go │ │ │ │ ├── README.md │ │ │ │ └── push.go │ │ │ └── NOTICE │ │ ├── procfs │ │ │ ├── .travis.yml │ │ │ ├── Makefile │ │ │ ├── NOTICE │ │ │ ├── README.md │ │ │ ├── AUTHORS.md │ │ │ ├── CONTRIBUTING.md │ │ │ ├── fs.go │ │ │ ├── proc_io.go │ │ │ ├── stat.go │ │ │ └── doc.go │ │ ├── client_model │ │ │ └── NOTICE │ │ └── common │ │ │ ├── NOTICE │ │ │ ├── model │ │ │ ├── model.go │ │ │ ├── fnv.go │ │ │ ├── metric.go │ │ │ └── fingerprinting.go │ │ │ ├── expfmt │ │ │ ├── fuzz.go │ │ │ ├── expfmt.go │ │ │ └── encode.go │ │ │ └── internal │ │ │ └── bitbucket.org │ │ │ └── ww │ │ │ └── goautoneg │ │ │ └── README.txt │ ├── streadway │ │ └── amqp │ │ │ ├── gen.sh │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── fuzz.go │ │ │ ├── auth.go │ │ │ ├── LICENSE │ │ │ ├── confirms.go │ │ │ ├── return.go │ │ │ ├── allocator.go │ │ │ └── consumers.go │ ├── spf13 │ │ ├── pflag │ │ │ ├── .travis.yml │ │ │ ├── LICENSE │ │ │ ├── int.go │ │ │ └── string.go │ │ └── cobra │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ └── md_docs.md │ ├── go-sql-driver │ │ └── mysql │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── appengine.go │ │ │ ├── result.go │ │ │ ├── transaction.go │ │ │ ├── AUTHORS │ │ │ ├── CONTRIBUTING.md │ │ │ └── rows.go │ ├── n0rad │ │ └── go-erlog │ │ │ ├── Makefile │ │ │ ├── appender.go │ │ │ ├── register │ │ │ └── register.go │ │ │ ├── data │ │ │ └── data.go │ │ │ ├── event.go │ │ │ ├── readme.md │ │ │ └── logs │ │ │ ├── logger.go │ │ │ ├── levels.go │ │ │ ├── default.go │ │ │ ├── entry.go │ │ │ └── dummy.go │ ├── Unknwon │ │ └── com │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ ├── math.go │ │ │ ├── README.md │ │ │ ├── url.go │ │ │ ├── html.go │ │ │ ├── regex.go │ │ │ ├── slice.go │ │ │ └── path.go │ ├── go-macaron │ │ └── inject │ │ │ ├── .travis.yml │ │ │ └── README.md │ ├── leekchan │ │ └── gtf │ │ │ ├── .travis.yml │ │ │ ├── .gitignore │ │ │ └── LICENSE │ ├── ghodss │ │ └── yaml │ │ │ ├── .gitignore │ │ │ └── LICENSE │ ├── bcicen │ │ └── go-haproxy │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── LICENSE │ │ │ ├── client.go │ │ │ └── kvcodec │ │ │ └── unmarshal.go │ ├── inconshreveable │ │ └── mousetrap │ │ │ ├── trap_others.go │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── trap_windows_1.4.go │ │ │ └── trap_windows.go │ ├── blablacar │ │ └── go-nerve │ │ │ └── nerve │ │ │ ├── reporter_console.go │ │ │ ├── check_exec.go │ │ │ ├── check_tcp.go │ │ │ ├── check_http.go │ │ │ ├── reporter_file.go │ │ │ ├── reporter.go │ │ │ ├── check_sql.go │ │ │ ├── utils.go │ │ │ ├── check_amqp.go │ │ │ ├── check_proxyhttp.go │ │ │ └── report.go │ ├── beorn7 │ │ └── perks │ │ │ └── LICENSE │ ├── samuel │ │ └── go-zookeeper │ │ │ ├── LICENSE │ │ │ └── zk │ │ │ ├── util.go │ │ │ └── dnshostprovider.go │ └── golang │ │ └── protobuf │ │ ├── LICENSE │ │ └── proto │ │ └── Makefile ├── gopkg.in │ ├── macaron.v1 │ │ ├── .gitignore │ │ ├── macaronlogo.png │ │ ├── .travis.yml │ │ ├── logger.go │ │ └── return_handler.go │ ├── ini.v1 │ │ ├── .gitignore │ │ └── Makefile │ └── yaml.v2 │ │ ├── LICENSE.libyaml │ │ ├── writerc.go │ │ ├── sorter.go │ │ └── README.md └── golang.org │ └── x │ └── crypto │ ├── ssh │ └── terminal │ │ ├── util_bsd.go │ │ ├── util_linux.go │ │ └── util_plan9.go │ ├── PATENTS │ └── LICENSE ├── gomake.cfg ├── goss.yaml ├── Godeps └── Readme ├── examples ├── synapse-minimal.yml ├── template.tmpl ├── haproxy-reload.sh ├── template.yml ├── new2.yml ├── new3.yml ├── synapse-compose.yml └── new.yml ├── docker-compose.yml ├── Dockerfile └── .travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | -------------------------------------------------------------------------------- /synapse/haproxy_client_test.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | -------------------------------------------------------------------------------- /vendor/github.com/gocarina/gocsv/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /vendor/github.com/mgutz/ansi/.gitignore: -------------------------------------------------------------------------------- 1 | *.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/gocarina/gocsv/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/.gitignore: -------------------------------------------------------------------------------- 1 | .db 2 | *.test 3 | *~ 4 | *.swp 5 | -------------------------------------------------------------------------------- /vendor/github.com/gocarina/gocsv/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gocarina/gocsv/v2 2 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/.gitignore: -------------------------------------------------------------------------------- 1 | cover.dat 2 | -------------------------------------------------------------------------------- /gomake.cfg: -------------------------------------------------------------------------------- 1 | app=synapse 2 | docker_user=bbcdocker 3 | docker_app=go-synapse 4 | #upx=true 5 | -------------------------------------------------------------------------------- /vendor/gopkg.in/macaron.v1/.gitignore: -------------------------------------------------------------------------------- 1 | macaron.sublime-project 2 | macaron.sublime-workspace -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | command-line-arguments.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Matt T. Proud (matt.proud@gmail.com) 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.5 5 | - 1.6 6 | -------------------------------------------------------------------------------- /goss.yaml: -------------------------------------------------------------------------------- 1 | port: 2 | tcp6:3455: 3 | listening: true 4 | ip: 5 | - '::' 6 | process: 7 | synapse: 8 | running: true 9 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go run spec/gen.go < spec/amqp0-9-1.stripped.extended.xml | gofmt > spec091.go 3 | -------------------------------------------------------------------------------- /vendor/gopkg.in/ini.v1/.gitignore: -------------------------------------------------------------------------------- 1 | testdata/conf_out.ini 2 | ini.sublime-project 3 | ini.sublime-workspace 4 | testdata/conf_reflect.ini 5 | -------------------------------------------------------------------------------- /vendor/gopkg.in/macaron.v1/macaronlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blablacar/go-synapse/HEAD/vendor/gopkg.in/macaron.v1/macaronlogo.png -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.3 7 | - 1.4 8 | - tip 9 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/.gitignore: -------------------------------------------------------------------------------- 1 | spec/spec 2 | examples/simple-consumer/simple-consumer 3 | examples/simple-producer/simple-producer 4 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .DS_Store? 3 | ._* 4 | .Spotlight-V100 5 | .Trashes 6 | Icon? 7 | ehthumbs.db 8 | Thumbs.db 9 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.3 4 | - 1.4.2 5 | - tip 6 | script: 7 | - go test ./... 8 | - go build 9 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/Makefile: -------------------------------------------------------------------------------- 1 | ci: 2 | ! gofmt -l *.go | read nothing 3 | go vet 4 | go test -v ./... 5 | go get golang.org/x/lint/golint 6 | golint *.go 7 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/Makefile: -------------------------------------------------------------------------------- 1 | # this just wrap go commands 2 | 3 | 4 | all: format test 5 | 6 | format: 7 | gofmt -w -s . 8 | 9 | test: 10 | go test -cover ./... 11 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/oid/doc.go: -------------------------------------------------------------------------------- 1 | // Package oid contains OID constants 2 | // as defined by the Postgres server. 3 | package oid 4 | 5 | // Oid is a Postgres Object ID. 6 | type Oid uint32 7 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | cover: 4 | go test -cover -v -coverprofile=cover.dat ./... 5 | go tool cover -func cover.dat 6 | 7 | .PHONY: cover 8 | -------------------------------------------------------------------------------- /examples/synapse-minimal.yml: -------------------------------------------------------------------------------- 1 | routers: 2 | - type: console 3 | services: 4 | - watcher: 5 | type: zookeeper 6 | hosts: ['localhost:2181'] 7 | path: /services/api/myapi 8 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - tip 8 | 9 | install: go get -v -t 10 | 11 | notifications: 12 | email: 13 | - u@gogs.io -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - tip 8 | 9 | before_script: 10 | - mysql -e 'create database gotest;' 11 | -------------------------------------------------------------------------------- /vendor/gopkg.in/macaron.v1/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | 4 | go: 5 | - 1.5 6 | - 1.6 7 | - tip 8 | 9 | script: go test -v -cover -race 10 | 11 | notifications: 12 | email: 13 | - u@gogs.io 14 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/NOTICE: -------------------------------------------------------------------------------- 1 | Data model artifacts for Prometheus. 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/NOTICE: -------------------------------------------------------------------------------- 1 | Common libraries shared by Prometheus Go components. 2 | Copyright 2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/ini.v1/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build test bench vet 2 | 3 | build: vet bench 4 | 5 | test: 6 | go test -v -cover -race 7 | 8 | bench: 9 | go test -v -cover -race -test.bench=. -test.benchmem 10 | 11 | vet: 12 | go vet 13 | -------------------------------------------------------------------------------- /examples/template.tmpl: -------------------------------------------------------------------------------- 1 | default: 2 | tripsearch: 3 | elasticsearch: 4 | hosts: [{{- range . -}} 5 | {{- if eq .Service.Name "services_es_es_site_search" -}}{{- range .Reports}}'{{.Host}}:{{.Port}}', {{end}}{{- end -}} 6 | {{- end -}}] 7 | -------------------------------------------------------------------------------- /vendor/github.com/go-macaron/inject/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | 4 | go: 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - tip 9 | 10 | script: go test -v -cover -race 11 | 12 | notifications: 13 | email: 14 | - u@gogs.io 15 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/appender.go: -------------------------------------------------------------------------------- 1 | package erlog 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/logs" 5 | ) 6 | 7 | type Appender interface { 8 | Fire(event *LogEvent) 9 | GetLevel() logs.Level 10 | SetLevel(level logs.Level) 11 | } 12 | -------------------------------------------------------------------------------- /examples/haproxy-reload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | if [ ! -S "/haproxy-master.sock" ]; then 6 | haproxy -W -S /haproxy-master.sock -D -f ${HAP_CONFIG} 7 | else 8 | echo "reload" | nc -U /haproxy-master.sock 9 | fi 10 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/register/register.go: -------------------------------------------------------------------------------- 1 | package register 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog" 5 | "github.com/n0rad/go-erlog/logs" 6 | ) 7 | 8 | func init() { 9 | logs.RegisterLoggerFactory(erlog.NewErlogFactory()) 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.1 5 | - 1.4 6 | - 1.5 7 | 8 | services: 9 | - rabbitmq 10 | 11 | env: 12 | - AMQP_URL=amqp://guest:guest@127.0.0.1:5672/ GOMAXPROCS=2 13 | 14 | script: go test -v -tags integration ./... 15 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/NOTICE: -------------------------------------------------------------------------------- 1 | procfs provides functions to retrieve system, kernel and process 2 | metrics from the pseudo-filesystem proc. 3 | 4 | Copyright 2014-2015 The Prometheus Authors 5 | 6 | This product includes software developed at 7 | SoundCloud Ltd. (http://soundcloud.com/). 8 | -------------------------------------------------------------------------------- /vendor/github.com/leekchan/gtf/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - tip 4 | before_install: 5 | - go get github.com/axw/gocov/gocov 6 | - go get github.com/mattn/goveralls 7 | - if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi 8 | script: 9 | - $HOME/gopath/bin/goveralls -service=travis-ci -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/fuzz.go: -------------------------------------------------------------------------------- 1 | // +build gofuzz 2 | package amqp 3 | 4 | import "bytes" 5 | 6 | func Fuzz(data []byte) int { 7 | r := reader{bytes.NewReader(data)} 8 | frame, err := r.ReadFrame() 9 | if err != nil { 10 | if frame != nil { 11 | panic("frame is not nil") 12 | } 13 | return 0 14 | } 15 | return 1 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/ghodss/yaml/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX leaves these everywhere on SMB shares 2 | ._* 3 | 4 | # Eclipse files 5 | .classpath 6 | .project 7 | .settings/** 8 | 9 | # Emacs save files 10 | *~ 11 | 12 | # Vim-related files 13 | [._]*.s[a-w][a-z] 14 | [._]s[a-w][a-z] 15 | *.un~ 16 | Session.vim 17 | .netrwhist 18 | 19 | # Go test binaries 20 | *.test 21 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/.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 | .idea 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | *.iml 25 | -------------------------------------------------------------------------------- /vendor/github.com/leekchan/gtf/.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/spf13/cobra/.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 | 24 | cobra.test 25 | -------------------------------------------------------------------------------- /vendor/github.com/bcicen/go-haproxy/.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/golang.org/x/crypto/ssh/terminal/util_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd netbsd openbsd 6 | 7 | package terminal 8 | 9 | import "syscall" 10 | 11 | const ioctlReadTermios = syscall.TIOCGETA 12 | const ioctlWriteTermios = syscall.TIOCSETA 13 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | synapse: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | - "1936:1936" 8 | volumes: 9 | - "./examples/synapse-compose.yml:/synapse.yml" 10 | 11 | zookeeper: 12 | image: 31z4/zookeeper 13 | ports: 14 | - "2181:2181" 15 | 16 | echoservera: 17 | image: k8s.gcr.io/echoserver:1.10 18 | 19 | echoserverb: 20 | image: k8s.gcr.io/echoserver:1.10 21 | -------------------------------------------------------------------------------- /examples/template.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | apiPort: 65534 4 | logLevel: info 5 | 6 | routers: 7 | - type: template 8 | destinationFile: /tmp/notexists/templated 9 | templateFile: ./examples/template.tmpl 10 | postTemplateCommand: [/bin/bash, -c, "echo 'ZZ' > /tmp/DDDD"] 11 | 12 | services: 13 | - watcher: 14 | type: zookeeper 15 | hosts: [ "10.20.135.132:2181","10.20.143.132:2181","10.20.159.132:2181","10.20.159.133:2181","10.20.143.133:2181" ] 16 | path: /services/es/es_site_search 17 | -------------------------------------------------------------------------------- /examples/new2.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | apiHost: localhost 4 | apiPort: 4242 5 | 6 | routers: 7 | - type: haproxy 8 | reloadCommand: [/reload.sh] 9 | reloadTimeout: 1000 10 | socketFile: /run/haproxy.socket 11 | 12 | services: 13 | - name: service1 14 | port: 4242 15 | 16 | routerOptions: 17 | port: 18 | serverOptions: "check inter 2s rise 3 fall 2" 19 | 20 | watcher: 21 | type: zookeeper 22 | hosts: ['localhost:2345'] 23 | path: /services/db/db_write 24 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/user_posix.go: -------------------------------------------------------------------------------- 1 | // Package pq is a pure Go Postgres driver for the database/sql package. 2 | 3 | // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris rumprun 4 | 5 | package pq 6 | 7 | import ( 8 | "os" 9 | "os/user" 10 | ) 11 | 12 | func userCurrent() (string, error) { 13 | u, err := user.Current() 14 | if err == nil { 15 | return u.Username, nil 16 | } 17 | 18 | name := os.Getenv("USER") 19 | if name != "" { 20 | return name, nil 21 | } 22 | 23 | return "", ErrCouldNotDetectUsername 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 terminal 6 | 7 | // These constants are declared here, rather than importing 8 | // them from the syscall package as some syscall packages, even 9 | // on linux, for example gccgo, do not declare them. 10 | const ioctlReadTermios = 0x5401 // syscall.TCGETS 11 | const ioctlWriteTermios = 0x5402 // syscall.TCSETS 12 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/README.md: -------------------------------------------------------------------------------- 1 | # procfs 2 | 3 | This procfs package provides functions to retrieve system, kernel and process 4 | metrics from the pseudo-filesystem proc. 5 | 6 | *WARNING*: This package is a work in progress. Its API may still break in 7 | backwards-incompatible ways without warnings. Use it at your own risk. 8 | 9 | [![GoDoc](https://godoc.org/github.com/prometheus/procfs?status.png)](https://godoc.org/github.com/prometheus/procfs) 10 | [![Build Status](https://travis-ci.org/prometheus/procfs.svg?branch=master)](https://travis-ci.org/prometheus/procfs) 11 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/appengine.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | // +build appengine 10 | 11 | package mysql 12 | 13 | import ( 14 | "appengine/cloudsql" 15 | ) 16 | 17 | func init() { 18 | RegisterDial("cloudsql", cloudsql.Dial) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/gocarina/gocsv/safe_csv.go: -------------------------------------------------------------------------------- 1 | package gocsv 2 | 3 | //Wraps around SafeCSVWriter and makes it thread safe. 4 | import ( 5 | "encoding/csv" 6 | "sync" 7 | ) 8 | 9 | type SafeCSVWriter struct { 10 | *csv.Writer 11 | m sync.Mutex 12 | } 13 | 14 | func NewSafeCSVWriter(original *csv.Writer) *SafeCSVWriter { 15 | return &SafeCSVWriter{ 16 | Writer: original, 17 | } 18 | } 19 | 20 | //Override write 21 | func (w *SafeCSVWriter) Write(row []string) error { 22 | w.m.Lock() 23 | defer w.m.Unlock() 24 | return w.Writer.Write(row) 25 | } 26 | 27 | //Override flush 28 | func (w *SafeCSVWriter) Flush() { 29 | w.m.Lock() 30 | w.Writer.Flush() 31 | w.m.Unlock() 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/go-macaron/inject/README.md: -------------------------------------------------------------------------------- 1 | # inject [![Build Status](https://travis-ci.org/go-macaron/inject.svg?branch=master)](https://travis-ci.org/go-macaron/inject) [![](http://gocover.io/_badge/github.com/go-macaron/inject)](http://gocover.io/github.com/go-macaron/inject) 2 | 3 | Package inject provides utilities for mapping and injecting dependencies in various ways. 4 | 5 | **This a modified version of [codegangsta/inject](https://github.com/codegangsta/inject) for special purpose of Macaron** 6 | 7 | **Please use the original version if you need dependency injection feature** 8 | 9 | ## License 10 | 11 | This project is under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for the full license text. -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/result.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlResult struct { 12 | affectedRows int64 13 | insertId int64 14 | } 15 | 16 | func (res *mysqlResult) LastInsertId() (int64, error) { 17 | return res.insertId, nil 18 | } 19 | 20 | func (res *mysqlResult) RowsAffected() (int64, error) { 21 | return res.affectedRows, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/reporter_console.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "fmt" 5 | "github.com/n0rad/go-erlog/errs" 6 | "io" 7 | "os" 8 | ) 9 | 10 | type ReporterConsole struct { 11 | ReporterCommon 12 | writer io.Writer 13 | } 14 | 15 | func NewReporterConsole() *ReporterConsole { 16 | return &ReporterConsole{ 17 | writer: os.Stdout, 18 | } 19 | } 20 | 21 | func (r *ReporterConsole) Init(s *Service) error { 22 | return nil 23 | } 24 | 25 | func (r *ReporterConsole) Report(report Report) error { 26 | content, err := report.toJson() 27 | if err != nil { 28 | return errs.WithEF(err, r.fields, "Failed to prepare report") 29 | } 30 | fmt.Fprintf(r.writer, "%s\n", content) 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /examples/new3.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | routers: 4 | - type: console 5 | # reloadCommand: [/reload.sh] 6 | # reloadTimeout: 1000 7 | # socketFile: /run/haproxy.socket 8 | 9 | services: 10 | - port: 4444 11 | watcher: 12 | type: zookeeper 13 | hosts: ['localhost:2181'] 14 | path: /monitoring/mysql/db_write 15 | 16 | - port: 9999 17 | serverSort: date 18 | watcher: 19 | type: zookeeper 20 | hosts: ['localhost:2181'] 21 | path: /monitoring/mysql/db_read 22 | 23 | serverCorrelation: # this will remove the first server declared in otherService from this service 24 | type: excludeServer 25 | otherServiceName: toto 26 | scope: first 27 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/AUTHORS.md: -------------------------------------------------------------------------------- 1 | The Prometheus project was started by Matt T. Proud (emeritus) and 2 | Julius Volz in 2012. 3 | 4 | Maintainers of this repository: 5 | 6 | * Tobias Schmidt 7 | 8 | The following individuals have contributed code to this repository 9 | (listed in alphabetical order): 10 | 11 | * Armen Baghumian 12 | * Bjoern Rabenstein 13 | * David Cournapeau 14 | * Ji-Hoon, Seol 15 | * Jonas Große Sundrup 16 | * Julius Volz 17 | * Matthias Rampke 18 | * Nicky Gerritsen 19 | * Rémi Audebert 20 | * Tobias Schmidt 21 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/fnv.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | // Inline and byte-free variant of hash/fnv's fnv64a. 4 | 5 | const ( 6 | offset64 = 14695981039346656037 7 | prime64 = 1099511628211 8 | ) 9 | 10 | // hashNew initializies a new fnv64a hash value. 11 | func hashNew() uint64 { 12 | return offset64 13 | } 14 | 15 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 16 | func hashAdd(h uint64, s string) uint64 { 17 | for i := 0; i < len(s); i++ { 18 | h ^= uint64(s[i]) 19 | h *= prime64 20 | } 21 | return h 22 | } 23 | 24 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 25 | func hashAddByte(h uint64, b byte) uint64 { 26 | h ^= uint64(b) 27 | h *= prime64 28 | return h 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package pbutil provides record length-delimited Protocol Buffer streaming. 16 | package pbutil 17 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/model.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package model contains common data structures that are shared across 15 | // Prometheus components and libraries. 16 | package model 17 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/data/data.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | type Fields map[string]interface{} 4 | 5 | type FieldsConverter interface { 6 | ToFields() Fields 7 | } 8 | 9 | func WithField(key string, value interface{}) Fields { 10 | i := make(Fields, 3) 11 | return i.WithField(key, value) 12 | } 13 | 14 | func WithFields(fields FieldsConverter) Fields { 15 | return fields.ToFields() 16 | } 17 | 18 | func (f Fields) WithField(key string, value interface{}) Fields { 19 | n := f.copy() 20 | n[key] = value 21 | return n 22 | } 23 | 24 | func (f Fields) WithFields(data Fields) Fields { 25 | n := f.copy() 26 | for k, v := range data { 27 | n[k] = v 28 | } 29 | return n 30 | } 31 | 32 | func (f Fields) copy() Fields { 33 | data := Fields{} 34 | for k, v := range f { 35 | data[k] = v 36 | } 37 | return data 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/event.go: -------------------------------------------------------------------------------- 1 | package erlog 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/logs" 5 | "runtime" 6 | "strings" 7 | "time" 8 | ) 9 | 10 | type LogEvent struct { 11 | logs.Entry 12 | Depth int 13 | Time time.Time 14 | File string 15 | Line int 16 | } 17 | 18 | func NewLogEvent(entry *logs.Entry) *LogEvent { 19 | var file string 20 | var line int 21 | var ok bool 22 | for i := 2; ; i++ { 23 | _, file, line, ok = runtime.Caller(i) 24 | if !ok { 25 | file = "???" 26 | line = 0 27 | } 28 | if !strings.Contains(file, "n0rad/go-erlog") { 29 | break 30 | } 31 | if strings.Contains(file, "n0rad/go-erlog/examples") { // TODO what to do with that ? 32 | break 33 | } 34 | } 35 | 36 | return &LogEvent{ 37 | Entry: *entry, 38 | File: file, 39 | Line: line, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11 as builder 2 | 3 | RUN apt-get update && apt-get install -y \ 4 | xz-utils \ 5 | && rm -rf /var/lib/apt/lists/* 6 | 7 | ADD https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz /usr/local 8 | RUN xz -d -c /usr/local/upx-3.94-amd64_linux.tar.xz | \ 9 | tar -xOf - upx-3.94-amd64_linux/upx > /bin/upx && \ 10 | chmod a+x /bin/upx 11 | 12 | WORKDIR $GOPATH/src/github.com/blablacar/go-synapse 13 | COPY . ./ 14 | RUN ./gomake && \ 15 | cp ./dist/synapse-v0-linux-amd64/synapse / 16 | 17 | 18 | FROM haproxy:1.9 19 | 20 | RUN apt-get update && apt-get install -y \ 21 | netcat-openbsd \ 22 | && rm -rf /var/lib/apt/lists/* 23 | 24 | COPY --from=builder /synapse / 25 | COPY ./examples/synapse-minimal.yml /synapse.yml 26 | COPY ./examples/haproxy-reload.sh / 27 | RUN chmod +x /haproxy-reload.sh 28 | 29 | CMD ["/synapse", "/synapse.yml"] 30 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/transaction.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlTx struct { 12 | mc *mysqlConn 13 | } 14 | 15 | func (tx *mysqlTx) Commit() (err error) { 16 | if tx.mc == nil || tx.mc.netConn == nil { 17 | return ErrInvalidConn 18 | } 19 | err = tx.mc.exec("COMMIT") 20 | tx.mc = nil 21 | return 22 | } 23 | 24 | func (tx *mysqlTx) Rollback() (err error) { 25 | if tx.mc == nil || tx.mc.netConn == nil { 26 | return ErrInvalidConn 27 | } 28 | err = tx.mc.exec("ROLLBACK") 29 | tx.mc = nil 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull 6 | request, addressing (with `@...`) one or more of the maintainers 7 | (see [AUTHORS.md](AUTHORS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /synapse/context.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "context" 5 | "sync" 6 | ) 7 | 8 | //type Context interface { 9 | // Done() <-chan struct{} 10 | // Err() error 11 | //} 12 | // 13 | //type TimeoutContext interface { 14 | // Context 15 | // Deadline() time.Time 16 | //} 17 | 18 | type SynapseContext interface { 19 | context.Context 20 | oneshot() bool 21 | } 22 | 23 | func NewSynapseContext(parent SynapseContext, oneshot bool) SynapseContext { 24 | return &SynapseContextImpl{ 25 | parent, 26 | //oneshot, 27 | } 28 | } 29 | 30 | type SynapseContextImpl struct { 31 | SynapseContext 32 | } 33 | 34 | type ContextImpl struct { 35 | stop chan struct{} //TODO this should not be bidirectionnal 36 | doneWaiter *sync.WaitGroup 37 | oneshot bool 38 | } 39 | 40 | func newContext(oneshot bool) *ContextImpl { 41 | return &ContextImpl{ 42 | stop: make(chan struct{}), 43 | doneWaiter: &sync.WaitGroup{}, 44 | oneshot: oneshot, 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/math.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | // PowInt is int type of math.Pow function. 18 | func PowInt(x int, y int) int { 19 | if y <= 0 { 20 | return 1 21 | } else { 22 | if y % 2 == 0 { 23 | sqrt := PowInt(x, y/2) 24 | return sqrt * sqrt 25 | } else { 26 | return PowInt(x, y-1) * x 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /examples/synapse-compose.yml: -------------------------------------------------------------------------------- 1 | LogLevel: trace 2 | routers: 3 | - type: haproxy 4 | listen: 5 | stats: 6 | - mode http 7 | - bind 0.0.0.0:1936 8 | - stats enable 9 | - stats uri / 10 | - stats auth admin:admin 11 | - timeout client 100s 12 | - timeout server 100s 13 | - timeout connect 100s 14 | - timeout queue 100s 15 | configPath: /haproxy.conf 16 | reloadCommand: ["/haproxy-reload.sh"] 17 | global: 18 | - stats socket /haproxy.sock level admin 19 | services: 20 | - watcher: 21 | type: zookeeper 22 | hosts: ['zookeeper:2181'] 23 | path: /services/echoserver 24 | routerOptions: 25 | frontend: 26 | - mode http 27 | - bind 0.0.0.0:8080 28 | backend: 29 | - mode http 30 | - timeout server 2m 31 | - timeout connect 45s 32 | serverOptions: check inter 1s rise 3 fall 2 33 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_exec.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/errs" 5 | "sync" 6 | ) 7 | 8 | type CheckExec struct { 9 | CheckCommon 10 | Command []string 11 | } 12 | 13 | func NewCheckExec() *CheckExec { 14 | return &CheckExec{} 15 | } 16 | 17 | func (x *CheckExec) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 18 | x.CommonRun(x, statusChange, stop, doneWait) 19 | } 20 | 21 | func (x *CheckExec) Init(s *Service) error { 22 | if err := x.CheckCommon.CommonInit(s); err != nil { 23 | return err 24 | } 25 | 26 | if len(x.Command) == 0 { 27 | return errs.With("Exec command type require a command") 28 | } 29 | x.fields = x.fields.WithField("command", x.Command) 30 | return nil 31 | } 32 | 33 | func (x *CheckExec) Check() error { 34 | if err := ExecCommand(x.Command, x.TimeoutInMilli); err != nil { 35 | return errs.WithEF(err, x.fields, "Check command failed") 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/bcicen/go-haproxy/README.md: -------------------------------------------------------------------------------- 1 | [![GoDoc](https://godoc.org/github.com/bcicen/go-haproxy?status.svg)](https://godoc.org/github.com/bcicen/go-haproxy) 2 | [![codebeat badge](https://codebeat.co/badges/f947c19e-0d7b-47d0-87b4-4e2e555ba806)](https://codebeat.co/projects/github-com-bcicen-go-haproxy) 3 | 4 | # go-haproxy 5 | Go library for interacting with HAProxys stats socket. 6 | 7 | ## Usage 8 | 9 | Initialize a client object. Supported address schemas are `tcp://` and `unix:///` 10 | ```go 11 | client := &haproxy.HAProxyClient{ 12 | Addr: "tcp://localhost:9999", 13 | } 14 | ``` 15 | 16 | Fetch results for a built in command(currently supports `show stats` and `show info`): 17 | ```go 18 | stats, err := client.Stats() 19 | for _, i := range stats { 20 | fmt.Printf("%s: %s\n", i.SvName, i.Status) 21 | } 22 | ``` 23 | 24 | Or retrieve the result body from an arbitrary command string: 25 | ```go 26 | result, err := h.RunCommand("show info") 27 | fmt.Println(result.String()) 28 | ``` 29 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/user_windows.go: -------------------------------------------------------------------------------- 1 | // Package pq is a pure Go Postgres driver for the database/sql package. 2 | package pq 3 | 4 | import ( 5 | "path/filepath" 6 | "syscall" 7 | ) 8 | 9 | // Perform Windows user name lookup identically to libpq. 10 | // 11 | // The PostgreSQL code makes use of the legacy Win32 function 12 | // GetUserName, and that function has not been imported into stock Go. 13 | // GetUserNameEx is available though, the difference being that a 14 | // wider range of names are available. To get the output to be the 15 | // same as GetUserName, only the base (or last) component of the 16 | // result is returned. 17 | func userCurrent() (string, error) { 18 | pw_name := make([]uint16, 128) 19 | pwname_size := uint32(len(pw_name)) - 1 20 | err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size) 21 | if err != nil { 22 | return "", ErrCouldNotDetectUsername 23 | } 24 | s := syscall.UTF16ToString(pw_name) 25 | u := filepath.Base(s) 26 | return u, nil 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_tcp.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/errs" 5 | "net" 6 | "strconv" 7 | "sync" 8 | "time" 9 | ) 10 | 11 | type CheckTcp struct { 12 | CheckCommon 13 | 14 | url string 15 | } 16 | 17 | func NewCheckTcp() *CheckTcp { 18 | return &CheckTcp{} 19 | } 20 | 21 | func (x *CheckTcp) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 22 | x.CommonRun(x, statusChange, stop, doneWait) 23 | } 24 | 25 | func (x *CheckTcp) Init(s *Service) error { 26 | if err := x.CheckCommon.CommonInit(s); err != nil { 27 | return err 28 | } 29 | 30 | x.url = x.Host + ":" + strconv.Itoa(x.Port) 31 | x.fields = x.fields.WithField("url", x.url) 32 | return nil 33 | } 34 | 35 | func (x *CheckTcp) Check() error { 36 | conn, err := net.DialTimeout("tcp", x.url, time.Duration(x.TimeoutInMilli)*time.Millisecond) 37 | if err != nil { 38 | return errs.WithEF(err, x.fields, "Check failed") 39 | } 40 | conn.Close() 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/fs.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | ) 8 | 9 | // FS represents the pseudo-filesystem proc, which provides an interface to 10 | // kernel data structures. 11 | type FS string 12 | 13 | // DefaultMountPoint is the common mount point of the proc filesystem. 14 | const DefaultMountPoint = "/proc" 15 | 16 | // NewFS returns a new FS mounted under the given mountPoint. It will error 17 | // if the mount point can't be read. 18 | func NewFS(mountPoint string) (FS, error) { 19 | info, err := os.Stat(mountPoint) 20 | if err != nil { 21 | return "", fmt.Errorf("could not read %s: %s", mountPoint, err) 22 | } 23 | if !info.IsDir() { 24 | return "", fmt.Errorf("mount point %s is not a directory", mountPoint) 25 | } 26 | 27 | return FS(mountPoint), nil 28 | } 29 | 30 | // Path returns the path of the given subsystem relative to the procfs root. 31 | func (fs FS) Path(p ...string) string { 32 | return path.Join(append([]string{string(fs)}, p...)...) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/README.md: -------------------------------------------------------------------------------- 1 | Common Functions 2 | ================ 3 | 4 | [![Build Status](https://travis-ci.org/Unknwon/com.svg)](https://travis-ci.org/Unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/com) 5 | 6 | This is an open source project for commonly used functions for the Go programming language. 7 | 8 | This package need >= **go 1.2** 9 | 10 | Code Convention: based on [Go Code Convention](https://github.com/Unknwon/go-code-convention). 11 | 12 | ## Contribute 13 | 14 | Your contribute is welcome, but you have to check following steps after you added some functions and commit them: 15 | 16 | 1. Make sure you wrote user-friendly comments for **all functions** . 17 | 2. Make sure you wrote test cases with any possible condition for **all functions** in file `*_test.go`. 18 | 3. Make sure you wrote benchmarks for **all functions** in file `*_test.go`. 19 | 4. Make sure you wrote useful examples for **all functions** in file `example_test.go`. 20 | 5. Make sure you ran `go test` and got **PASS** . 21 | -------------------------------------------------------------------------------- /vendor/github.com/mgutz/ansi/print.go: -------------------------------------------------------------------------------- 1 | package ansi 2 | 3 | // PrintStyles prints all style combinations to the terminal. 4 | func PrintStyles() { 5 | oldPlain := plain 6 | plain = false 7 | 8 | bgColors := []string{ 9 | "", 10 | ":black", 11 | ":red", 12 | ":green", 13 | ":yellow", 14 | ":blue", 15 | ":magenta", 16 | ":cyan", 17 | ":white", 18 | } 19 | for fg := range Colors { 20 | for _, bg := range bgColors { 21 | println(padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg})) 22 | println(padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"})) 23 | println(padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"})) 24 | } 25 | } 26 | plain = oldPlain 27 | } 28 | 29 | func pad(s string, length int) string { 30 | for len(s) < length { 31 | s += " " 32 | } 33 | return s 34 | } 35 | 36 | func padColor(s string, styles []string) string { 37 | buffer := "" 38 | for _, style := range styles { 39 | buffer += Color(pad(s+style, 20), s+style) 40 | } 41 | return buffer 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/NOTICE: -------------------------------------------------------------------------------- 1 | Prometheus instrumentation library for Go applications 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | 7 | 8 | The following components are included in this product: 9 | 10 | goautoneg 11 | http://bitbucket.org/ww/goautoneg 12 | Copyright 2011, Open Knowledge Foundation Ltd. 13 | See README.txt for license details. 14 | 15 | perks - a fork of https://github.com/bmizerany/perks 16 | https://github.com/beorn7/perks 17 | Copyright 2013-2015 Blake Mizerany, Björn Rabenstein 18 | See https://github.com/beorn7/perks/blob/master/README.md for license details. 19 | 20 | Go support for Protocol Buffers - Google's data interchange format 21 | http://github.com/golang/protobuf/ 22 | Copyright 2010 The Go Authors 23 | See source code for license details. 24 | 25 | Support for streaming Protocol Buffer messages for the Go language (golang). 26 | https://github.com/matttproud/golang_protobuf_extensions 27 | Copyright 2013 Matt T. Proud 28 | Licensed under the Apache License, Version 2.0 29 | -------------------------------------------------------------------------------- /vendor/github.com/mgutz/ansi/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013 Mario L. Gutierrez 3 | 4 | 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: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | 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. 9 | 10 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2013, 'pq' Contributors 2 | Portions Copyright (C) 2011 Blake Mizerany 3 | 4 | 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: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | 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. 9 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Blake Mizerany 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/bcicen/go-haproxy/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 bradley 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/gocarina/gocsv/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jonathan Picques 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. -------------------------------------------------------------------------------- /vendor/github.com/leekchan/gtf/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kyoung-chan Lee (leekchan@gmail.com) 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 | -------------------------------------------------------------------------------- /synapse/router_console.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "github.com/n0rad/go-erlog/errs" 7 | "io" 8 | "os" 9 | ) 10 | 11 | type RouterConsole struct { 12 | RouterCommon 13 | 14 | writer io.Writer 15 | } 16 | 17 | func NewRouterConsole() *RouterConsole { 18 | return &RouterConsole{ 19 | writer: os.Stdout, 20 | } 21 | } 22 | 23 | func (r *RouterConsole) Run(context *ContextImpl) { 24 | r.RunCommon(context, r) 25 | } 26 | 27 | func (r *RouterConsole) Init(s *Synapse) error { 28 | if err := r.commonInit(r, s); err != nil { 29 | return errs.WithEF(err, r.fields, "Failed to init common router") 30 | } 31 | return nil 32 | } 33 | 34 | func (r *RouterConsole) Update(reports []ServiceReport) error { 35 | for _, report := range reports { 36 | res, err := json.Marshal(report.Reports) 37 | if err != nil { 38 | return errs.WithEF(err, r.fields, "Failed to prepare router update") 39 | } 40 | fmt.Fprintf(r.writer, "%s\n", res) 41 | } 42 | return nil 43 | } 44 | 45 | func (r *RouterConsole) ParseServerOptions(data []byte) (interface{}, error) { 46 | return nil, nil 47 | } 48 | 49 | func (r *RouterConsole) ParseRouterOptions(data []byte) (interface{}, error) { 50 | return nil, nil 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/fuzz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Build only when actually fuzzing 15 | // +build gofuzz 16 | 17 | package expfmt 18 | 19 | import "bytes" 20 | 21 | // Fuzz text metric parser with with github.com/dvyukov/go-fuzz: 22 | // 23 | // go-fuzz-build github.com/prometheus/common/expfmt 24 | // go-fuzz -bin expfmt-fuzz.zip -workdir fuzz 25 | // 26 | // Further input samples should go in the folder fuzz/corpus. 27 | func Fuzz(in []byte) int { 28 | parser := TextParser{} 29 | _, err := parser.TextToMetricFamilies(bytes.NewReader(in)) 30 | 31 | if err != nil { 32 | return 0 33 | } 34 | 35 | return 1 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/url.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | import ( 18 | "encoding/base64" 19 | "net/url" 20 | ) 21 | 22 | // url encode string, is + not %20 23 | func UrlEncode(str string) string { 24 | return url.QueryEscape(str) 25 | } 26 | 27 | // url decode string 28 | func UrlDecode(str string) (string, error) { 29 | return url.QueryUnescape(str) 30 | } 31 | 32 | // base64 encode 33 | func Base64Encode(str string) string { 34 | return base64.StdEncoding.EncodeToString([]byte(str)) 35 | } 36 | 37 | // base64 decode 38 | func Base64Decode(str string) (string, error) { 39 | s, e := base64.StdEncoding.DecodeString(str) 40 | return string(s), e 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/readme.md: -------------------------------------------------------------------------------- 1 | # Go erlog 2 | 3 | *this is experimental* 4 | 5 | In a fusion of logrus and go-errors logic with improvement to provide: 6 | - a logging api supporting fields and stacktrace 7 | - a logging implementation supporting multiple appenders 8 | - log level by appenders 9 | - trace log level 10 | - fields to errors 11 | - stacktrace to errors 12 | - errors to log transformation without losing fields or stackstrace 13 | 14 | # install 15 | 16 | ```shell 17 | go get github.com/n0rad/go-erlog 18 | ``` 19 | 20 | # usage 21 | 22 | basic : 23 | ```go 24 | package main 25 | 26 | import ( 27 | "github.com/n0rad/go-erlog/log" // the api 28 | _ "github.com/n0rad/go-erlog/register" // use erlog implementation, with default appender (colored to stderr) 29 | ) 30 | 31 | func main() { 32 | log.SetLevel(log.TRACE) // default is INFO 33 | 34 | log.Trace("I'm trace") 35 | log.Debug("I'm debug") 36 | log.Info("I'm info") 37 | log.Warn("I'm warn") 38 | log.Error("I'm error") 39 | 40 | func() { 41 | defer func() { recover() }() 42 | func() { log.Panic("I'm panic") }() 43 | }() 44 | 45 | log.Fatal("I'm fatal") 46 | } 47 | ``` 48 | 49 | will produce 50 | 51 | ![basic](https://raw.githubusercontent.com/n0rad/go-erlog/master/docs/basic.png) 52 | 53 | advanced : 54 | 55 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/auth.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Sean Treadway, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | // Source code and contact info at http://github.com/streadway/amqp 5 | 6 | package amqp 7 | 8 | import ( 9 | "fmt" 10 | ) 11 | 12 | // Authentication interface provides a means for different SASL authentication 13 | // mechanisms to be used during connection tuning. 14 | type Authentication interface { 15 | Mechanism() string 16 | Response() string 17 | } 18 | 19 | // PlainAuth is a similar to Basic Auth in HTTP. 20 | type PlainAuth struct { 21 | Username string 22 | Password string 23 | } 24 | 25 | func (me *PlainAuth) Mechanism() string { 26 | return "PLAIN" 27 | } 28 | 29 | func (me *PlainAuth) Response() string { 30 | return fmt.Sprintf("\000%s\000%s", me.Username, me.Password) 31 | } 32 | 33 | // Finds the first mechanism preferred by the client that the server supports. 34 | func pickSASLMechanism(client []Authentication, serverMechanisms []string) (auth Authentication, ok bool) { 35 | for _, auth = range client { 36 | for _, mech := range serverMechanisms { 37 | if auth.Mechanism() == mech { 38 | return auth, true 39 | } 40 | } 41 | } 42 | 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to pq 2 | 3 | `pq` has a backlog of pull requests, but contributions are still very 4 | much welcome. You can help with patch review, submitting bug reports, 5 | or adding new functionality. There is no formal style guide, but 6 | please conform to the style of existing code and general Go formatting 7 | conventions when submitting patches. 8 | 9 | ### Patch review 10 | 11 | Help review existing open pull requests by commenting on the code or 12 | proposed functionality. 13 | 14 | ### Bug reports 15 | 16 | We appreciate any bug reports, but especially ones with self-contained 17 | (doesn't depend on code outside of pq), minimal (can't be simplified 18 | further) test cases. It's especially helpful if you can submit a pull 19 | request with just the failing test case (you'll probably want to 20 | pattern it after the tests in 21 | [conn_test.go](https://github.com/lib/pq/blob/master/conn_test.go). 22 | 23 | ### New functionality 24 | 25 | There are a number of pending patches for new functionality, so 26 | additional feature patches will take a while to merge. Still, patches 27 | are generally reviewed based on usefulness and complexity in addition 28 | to time-in-queue, so if you have a knockout idea, take a shot. Feel 29 | free to open an issue discussion your proposed patch beforehand. 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fnv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | // Inline and byte-free variant of hash/fnv's fnv64a. 17 | 18 | const ( 19 | offset64 = 14695981039346656037 20 | prime64 = 1099511628211 21 | ) 22 | 23 | // hashNew initializies a new fnv64a hash value. 24 | func hashNew() uint64 { 25 | return offset64 26 | } 27 | 28 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 29 | func hashAdd(h uint64, s string) uint64 { 30 | for i := 0; i < len(s); i++ { 31 | h ^= uint64(s[i]) 32 | h *= prime64 33 | } 34 | return h 35 | } 36 | 37 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 38 | func hashAddByte(h uint64, b byte) uint64 { 39 | h ^= uint64(b) 40 | h *= prime64 41 | return h 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_io.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | // ProcIO models the content of /proc//io. 10 | type ProcIO struct { 11 | // Chars read. 12 | RChar uint64 13 | // Chars written. 14 | WChar uint64 15 | // Read syscalls. 16 | SyscR uint64 17 | // Write syscalls. 18 | SyscW uint64 19 | // Bytes read. 20 | ReadBytes uint64 21 | // Bytes written. 22 | WriteBytes uint64 23 | // Bytes written, but taking into account truncation. See 24 | // Documentation/filesystems/proc.txt in the kernel sources for 25 | // detailed explanation. 26 | CancelledWriteBytes int64 27 | } 28 | 29 | // NewIO creates a new ProcIO instance from a given Proc instance. 30 | func (p Proc) NewIO() (ProcIO, error) { 31 | pio := ProcIO{} 32 | 33 | f, err := os.Open(p.path("io")) 34 | if err != nil { 35 | return pio, err 36 | } 37 | defer f.Close() 38 | 39 | data, err := ioutil.ReadAll(f) 40 | if err != nil { 41 | return pio, err 42 | } 43 | 44 | ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" + 45 | "read_bytes: %d\nwrite_bytes: %d\n" + 46 | "cancelled_write_bytes: %d\n" 47 | 48 | _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR, 49 | &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes) 50 | if err != nil { 51 | return pio, err 52 | } 53 | 54 | return pio, nil 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Sean Treadway, SoundCloud Ltd. 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, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | 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/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/stat.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | // Stat represents kernel/system statistics. 12 | type Stat struct { 13 | // Boot time in seconds since the Epoch. 14 | BootTime int64 15 | } 16 | 17 | // NewStat returns kernel/system statistics read from /proc/stat. 18 | func NewStat() (Stat, error) { 19 | fs, err := NewFS(DefaultMountPoint) 20 | if err != nil { 21 | return Stat{}, err 22 | } 23 | 24 | return fs.NewStat() 25 | } 26 | 27 | // NewStat returns an information about current kernel/system statistics. 28 | func (fs FS) NewStat() (Stat, error) { 29 | f, err := os.Open(fs.Path("stat")) 30 | if err != nil { 31 | return Stat{}, err 32 | } 33 | defer f.Close() 34 | 35 | s := bufio.NewScanner(f) 36 | for s.Scan() { 37 | line := s.Text() 38 | if !strings.HasPrefix(line, "btime") { 39 | continue 40 | } 41 | fields := strings.Fields(line) 42 | if len(fields) != 2 { 43 | return Stat{}, fmt.Errorf("couldn't parse %s line %s", f.Name(), line) 44 | } 45 | i, err := strconv.ParseInt(fields[1], 10, 32) 46 | if err != nil { 47 | return Stat{}, fmt.Errorf("couldn't parse %s: %s", fields[1], err) 48 | } 49 | return Stat{BootTime: i}, nil 50 | } 51 | if err := s.Err(); err != nil { 52 | return Stat{}, fmt.Errorf("couldn't parse %s: %s", f.Name(), err) 53 | } 54 | 55 | return Stat{}, fmt.Errorf("couldn't parse %s, missing btime", f.Name()) 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Prometheus Team 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package procfs provides functions to retrieve system, kernel and process 15 | // metrics from the pseudo-filesystem proc. 16 | // 17 | // Example: 18 | // 19 | // package main 20 | // 21 | // import ( 22 | // "fmt" 23 | // "log" 24 | // 25 | // "github.com/prometheus/procfs" 26 | // ) 27 | // 28 | // func main() { 29 | // p, err := procfs.Self() 30 | // if err != nil { 31 | // log.Fatalf("could not get process: %s", err) 32 | // } 33 | // 34 | // stat, err := p.NewStat() 35 | // if err != nil { 36 | // log.Fatalf("could not get process stat: %s", err) 37 | // } 38 | // 39 | // fmt.Printf("command: %s\n", stat.Comm) 40 | // fmt.Printf("cpu time: %fs\n", stat.CPUTime()) 41 | // fmt.Printf("vsize: %dB\n", stat.VirtualMemory()) 42 | // fmt.Printf("rss: %dB\n", stat.ResidentMemory()) 43 | // } 44 | // 45 | package procfs 46 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | This is the [Prometheus](http://www.prometheus.io) telemetric 3 | instrumentation client [Go](http://golang.org) client library. It 4 | enable authors to define process-space metrics for their servers and 5 | expose them through a web service interface for extraction, 6 | aggregation, and a whole slew of other post processing techniques. 7 | 8 | # Installing 9 | $ go get github.com/prometheus/client_golang/prometheus 10 | 11 | # Example 12 | ```go 13 | package main 14 | 15 | import ( 16 | "net/http" 17 | 18 | "github.com/prometheus/client_golang/prometheus" 19 | ) 20 | 21 | var ( 22 | indexed = prometheus.NewCounter(prometheus.CounterOpts{ 23 | Namespace: "my_company", 24 | Subsystem: "indexer", 25 | Name: "documents_indexed", 26 | Help: "The number of documents indexed.", 27 | }) 28 | size = prometheus.NewGauge(prometheus.GaugeOpts{ 29 | Namespace: "my_company", 30 | Subsystem: "storage", 31 | Name: "documents_total_size_bytes", 32 | Help: "The total size of all documents in the storage.", 33 | }) 34 | ) 35 | 36 | func main() { 37 | http.Handle("/metrics", prometheus.Handler()) 38 | 39 | indexed.Inc() 40 | size.Set(5) 41 | 42 | http.ListenAndServe(":8080", nil) 43 | } 44 | 45 | func init() { 46 | prometheus.MustRegister(indexed) 47 | prometheus.MustRegister(size) 48 | } 49 | ``` 50 | 51 | # Documentation 52 | 53 | [![GoDoc](https://godoc.org/github.com/prometheus/client_golang?status.png)](https://godoc.org/github.com/prometheus/client_golang) 54 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/logs/logger.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "reflect" 7 | "runtime" 8 | "sync" 9 | ) 10 | 11 | type LogFactory interface { 12 | GetLog(name string) Log 13 | } 14 | 15 | type Log interface { 16 | Trace(msg ...string) 17 | Debug(msg ...string) 18 | Info(msg ...string) 19 | Warn(msg ...string) 20 | Error(msg ...string) 21 | Panic(msg ...string) 22 | Fatal(msg ...string) 23 | 24 | Tracef(format string, msg ...interface{}) 25 | Debugf(format string, msg ...interface{}) 26 | Infof(format string, msg ...interface{}) 27 | Warnf(format string, msg ...interface{}) 28 | Errorf(format string, msg ...interface{}) 29 | Panicf(format string, msg ...interface{}) 30 | Fatalf(format string, msg ...interface{}) 31 | 32 | LogEntry(entry *Entry) 33 | 34 | GetLevel() Level 35 | SetLevel(lvl Level) 36 | 37 | IsLevelEnabled(lvl Level) bool 38 | IsTraceEnabled() bool 39 | IsDebugEnabled() bool 40 | IsInfoEnabled() bool 41 | IsWarnEnabled() bool 42 | IsErrorEnabled() bool 43 | IsPanicEnabled() bool 44 | IsFatalEnabled() bool 45 | } 46 | 47 | var factory LogFactory = &DummyLog{Out: os.Stderr} 48 | var mu sync.Mutex 49 | 50 | func RegisterLoggerFactory(f LogFactory) { 51 | mu.Lock() 52 | if f == factory { 53 | return 54 | } 55 | 56 | if _, ok := factory.(*DummyLog); !ok { 57 | _, file, line, _ := runtime.Caller(1) 58 | fmt.Fprintf(os.Stderr, "Re-Registering the logger factory : %s:%d. There is already one registered : %s\n", file, line, reflect.TypeOf(factory)) 59 | } 60 | factory = f 61 | mu.Unlock() 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/expfmt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // A package for reading and writing Prometheus metrics. 15 | package expfmt 16 | 17 | type Format string 18 | 19 | const ( 20 | TextVersion = "0.0.4" 21 | 22 | ProtoType = `application/vnd.google.protobuf` 23 | ProtoProtocol = `io.prometheus.client.MetricFamily` 24 | ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" 25 | 26 | // The Content-Type values for the different wire protocols. 27 | FmtUnknown Format = `` 28 | FmtText Format = `text/plain; version=` + TextVersion 29 | FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` 30 | FmtProtoText Format = ProtoFmt + ` encoding=text` 31 | FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` 32 | 33 | // fmtJSON2 is hidden as it is deprecated. 34 | fmtJSON2 Format = `application/json; version=0.0.2` 35 | ) 36 | 37 | const ( 38 | hdrContentType = "Content-Type" 39 | hdrAccept = "Accept" 40 | ) 41 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/samuel/go-zookeeper/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Samuel Stauffer 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 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the author nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/oid/gen.go: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | 3 | // Generate the table of OID values 4 | // Run with 'go run gen.go'. 5 | package main 6 | 7 | import ( 8 | "database/sql" 9 | "fmt" 10 | "log" 11 | "os" 12 | "os/exec" 13 | 14 | _ "github.com/lib/pq" 15 | ) 16 | 17 | func main() { 18 | datname := os.Getenv("PGDATABASE") 19 | sslmode := os.Getenv("PGSSLMODE") 20 | 21 | if datname == "" { 22 | os.Setenv("PGDATABASE", "pqgotest") 23 | } 24 | 25 | if sslmode == "" { 26 | os.Setenv("PGSSLMODE", "disable") 27 | } 28 | 29 | db, err := sql.Open("postgres", "") 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | cmd := exec.Command("gofmt") 34 | cmd.Stderr = os.Stderr 35 | w, err := cmd.StdinPipe() 36 | if err != nil { 37 | log.Fatal(err) 38 | } 39 | f, err := os.Create("types.go") 40 | if err != nil { 41 | log.Fatal(err) 42 | } 43 | cmd.Stdout = f 44 | err = cmd.Start() 45 | if err != nil { 46 | log.Fatal(err) 47 | } 48 | fmt.Fprintln(w, "// generated by 'go run gen.go'; do not edit") 49 | fmt.Fprintln(w, "\npackage oid") 50 | fmt.Fprintln(w, "const (") 51 | rows, err := db.Query(` 52 | SELECT typname, oid 53 | FROM pg_type WHERE oid < 10000 54 | ORDER BY oid; 55 | `) 56 | if err != nil { 57 | log.Fatal(err) 58 | } 59 | var name string 60 | var oid int 61 | for rows.Next() { 62 | err = rows.Scan(&name, &oid) 63 | if err != nil { 64 | log.Fatal(err) 65 | } 66 | fmt.Fprintf(w, "T_%s Oid = %d\n", name, oid) 67 | } 68 | if err = rows.Err(); err != nil { 69 | log.Fatal(err) 70 | } 71 | fmt.Fprintln(w, ")") 72 | w.Close() 73 | cmd.Wait() 74 | } 75 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: required 3 | go: 4 | - 1.11 5 | install: 6 | - sudo apt-get install -qq upx 7 | script: 8 | - bash -c 'echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin' 9 | - "./gomake" 10 | - "./gomake docker_push" 11 | env: 12 | global: 13 | - secure: ClStPrbv+A9NJS18CpAWvmEZ50RyAJLwc415NDiRJciJFobmbIA0PaB6g6XJfHu57jlMN7jOgStEdaC8MLNLyoKugDW/ab08TfGNmcmzcJYVjjFWQmv0Z3WsvDVtCETN5WTaBWlqlDBJN4Oe3eGnxE81N9/YFX2NEWs+McnsOzqKWyyFL6TFUsUGO7qbhNLlVojQmTbUL9KaqJdz2KzVjzTcHLHNLj8wa1thO4sd8BAUg/zx4Avf2whWW3VyHSLeNhx5BJ6kZPveJBMNhFGF/1Mtxn9Ugzbsn1rkD5W/juHgVSCep3nIpkwmLh+dKVwQrfq6w1Bp2xPhYyeFf3ULflmea3lHL/MATaR73u4ZA0AgWQugRhUHSKwZ922qykWEli605KkJ11Wm0xrOlphhGGOJPUd7Va2IAYmYDodmiVU2viCirc1HTccp4AdkeYzPVJSCdBqoh1+Vv6fLkHa/kQ3fGaIa+uGSoBV1mhaFys6NpFFbFyPNV90n/k2a1PHOewXsiOpomQxy7n+rVyz4+bV+473i/XsDqj0Eoi7FiVyQgoK00k/QH3QD9LaFiisyvMKzO+SdRvlGgnv+bMiCXdZsfa1lOE8kObKxhGmN3zn+NcRQ31GbIm+qq2fgfWJpHKScfIczkR88BeQiEYTZAH46u0ZWXYtr0jI9Q5gmDfI= 14 | - secure: y55ReQZbYMIP6vgDqi1HOfvV+FlB5QWJfwmEHTce60QyZe4oBmCPaA3dDEqWwN5/HvONNPyxsyIehsCDNLnp6rbQpRtgqPU2tZaGt3jqfQiPC3GItppWrDLx/XbEmlkdYvI8fV60qrYg9LetOe3jAb3Ou9NPb3MdTLA9NuKSHtZCWCFqFfsr68yC57mlR1xjOVJj4KaTNOMd51FdxG756mFcA3x2G7parCVOewE8E9hlLiQBHjQDlvSwMSBFQOW47yebQ7s8CnfU6hE4db2cMWfsXvSf259QY5StCBOKrC43+pXzwmtiQZztvTZBn4pmUQ1CyIP3VzxEuUwgWBFuEgnmRmgqVtU1WNbqz7QpD3k9GC7x3spEYuyz32JHoJwgrxIOaujy8LHwuT2ceIOKm2Xg+/9OhuTKIaHzTaLJ0BzFIyi3oj4GBIpEDmltXcEJZn5uWXU0Tcmc+tFWCdI4Lri7wIe+VsAXPeHz17y5IafHtMeBC2zhE4pn3m9pHunzHcsH/fYwOmSJacgcRd4bd7AO6K9YZ8MwhM+IVGvOTnrSFlV9ggu04xf1ZoowFkbba2MB51DYx9x5QRor1fFi5ZWjw56QVCNsINcmRgpAUUxdUa5DGOTfmIhJMtoseCnGjeeHgNajBjGYP8+zbdpzz3NUCSEIzWBVGA5W/4JRTiY= 15 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Go-MySQL-Driver authors for copyright purposes. 2 | 3 | # If you are submitting a patch, please add your name or the name of the 4 | # organization which holds the copyright to this list in alphabetical order. 5 | 6 | # Names should be added to this file as 7 | # Name 8 | # The email address is not required for organizations. 9 | # Please keep the list sorted. 10 | 11 | 12 | # Individual Persons 13 | 14 | Aaron Hopkins 15 | Arne Hormann 16 | Carlos Nieto 17 | Chris Moos 18 | DisposaBoy 19 | Frederick Mayle 20 | Gustavo Kristic 21 | Hanno Braun 22 | Henri Yandell 23 | INADA Naoki 24 | James Harr 25 | Jian Zhen 26 | Joshua Prunier 27 | Julien Schmidt 28 | Kamil Dziedzic 29 | Leonardo YongUk Kim 30 | Lucas Liu 31 | Luke Scott 32 | Michael Woolnough 33 | Nicola Peduzzi 34 | Runrioter Wung 35 | Soroush Pour 36 | Stan Putrya 37 | Xiaobing Jiang 38 | Xiuming Chen 39 | 40 | # Organizations 41 | 42 | Barracuda Networks, Inc. 43 | Google Inc. 44 | Stripe Inc. 45 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_http.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/errs" 5 | "io/ioutil" 6 | "net/http" 7 | "strconv" 8 | "sync" 9 | "time" 10 | ) 11 | 12 | type CheckHttp struct { 13 | CheckCommon 14 | Path string 15 | 16 | url string 17 | client http.Client 18 | } 19 | 20 | func NewCheckHttp() *CheckHttp { 21 | return &CheckHttp{ 22 | Path: "/", 23 | } 24 | } 25 | 26 | func (x *CheckHttp) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 27 | x.CommonRun(x, statusChange, stop, doneWait) 28 | } 29 | 30 | func (x *CheckHttp) Init(s *Service) error { 31 | if err := x.CheckCommon.CommonInit(s); err != nil { 32 | return err 33 | } 34 | 35 | x.client = http.Client{ 36 | Timeout: time.Duration(x.TimeoutInMilli) * time.Millisecond, 37 | } 38 | if len(x.Path) == 0 || x.Path[0] != '/' { 39 | x.Path = "/" + x.Path 40 | } 41 | 42 | x.url = "http://" + x.Host + ":" + strconv.Itoa(x.Port) + x.Path 43 | x.fields = x.fields.WithField("url", x.url).WithField("type", x.Type) 44 | return nil 45 | } 46 | 47 | func (x *CheckHttp) Check() error { 48 | resp, err := x.client.Get(x.url) 49 | if err != nil || (resp.StatusCode >= 500 && resp.StatusCode < 600) { 50 | ff := x.fields 51 | if err == nil { 52 | ff = ff.WithField("status_code", resp.StatusCode) 53 | if content, err := ioutil.ReadAll(resp.Body); err == nil { 54 | ff = ff.WithField("content", string(content)) 55 | } 56 | resp.Body.Close() 57 | } 58 | return errs.WithEF(err, ff, "Url check failed") 59 | } 60 | if err == nil { 61 | resp.Body.Close() 62 | } 63 | return nil 64 | } 65 | 66 | func (x *CheckHttp) String() string { 67 | return x.url 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "io" 20 | 21 | "github.com/golang/protobuf/proto" 22 | ) 23 | 24 | // WriteDelimited encodes and dumps a message to the provided writer prefixed 25 | // with a 32-bit varint indicating the length of the encoded message, producing 26 | // a length-delimited record stream, which can be used to chain together 27 | // encoded messages of the same type together in a file. It returns the total 28 | // number of bytes written and any applicable error. This is roughly 29 | // equivalent to the companion Java API's MessageLite#writeDelimitedTo. 30 | func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) { 31 | buffer, err := proto.Marshal(m) 32 | if err != nil { 33 | return 0, err 34 | } 35 | 36 | var buf [binary.MaxVarintLen32]byte 37 | encodedLength := binary.PutUvarint(buf[:], uint64(len(buffer))) 38 | 39 | sync, err := w.Write(buf[:encodedLength]) 40 | if err != nil { 41 | return sync, err 42 | } 43 | 44 | n, err = w.Write(buffer) 45 | return n + sync, err 46 | } 47 | -------------------------------------------------------------------------------- /synapse/report_sort.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/n0rad/go-erlog/data" 6 | "github.com/n0rad/go-erlog/errs" 7 | "math/rand" 8 | "sort" 9 | "strings" 10 | ) 11 | 12 | type ReportSortType string 13 | 14 | func (n ReportSortType) Sort(reports *[]Report) { 15 | switch n { 16 | case SORT_RANDOM: 17 | for i := range *reports { 18 | j := rand.Intn(i + 1) 19 | (*reports)[i], (*reports)[j] = (*reports)[j], (*reports)[i] 20 | } 21 | case SORT_NAME: 22 | sort.Sort(ByName{*reports}) 23 | case SORT_DATE: 24 | sort.Sort(ByDate{*reports}) 25 | } 26 | } 27 | 28 | type Reports []Report 29 | 30 | func (s Reports) Len() int { 31 | return len(s) 32 | } 33 | func (s Reports) Swap(i, j int) { 34 | s[i], s[j] = s[j], s[i] 35 | } 36 | 37 | type ByName struct{ Reports } 38 | 39 | func (s ByName) Less(i, j int) bool { 40 | return s.Reports[i].Name < s.Reports[j].Name 41 | } 42 | 43 | type ByDate struct{ Reports } 44 | 45 | func (s ByDate) Less(i, j int) bool { 46 | return s.Reports[i].CreationTime < s.Reports[j].CreationTime 47 | } 48 | 49 | func (n *ReportSortType) UnmarshalJSON(d []byte) error { 50 | var s string 51 | if err := json.Unmarshal(d, &s); err != nil { 52 | return errs.WithF(data.WithField("value", string(d)), "Failed to unmarsal serverSort") 53 | } 54 | 55 | switch strings.ToLower(s) { 56 | case string(SORT_RANDOM): 57 | *n = SORT_RANDOM 58 | case string(SORT_NAME): 59 | *n = SORT_NAME 60 | case string(SORT_DATE): 61 | *n = SORT_DATE 62 | default: 63 | return errs.WithF(data.WithField("value", s), "Unknown serverSort") 64 | } 65 | return nil 66 | } 67 | 68 | const SORT_RANDOM ReportSortType = "random" 69 | const SORT_NAME ReportSortType = "name" 70 | const SORT_DATE ReportSortType = "date" 71 | -------------------------------------------------------------------------------- /vendor/github.com/mgutz/ansi/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package ansi is a small, fast library to create ANSI colored strings and codes. 3 | 4 | Installation 5 | 6 | # this installs the color viewer and the package 7 | go get -u github.com/mgutz/ansi/cmd/ansi-mgutz 8 | 9 | Example 10 | 11 | // colorize a string, SLOW 12 | msg := ansi.Color("foo", "red+b:white") 13 | 14 | // create a closure to avoid recalculating ANSI code compilation 15 | phosphorize := ansi.ColorFunc("green+h:black") 16 | msg = phosphorize("Bring back the 80s!") 17 | msg2 := phospohorize("Look, I'm a CRT!") 18 | 19 | // cache escape codes and build strings manually 20 | lime := ansi.ColorCode("green+h:black") 21 | reset := ansi.ColorCode("reset") 22 | 23 | fmt.Println(lime, "Bring back the 80s!", reset) 24 | 25 | Other examples 26 | 27 | Color(s, "red") // red 28 | Color(s, "red+b") // red bold 29 | Color(s, "red+B") // red blinking 30 | Color(s, "red+u") // red underline 31 | Color(s, "red+bh") // red bold bright 32 | Color(s, "red:white") // red on white 33 | Color(s, "red+b:white+h") // red bold on white bright 34 | Color(s, "red+B:white+h") // red blink on white bright 35 | 36 | To view color combinations, from terminal 37 | 38 | ansi-mgutz 39 | 40 | Style format 41 | 42 | "foregroundColor+attributes:backgroundColor+attributes" 43 | 44 | Colors 45 | 46 | black 47 | red 48 | green 49 | yellow 50 | blue 51 | magenta 52 | cyan 53 | white 54 | 55 | Attributes 56 | 57 | b = bold foreground 58 | B = Blink foreground 59 | u = underline foreground 60 | h = high intensity (bright) foreground, background 61 | i = inverse 62 | 63 | Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) 64 | */ 65 | package ansi 66 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | ## Reporting Issues 4 | 5 | Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed). 6 | 7 | Please provide the following minimum information: 8 | * Your Go-MySQL-Driver version (or git SHA) 9 | * Your Go version (run `go version` in your console) 10 | * A detailed issue description 11 | * Error Log if present 12 | * If possible, a short example 13 | 14 | 15 | ## Contributing Code 16 | 17 | By contributing to this project, you share your code under the Mozilla Public License 2, as specified in the LICENSE file. 18 | Don't forget to add yourself to the AUTHORS file. 19 | 20 | ### Pull Requests Checklist 21 | 22 | Please check the following points before submitting your pull request: 23 | - [x] Code compiles correctly 24 | - [x] Created tests, if possible 25 | - [x] All tests pass 26 | - [x] Extended the README / documentation, if necessary 27 | - [x] Added yourself to the AUTHORS file 28 | 29 | ### Code Review 30 | 31 | Everyone is invited to review and comment on pull requests. 32 | If it looks fine to you, comment with "LGTM" (Looks good to me). 33 | 34 | If changes are required, notice the reviewers with "PTAL" (Please take another look) after committing the fixes. 35 | 36 | Before merging the Pull Request, at least one [team member](https://github.com/go-sql-driver?tab=members) must have commented with "LGTM". 37 | 38 | ## Development Ideas 39 | 40 | If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/go-sql-driver/mysql/wiki/Development-Ideas) Wiki page. 41 | -------------------------------------------------------------------------------- /vendor/github.com/samuel/go-zookeeper/zk/util.go: -------------------------------------------------------------------------------- 1 | package zk 2 | 3 | import ( 4 | "crypto/sha1" 5 | "encoding/base64" 6 | "fmt" 7 | "math/rand" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | // AuthACL produces an ACL list containing a single ACL which uses the 13 | // provided permissions, with the scheme "auth", and ID "", which is used 14 | // by ZooKeeper to represent any authenticated user. 15 | func AuthACL(perms int32) []ACL { 16 | return []ACL{{perms, "auth", ""}} 17 | } 18 | 19 | // WorldACL produces an ACL list containing a single ACL which uses the 20 | // provided permissions, with the scheme "world", and ID "anyone", which 21 | // is used by ZooKeeper to represent any user at all. 22 | func WorldACL(perms int32) []ACL { 23 | return []ACL{{perms, "world", "anyone"}} 24 | } 25 | 26 | func DigestACL(perms int32, user, password string) []ACL { 27 | userPass := []byte(fmt.Sprintf("%s:%s", user, password)) 28 | h := sha1.New() 29 | if n, err := h.Write(userPass); err != nil || n != len(userPass) { 30 | panic("SHA1 failed") 31 | } 32 | digest := base64.StdEncoding.EncodeToString(h.Sum(nil)) 33 | return []ACL{{perms, "digest", fmt.Sprintf("%s:%s", user, digest)}} 34 | } 35 | 36 | // FormatServers takes a slice of addresses, and makes sure they are in a format 37 | // that resembles :. If the server has no port provided, the 38 | // DefaultPort constant is added to the end. 39 | func FormatServers(servers []string) []string { 40 | for i := range servers { 41 | if !strings.Contains(servers[i], ":") { 42 | servers[i] = servers[i] + ":" + strconv.Itoa(DefaultPort) 43 | } 44 | } 45 | return servers 46 | } 47 | 48 | // stringShuffle performs a Fisher-Yates shuffle on a slice of strings 49 | func stringShuffle(s []string) { 50 | for i := len(s) - 1; i > 0; i-- { 51 | j := rand.Intn(i + 1) 52 | s[i], s[j] = s[j], s[i] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/logs/levels.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "encoding/json" 7 | ) 8 | 9 | type Level uint8 10 | 11 | const ( 12 | // the program cannot continue. will log and exit(1) 13 | FATAL Level = iota 14 | // the routine cannot continue. will log and call go panic function 15 | PANIC 16 | // program continue but caller have received error or data lost or similar 17 | ERROR 18 | // recovered problem or non critical 19 | WARN 20 | // general info 21 | INFO 22 | // tell what is going on step by step 23 | DEBUG 24 | // log data content 25 | TRACE 26 | ) 27 | 28 | func (r *Level) UnmarshalJSON(b []byte) error { 29 | var str string 30 | if err := json.Unmarshal(b, &str); err != nil { 31 | return err 32 | } 33 | 34 | lvl, err := ParseLevel(str) 35 | if err != nil { 36 | return err 37 | } 38 | *r = lvl 39 | return nil 40 | } 41 | 42 | func (level Level) String() string { 43 | switch level { 44 | case TRACE: 45 | return "TRACE" 46 | case DEBUG: 47 | return "DEBUG" 48 | case INFO: 49 | return "INFO" 50 | case WARN: 51 | return "WARN" 52 | case ERROR: 53 | return "ERROR" 54 | case FATAL: 55 | return "FATAL" 56 | case PANIC: 57 | return "PANIC" 58 | } 59 | return "UNKNOWN" 60 | } 61 | 62 | func ParseLevel(lvl string) (Level, error) { 63 | lvl2 := strings.ToUpper(lvl) 64 | switch lvl2 { 65 | case "PANIC": 66 | return PANIC, nil 67 | case "FATAL": 68 | return FATAL, nil 69 | case "ERROR": 70 | return ERROR, nil 71 | case "WARN", "WARNING": 72 | return WARN, nil 73 | case "INFO": 74 | return INFO, nil 75 | case "DEBUG": 76 | return DEBUG, nil 77 | case "TRACE": 78 | return TRACE, nil 79 | } 80 | var l Level 81 | return l, fmt.Errorf("Not a valid log level: %s", lvl) // not using errs to prevent cycle dep 82 | } 83 | 84 | func (l Level) IsEnableFor(level Level) bool { 85 | return level >= l 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/reporter_file.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/errs" 5 | "os" 6 | "path" 7 | ) 8 | 9 | type ReporterFile struct { 10 | ReporterCommon 11 | Path string 12 | Append bool 13 | } 14 | 15 | func NewReporterFile() *ReporterFile { 16 | return &ReporterFile{ 17 | Path: "/tmp/nerve.report", 18 | Append: false, 19 | } 20 | } 21 | 22 | func (r *ReporterFile) Init(s *Service) error { 23 | if r.Path == "" { 24 | return errs.WithF(s.fields, "Reporter file need a path") 25 | } 26 | 27 | r.fields = r.fields.WithField("path", r.Path) 28 | if err := os.MkdirAll(path.Dir(r.Path), 0755); err != nil { 29 | return errs.WithEF(err, r.fields.WithField("path", path.Dir(r.Path)), "Failed to create directories") 30 | } 31 | file, err := r.openReport() 32 | if err != nil { 33 | return err 34 | } 35 | defer file.Close() 36 | return nil 37 | } 38 | 39 | func (r *ReporterFile) openReport() (*os.File, error) { 40 | flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC 41 | if r.Append { 42 | flags = os.O_APPEND | os.O_CREATE | os.O_WRONLY 43 | } 44 | file, err := os.OpenFile(r.Path, flags, 0644) 45 | if err != nil { 46 | return nil, errs.WithEF(err, r.fields, "Failed to open report file") 47 | } 48 | return file, nil 49 | } 50 | 51 | func (r *ReporterFile) Report(report Report) error { 52 | file, err := r.openReport() 53 | if err != nil { 54 | return err 55 | } 56 | defer file.Close() 57 | 58 | var res string 59 | if !r.Append && !*report.Available { 60 | res = "" 61 | } else { 62 | content, err := report.toJson() 63 | if err != nil { 64 | return errs.WithEF(err, r.fields, "Failed to prepare report") 65 | } 66 | res = string(content) + "\n" 67 | } 68 | 69 | if n, err := file.WriteString(res); err != nil || n != len(res) { 70 | return errs.WithEF(err, r.fields, "Failed write report to file") 71 | } 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/reporter.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/n0rad/go-erlog/data" 6 | "github.com/n0rad/go-erlog/errs" 7 | ) 8 | 9 | type Reporter interface { 10 | Report(report Report) error 11 | Init(s *Service) error 12 | Destroy() 13 | getCommon() *ReporterCommon 14 | GetFields() data.Fields 15 | } 16 | 17 | type ReporterCommon struct { 18 | Type string 19 | 20 | fields data.Fields 21 | } 22 | 23 | func (r *ReporterCommon) GetFields() data.Fields { 24 | return r.fields 25 | } 26 | 27 | func (r *ReporterCommon) Init(s *Service) error { 28 | r.fields = s.fields.WithField("type", r.Type) 29 | return nil 30 | } 31 | 32 | func (r *ReporterCommon) Destroy() {} 33 | 34 | func (r *ReporterCommon) getCommon() *ReporterCommon { 35 | return r 36 | } 37 | 38 | func ReporterFromJson(data []byte, s *Service) (Reporter, error) { 39 | t := &ReporterCommon{} 40 | if err := json.Unmarshal([]byte(data), t); err != nil { 41 | return nil, errs.WithE(err, "Failed to unmarshall reporter type") 42 | } 43 | 44 | fields := s.fields.WithField("type", t.Type) 45 | var typedReporter Reporter 46 | switch t.Type { 47 | case "file": 48 | typedReporter = NewReporterFile() 49 | case "console": 50 | typedReporter = NewReporterConsole() 51 | case "zookeeper": 52 | typedReporter = NewReporterZookeeper() 53 | default: 54 | return nil, errs.WithF(fields, "Unsupported reporter type") 55 | } 56 | 57 | if err := json.Unmarshal([]byte(data), &typedReporter); err != nil { 58 | return nil, errs.WithEF(err, fields, "Failed to unmarshall reporter") 59 | } 60 | 61 | if err := typedReporter.getCommon().Init(s); err != nil { 62 | return nil, errs.WithEF(err, fields, "Failed to init common reporter") 63 | } 64 | 65 | if err := typedReporter.Init(s); err != nil { 66 | return nil, errs.WithEF(err, fields, "Failed to init reporter") 67 | } 68 | return typedReporter, nil 69 | } 70 | -------------------------------------------------------------------------------- /synapse/router_haproxy_test.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/blablacar/go-nerve/nerve" 7 | ) 8 | 9 | func TestIsSocketUpdatable(t *testing.T) { 10 | s := &Synapse{} 11 | s.Init("version", "buildtime", true) 12 | 13 | r := NewRouterHaProxy() 14 | r.Global = []string{"stats socket /tmp/haproxy.sock"} 15 | r.Init(s) 16 | 17 | yes := true 18 | no := false 19 | 20 | NodeA := Report{ 21 | nerve.Report{ 22 | Available: &yes, 23 | Host: "10.0.0.1", 24 | Port: 8080, 25 | Name: "NodeA", 26 | HaProxyServerOptions: "", 27 | }, 28 | int64(0), 29 | } 30 | NodeB := Report{ 31 | nerve.Report{ 32 | Available: &no, 33 | Host: "10.0.0.1", 34 | Port: 8080, 35 | Name: "NodeB", 36 | HaProxyServerOptions: "", 37 | }, 38 | int64(0), 39 | } 40 | 41 | srNew := ServiceReport{ 42 | Service: &Service{ 43 | Name: "ServiceA", 44 | id: 0, 45 | }, 46 | Reports: []Report{ 47 | NodeA, 48 | }, 49 | } 50 | 51 | r.lastEvents = map[string]*ServiceReport{ 52 | "ServiceA_0": { 53 | Service: &Service{ 54 | Name: "ServiceA", 55 | }, 56 | Reports: []Report{ 57 | NodeA, 58 | }, 59 | }, 60 | } 61 | 62 | // last has nodeA, new has nodeA 63 | if u := r.isSocketUpdatable(srNew); !u { 64 | t.Errorf("isSocketUpdatable should be true, was %v", u) 65 | } 66 | 67 | // last has nodeA, new has nodeA+nodeB 68 | srNew.Reports = append(srNew.Reports, NodeB) 69 | if u := r.isSocketUpdatable(srNew); u { 70 | t.Errorf("isSocketUpdatable should be false, was %v", u) 71 | } 72 | 73 | // last has nodeA+nodeB, new has nodeA+nodeB 74 | r.lastEvents["ServiceA_0"].Reports = append(r.lastEvents["ServiceA_0"].Reports, NodeB) 75 | if u := r.isSocketUpdatable(srNew); !u { 76 | t.Errorf("isSocketUpdatable should be true, was %v", u) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/html.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | import ( 18 | "html" 19 | "regexp" 20 | "strings" 21 | ) 22 | 23 | // Html2JS converts []byte type of HTML content into JS format. 24 | func Html2JS(data []byte) []byte { 25 | s := string(data) 26 | s = strings.Replace(s, `\`, `\\`, -1) 27 | s = strings.Replace(s, "\n", `\n`, -1) 28 | s = strings.Replace(s, "\r", "", -1) 29 | s = strings.Replace(s, "\"", `\"`, -1) 30 | s = strings.Replace(s, "", "<table>", -1) 31 | return []byte(s) 32 | } 33 | 34 | // encode html chars to string 35 | func HtmlEncode(str string) string { 36 | return html.EscapeString(str) 37 | } 38 | 39 | // decode string to html chars 40 | func HtmlDecode(str string) string { 41 | return html.UnescapeString(str) 42 | } 43 | 44 | // strip tags in html string 45 | func StripTags(src string) string { 46 | //去除style,script,html tag 47 | re := regexp.MustCompile(`(?s)<(?:style|script)[^<>]*>.*?|]*>|`) 48 | src = re.ReplaceAllString(src, "") 49 | 50 | //trim all spaces(2+) into \n 51 | re = regexp.MustCompile(`\s{2,}`) 52 | src = re.ReplaceAllString(src, "\n") 53 | 54 | return strings.TrimSpace(src) 55 | } 56 | 57 | // change \n to
58 | func Nl2br(str string) string { 59 | return strings.Replace(str, "\n", "
", -1) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/bcicen/go-haproxy/client.go: -------------------------------------------------------------------------------- 1 | // Package haproxy provides a minimal client for communicating with, and issuing commands to, HAproxy over a network or file socket. 2 | package haproxy 3 | 4 | import ( 5 | "bytes" 6 | "fmt" 7 | "io" 8 | "net" 9 | "strings" 10 | "time" 11 | ) 12 | 13 | const ( 14 | socketSchema = "unix://" 15 | tcpSchema = "tcp://" 16 | ) 17 | 18 | // HAProxyClient is the main structure of the library. 19 | type HAProxyClient struct { 20 | Addr string 21 | Timeout int 22 | conn net.Conn 23 | } 24 | 25 | // RunCommand is the entrypoint to the client. Sends an arbitray command string to HAProxy. 26 | func (h *HAProxyClient) RunCommand(cmd string) (*bytes.Buffer, error) { 27 | err := h.dial() 28 | if err != nil { 29 | return nil, err 30 | } 31 | defer h.conn.Close() 32 | 33 | result := bytes.NewBuffer(nil) 34 | 35 | _, err = h.conn.Write([]byte(cmd + "\n")) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | _, err = io.Copy(result, h.conn) 41 | if err != nil { 42 | return nil, err 43 | } 44 | 45 | if strings.HasPrefix(result.String(), "Unknown command") { 46 | return nil, fmt.Errorf("Unknown command: %s", cmd) 47 | } 48 | 49 | return result, nil 50 | } 51 | 52 | func (h *HAProxyClient) dial() (err error) { 53 | if h.Timeout == 0 { 54 | h.Timeout = 30 55 | } 56 | 57 | timeout := time.Duration(h.Timeout) * time.Second 58 | 59 | switch h.schema() { 60 | case "socket": 61 | h.conn, err = net.DialTimeout("unix", strings.Replace(h.Addr, socketSchema, "", 1), timeout) 62 | case "tcp": 63 | h.conn, err = net.DialTimeout("tcp", strings.Replace(h.Addr, tcpSchema, "", 1), timeout) 64 | default: 65 | return fmt.Errorf("unknown schema") 66 | } 67 | return err 68 | } 69 | 70 | func (h *HAProxyClient) schema() string { 71 | if strings.HasPrefix(h.Addr, socketSchema) { 72 | return "socket" 73 | } 74 | if strings.HasPrefix(h.Addr, tcpSchema) { 75 | return "tcp" 76 | } 77 | return "" 78 | } 79 | -------------------------------------------------------------------------------- /synapse/watcher.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/n0rad/go-erlog/data" 6 | "github.com/n0rad/go-erlog/errs" 7 | ) 8 | 9 | type WatcherCommon struct { 10 | Type string 11 | 12 | reports *reportMap 13 | service *Service 14 | fields data.Fields 15 | } 16 | 17 | type Watcher interface { 18 | Init(service *Service) error 19 | GetFields() data.Fields 20 | Watch(context *ContextImpl, events chan<- ServiceReport, s *Service) 21 | GetServiceName() string 22 | } 23 | 24 | func (w *WatcherCommon) CommonInit(service *Service) error { 25 | w.fields = data.WithField("type", w.Type) 26 | w.service = service 27 | w.reports = NewReportMap(service) 28 | return nil 29 | } 30 | 31 | func (w *WatcherCommon) GetFields() data.Fields { 32 | return w.fields 33 | } 34 | 35 | func WatcherFromJson(content []byte, service *Service) (Watcher, error) { 36 | t := &WatcherCommon{} 37 | if err := json.Unmarshal([]byte(content), t); err != nil { 38 | return nil, errs.WithE(err, "Failed to unmarshall watcher type") 39 | } 40 | 41 | fields := data.WithField("type", t.Type) 42 | var typedWatcher Watcher 43 | switch t.Type { 44 | case "zookeeper": 45 | typedWatcher = NewWatcherZookeeper() 46 | default: 47 | return nil, errs.WithF(fields, "Unsupported watcher type") 48 | } 49 | 50 | if err := json.Unmarshal([]byte(content), &typedWatcher); err != nil { 51 | return nil, errs.WithEF(err, fields, "Failed to unmarshall watcher") 52 | } 53 | 54 | if err := typedWatcher.Init(service); err != nil { 55 | return nil, errs.WithEF(err, fields, "Failed to init watcher") 56 | } 57 | return typedWatcher, nil 58 | } 59 | 60 | func (w *WatcherZookeeper) changedToReport(reportsStop <-chan struct{}, events chan<- ServiceReport, s *Service) { 61 | for { 62 | select { 63 | case <-w.reports.changed: 64 | reports := w.reports.getValues() 65 | events <- ServiceReport{Service: s, Reports: reports} 66 | case <-reportsStop: 67 | return 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/url.go: -------------------------------------------------------------------------------- 1 | package pq 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | nurl "net/url" 7 | "sort" 8 | "strings" 9 | ) 10 | 11 | // ParseURL no longer needs to be used by clients of this library since supplying a URL as a 12 | // connection string to sql.Open() is now supported: 13 | // 14 | // sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full") 15 | // 16 | // It remains exported here for backwards-compatibility. 17 | // 18 | // ParseURL converts a url to a connection string for driver.Open. 19 | // Example: 20 | // 21 | // "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full" 22 | // 23 | // converts to: 24 | // 25 | // "user=bob password=secret host=1.2.3.4 port=5432 dbname=mydb sslmode=verify-full" 26 | // 27 | // A minimal example: 28 | // 29 | // "postgres://" 30 | // 31 | // This will be blank, causing driver.Open to use all of the defaults 32 | func ParseURL(url string) (string, error) { 33 | u, err := nurl.Parse(url) 34 | if err != nil { 35 | return "", err 36 | } 37 | 38 | if u.Scheme != "postgres" && u.Scheme != "postgresql" { 39 | return "", fmt.Errorf("invalid connection protocol: %s", u.Scheme) 40 | } 41 | 42 | var kvs []string 43 | escaper := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`) 44 | accrue := func(k, v string) { 45 | if v != "" { 46 | kvs = append(kvs, k+"="+escaper.Replace(v)) 47 | } 48 | } 49 | 50 | if u.User != nil { 51 | v := u.User.Username() 52 | accrue("user", v) 53 | 54 | v, _ = u.User.Password() 55 | accrue("password", v) 56 | } 57 | 58 | if host, port, err := net.SplitHostPort(u.Host); err != nil { 59 | accrue("host", u.Host) 60 | } else { 61 | accrue("host", host) 62 | accrue("port", port) 63 | } 64 | 65 | if u.Path != "" { 66 | accrue("dbname", u.Path[1:]) 67 | } 68 | 69 | q := u.Query() 70 | for k := range q { 71 | accrue(k, q.Get(k)) 72 | } 73 | 74 | sort.Strings(kvs) // Makes testing easier (not a performance concern) 75 | return strings.Join(kvs, " "), nil 76 | } 77 | -------------------------------------------------------------------------------- /examples/new.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | apiHost: localhost 4 | apiPort: 8888 5 | 6 | routers: 7 | - type: haproxy 8 | configPath: /tmp/hap.config 9 | reloadCommand: [./examples/haproxy_reload.sh] 10 | 11 | global: 12 | # - log 127.0.0.1 local5 notice 13 | - maxconn 32000 14 | - ulimit-n 65536 15 | - daemon 16 | - stats socket /tmp/hap.socket level admin 17 | 18 | listen: 19 | stats: 20 | - mode http 21 | - bind 127.0.0.1:1936 22 | - stats enable 23 | # - stats hide-version 24 | # - stats realm Haproxy\ Statistics 25 | - stats uri / 26 | # - stats refresh 5s 27 | # - stats auth admin:admin 28 | # - timeout client 100s 29 | # - timeout server 100s 30 | # - timeout connect 100s 31 | # - timeout queue 100s 32 | 33 | services: 34 | - watcher: 35 | type: zookeeper 36 | hosts: ['localhost:2181'] 37 | path: /services/api/myapi 38 | serverOptions: cookie {{sha1String .Name}} check inter 2s rise 3 fall 2 39 | routerOptions: 40 | frontend: 41 | - mode tcp 42 | - timeout client 31s 43 | - bind 127.0.0.1:5679 44 | backend: 45 | - mode tcp 46 | - timeout server 2m 47 | - timeout connect 45s 48 | 49 | - watcher: 50 | type: zookeeper 51 | hosts: ['localhost:2181'] 52 | path: /monitoring/api/myapi 53 | 54 | - watcher: 55 | type: zookeeper 56 | path: /monitoring/sql/sql1 57 | hosts: ['localhost:2181'] 58 | 59 | serverOptions: check inter 2s rise 3 fall 2 60 | routerOptions: 61 | frontend: 62 | - mode tcp 63 | - timeout client 31s 64 | - bind 127.0.0.1:5679 65 | backend: 66 | - mode tcp 67 | - timeout server 2m 68 | - timeout connect 45s 69 | - option mysql-check user haproxy 70 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/buf.go: -------------------------------------------------------------------------------- 1 | package pq 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | 7 | "github.com/lib/pq/oid" 8 | ) 9 | 10 | type readBuf []byte 11 | 12 | func (b *readBuf) int32() (n int) { 13 | n = int(int32(binary.BigEndian.Uint32(*b))) 14 | *b = (*b)[4:] 15 | return 16 | } 17 | 18 | func (b *readBuf) oid() (n oid.Oid) { 19 | n = oid.Oid(binary.BigEndian.Uint32(*b)) 20 | *b = (*b)[4:] 21 | return 22 | } 23 | 24 | // N.B: this is actually an unsigned 16-bit integer, unlike int32 25 | func (b *readBuf) int16() (n int) { 26 | n = int(binary.BigEndian.Uint16(*b)) 27 | *b = (*b)[2:] 28 | return 29 | } 30 | 31 | func (b *readBuf) string() string { 32 | i := bytes.IndexByte(*b, 0) 33 | if i < 0 { 34 | errorf("invalid message format; expected string terminator") 35 | } 36 | s := (*b)[:i] 37 | *b = (*b)[i+1:] 38 | return string(s) 39 | } 40 | 41 | func (b *readBuf) next(n int) (v []byte) { 42 | v = (*b)[:n] 43 | *b = (*b)[n:] 44 | return 45 | } 46 | 47 | func (b *readBuf) byte() byte { 48 | return b.next(1)[0] 49 | } 50 | 51 | type writeBuf struct { 52 | buf []byte 53 | pos int 54 | } 55 | 56 | func (b *writeBuf) int32(n int) { 57 | x := make([]byte, 4) 58 | binary.BigEndian.PutUint32(x, uint32(n)) 59 | b.buf = append(b.buf, x...) 60 | } 61 | 62 | func (b *writeBuf) int16(n int) { 63 | x := make([]byte, 2) 64 | binary.BigEndian.PutUint16(x, uint16(n)) 65 | b.buf = append(b.buf, x...) 66 | } 67 | 68 | func (b *writeBuf) string(s string) { 69 | b.buf = append(b.buf, (s + "\000")...) 70 | } 71 | 72 | func (b *writeBuf) byte(c byte) { 73 | b.buf = append(b.buf, c) 74 | } 75 | 76 | func (b *writeBuf) bytes(v []byte) { 77 | b.buf = append(b.buf, v...) 78 | } 79 | 80 | func (b *writeBuf) wrap() []byte { 81 | p := b.buf[b.pos:] 82 | binary.BigEndian.PutUint32(p, uint32(len(p))) 83 | return b.buf 84 | } 85 | 86 | func (b *writeBuf) next(c byte) { 87 | p := b.buf[b.pos:] 88 | binary.BigEndian.PutUint32(p, uint32(len(p))) 89 | b.pos = len(b.buf) + 1 90 | b.buf = append(b.buf, c, 0, 0, 0, 0) 91 | } 92 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/regex.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | import "regexp" 18 | 19 | const ( 20 | regex_email_pattern = `(?i)[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}` 21 | regex_strict_email_pattern = `(?i)[A-Z0-9!#$%&'*+/=?^_{|}~-]+` + 22 | `(?:\.[A-Z0-9!#$%&'*+/=?^_{|}~-]+)*` + 23 | `@(?:[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?\.)+` + 24 | `[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?` 25 | regex_url_pattern = `(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?` 26 | ) 27 | 28 | var ( 29 | regex_email *regexp.Regexp 30 | regex_strict_email *regexp.Regexp 31 | regex_url *regexp.Regexp 32 | ) 33 | 34 | func init() { 35 | regex_email = regexp.MustCompile(regex_email_pattern) 36 | regex_strict_email = regexp.MustCompile(regex_strict_email_pattern) 37 | regex_url = regexp.MustCompile(regex_url_pattern) 38 | } 39 | 40 | // validate string is an email address, if not return false 41 | // basically validation can match 99% cases 42 | func IsEmail(email string) bool { 43 | return regex_email.MatchString(email) 44 | } 45 | 46 | // validate string is an email address, if not return false 47 | // this validation omits RFC 2822 48 | func IsEmailRFC(email string) bool { 49 | return regex_strict_email.MatchString(email) 50 | } 51 | 52 | // validate string is a url link, if not return false 53 | // simple validation can match 99% cases 54 | func IsUrl(url string) bool { 55 | return regex_url.MatchString(url) 56 | } 57 | -------------------------------------------------------------------------------- /synapse/report.go: -------------------------------------------------------------------------------- 1 | package synapse 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/blablacar/go-nerve/nerve" 6 | "github.com/n0rad/go-erlog/data" 7 | "github.com/n0rad/go-erlog/logs" 8 | "sync" 9 | ) 10 | 11 | const PrometheusLabelContent = "content" 12 | 13 | type reportMap struct { 14 | sync.RWMutex 15 | service *Service 16 | m map[string]Report 17 | changed chan struct{} 18 | } 19 | 20 | type Report struct { 21 | nerve.Report 22 | CreationTime int64 23 | } 24 | 25 | func (r Report) String() string { 26 | return r.Report.String() 27 | } 28 | 29 | func NewReportMap(service *Service) *reportMap { 30 | n := reportMap{ 31 | service: service, 32 | } 33 | n.m = make(map[string]Report) 34 | n.changed = make(chan struct{}) 35 | return &n 36 | } 37 | 38 | func (n *reportMap) setNoNodes() { 39 | n.Lock() 40 | n.m = make(map[string]Report) 41 | n.Unlock() 42 | n.changed <- struct{}{} 43 | } 44 | 45 | func (n *reportMap) addRawReport(name string, content []byte, failFields data.Fields, creationTime int64) { 46 | r := nerve.Report{} 47 | if err := json.Unmarshal(content, &r); err != nil { 48 | n.service.synapse.watcherFailures.WithLabelValues(n.service.Name, PrometheusLabelContent).Inc() 49 | logs.WithEF(err, failFields.WithField("content", string(content))).Warn("Failed to unmarshal report") 50 | return 51 | } 52 | n.Lock() 53 | n.m[name] = Report{r, creationTime} 54 | n.Unlock() 55 | n.changed <- struct{}{} 56 | } 57 | 58 | func (n *reportMap) removeAll() { 59 | n.Lock() 60 | for k := range n.m { 61 | delete(n.m, k) 62 | } 63 | n.Unlock() 64 | n.changed <- struct{}{} 65 | } 66 | 67 | func (n *reportMap) removeNode(name string) { 68 | n.Lock() 69 | delete(n.m, name) 70 | n.Unlock() 71 | n.changed <- struct{}{} 72 | } 73 | 74 | func (n *reportMap) get(name string) (Report, bool) { 75 | n.RLock() 76 | defer n.RUnlock() 77 | value, ok := n.m[name] 78 | return value, ok 79 | } 80 | 81 | func (n *reportMap) getValues() []Report { 82 | n.RLock() 83 | defer n.RUnlock() 84 | r := []Report{} 85 | for _, v := range n.m { 86 | r = append(r, v) 87 | } 88 | return r 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/logs/default.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | func GetDefaultLog() Log { return factory.GetLog("") } 4 | func GetLog(name string) Log { return factory.GetLog(name) } 5 | 6 | func SetLevel(lvl Level) { GetDefaultLog().SetLevel(lvl) } 7 | func GetLevel() Level { return GetDefaultLog().GetLevel() } 8 | 9 | func Trace(msg ...string) { GetDefaultLog().Trace(msg...) } 10 | func Debug(msg ...string) { GetDefaultLog().Debug(msg...) } 11 | func Info(msg ...string) { GetDefaultLog().Info(msg...) } 12 | func Warn(msg ...string) { GetDefaultLog().Warn(msg...) } 13 | func Error(msg ...string) { GetDefaultLog().Error(msg...) } 14 | func Panic(msg ...string) { GetDefaultLog().Panic(msg...) } 15 | func Fatal(msg ...string) { GetDefaultLog().Fatal(msg...) } 16 | 17 | func Tracef(format string, msg ...interface{}) { GetDefaultLog().Tracef(format, msg...) } 18 | func Debugf(format string, msg ...interface{}) { GetDefaultLog().Debugf(format, msg...) } 19 | func Infof(format string, msg ...interface{}) { GetDefaultLog().Infof(format, msg...) } 20 | func Warnf(format string, msg ...interface{}) { GetDefaultLog().Warnf(format, msg...) } 21 | func Errorf(format string, msg ...interface{}) { GetDefaultLog().Errorf(format, msg...) } 22 | func Panicf(format string, msg ...interface{}) { GetDefaultLog().Panicf(format, msg...) } 23 | func Fatalf(format string, msg ...interface{}) { GetDefaultLog().Fatalf(format, msg...) } 24 | 25 | func LogEntry(entry *Entry) { GetDefaultLog().LogEntry(entry) } 26 | 27 | func IsLevelEnabled(lvl Level) bool { return GetDefaultLog().IsLevelEnabled(lvl) } 28 | func IsTraceEnabled() bool { return GetDefaultLog().IsTraceEnabled() } 29 | func IsDebugEnabled() bool { return GetDefaultLog().IsDebugEnabled() } 30 | func IsInfoEnabled() bool { return GetDefaultLog().IsInfoEnabled() } 31 | func IsWarnEnabled() bool { return GetDefaultLog().IsWarnEnabled() } 32 | func IsErrorEnabled() bool { return GetDefaultLog().IsErrorEnabled() } 33 | func IsPanicEnabled() bool { return GetDefaultLog().IsPanicEnabled() } 34 | func IsFatalEnabled() bool { return GetDefaultLog().IsFatalEnabled() } 35 | -------------------------------------------------------------------------------- /vendor/gopkg.in/macaron.v1/logger.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Martini Authors 2 | // Copyright 2014 The Macaron Authors 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 5 | // not use this file except in compliance with the License. You may obtain 6 | // a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | // License for the specific language governing permissions and limitations 14 | // under the License. 15 | 16 | package macaron 17 | 18 | import ( 19 | "fmt" 20 | "log" 21 | "net/http" 22 | "runtime" 23 | "time" 24 | ) 25 | 26 | var ( 27 | ColorLog = true 28 | LogTimeFormat = "2006-01-02 15:04:05" 29 | ) 30 | 31 | func init() { 32 | ColorLog = runtime.GOOS != "windows" 33 | } 34 | 35 | // Logger returns a middleware handler that logs the request as it goes in and the response as it goes out. 36 | func Logger() Handler { 37 | return func(ctx *Context, log *log.Logger) { 38 | start := time.Now() 39 | 40 | log.Printf("%s: Started %s %s for %s", time.Now().Format(LogTimeFormat), ctx.Req.Method, ctx.Req.RequestURI, ctx.RemoteAddr()) 41 | 42 | rw := ctx.Resp.(ResponseWriter) 43 | ctx.Next() 44 | 45 | content := fmt.Sprintf("%s: Completed %s %v %s in %v", time.Now().Format(LogTimeFormat), ctx.Req.RequestURI, rw.Status(), http.StatusText(rw.Status()), time.Since(start)) 46 | if ColorLog { 47 | switch rw.Status() { 48 | case 200, 201, 202: 49 | content = fmt.Sprintf("\033[1;32m%s\033[0m", content) 50 | case 301, 302: 51 | content = fmt.Sprintf("\033[1;37m%s\033[0m", content) 52 | case 304: 53 | content = fmt.Sprintf("\033[1;33m%s\033[0m", content) 54 | case 401, 403: 55 | content = fmt.Sprintf("\033[4;31m%s\033[0m", content) 56 | case 404: 57 | content = fmt.Sprintf("\033[1;31m%s\033[0m", content) 58 | case 500: 59 | content = fmt.Sprintf("\033[1;36m%s\033[0m", content) 60 | } 61 | } 62 | log.Println(content) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_sql.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "bytes" 5 | "database/sql" 6 | _ "github.com/go-sql-driver/mysql" 7 | _ "github.com/lib/pq" 8 | "github.com/n0rad/go-erlog/errs" 9 | "github.com/n0rad/go-erlog/logs" 10 | "sync" 11 | "text/template" 12 | ) 13 | 14 | type CheckSql struct { 15 | CheckCommon 16 | Username string 17 | Password string 18 | Request string 19 | Datasource string 20 | Driver string 21 | 22 | templatedDatasource string 23 | } 24 | 25 | func NewCheckSql() *CheckSql { 26 | return &CheckSql{ 27 | CheckCommon: CheckCommon{Port: 3306}, 28 | Username: "root", 29 | Password: "", 30 | Request: "SELECT 1", 31 | Datasource: "{{.Username}}:{{.Password}}@tcp([{{.Host}}]:{{.Port}})/?timeout={{.TimeoutInMilli}}ms", 32 | Driver: "mysql", 33 | } 34 | } 35 | 36 | func (x *CheckSql) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 37 | x.CommonRun(x, statusChange, stop, doneWait) 38 | } 39 | 40 | func (x *CheckSql) Init(s *Service) error { 41 | if err := x.CheckCommon.CommonInit(s); err != nil { 42 | return err 43 | } 44 | 45 | switch x.Driver { 46 | case "mysql", "postgres": 47 | default: 48 | return errs.WithF(x.fields.WithField("driver", x.Driver), "Unsupported driver") 49 | } 50 | 51 | template, err := template.New("datasource").Parse(x.Datasource) 52 | if err != nil { 53 | return errs.WithEF(err, x.fields, "Failed to parse datasource template") 54 | } 55 | 56 | var buff bytes.Buffer 57 | if err := template.Execute(&buff, x); err != nil { 58 | return errs.WithEF(err, x.fields, "Datasource templating failed") 59 | } 60 | x.templatedDatasource = buff.String() 61 | logs.WithF(x.fields.WithField("datasource", x.templatedDatasource)).Debug("datasource templated") 62 | return nil 63 | } 64 | 65 | func (x *CheckSql) Check() error { 66 | conn, err := sql.Open(x.Driver, x.templatedDatasource) 67 | if err != nil { 68 | return errs.WithEF(err, x.fields, "Cannot open connection") 69 | } 70 | defer conn.Close() 71 | rows, err := conn.Query(x.Request) 72 | if err != nil { 73 | return errs.WithEF(err, x.fields, "Check query failed") 74 | } 75 | defer rows.Close() 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package terminal provides support functions for dealing with terminals, as 6 | // commonly found on UNIX systems. 7 | // 8 | // Putting a terminal into raw mode is the most common requirement: 9 | // 10 | // oldState, err := terminal.MakeRaw(0) 11 | // if err != nil { 12 | // panic(err) 13 | // } 14 | // defer terminal.Restore(0, oldState) 15 | package terminal 16 | 17 | import ( 18 | "fmt" 19 | "runtime" 20 | ) 21 | 22 | type State struct{} 23 | 24 | // IsTerminal returns true if the given file descriptor is a terminal. 25 | func IsTerminal(fd int) bool { 26 | return false 27 | } 28 | 29 | // MakeRaw put the terminal connected to the given file descriptor into raw 30 | // mode and returns the previous state of the terminal so that it can be 31 | // restored. 32 | func MakeRaw(fd int) (*State, error) { 33 | return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 34 | } 35 | 36 | // GetState returns the current state of a terminal which may be useful to 37 | // restore the terminal after a signal. 38 | func GetState(fd int) (*State, error) { 39 | return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 40 | } 41 | 42 | // Restore restores the terminal connected to the given file descriptor to a 43 | // previous state. 44 | func Restore(fd int, state *State) error { 45 | return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 46 | } 47 | 48 | // GetSize returns the dimensions of the given terminal. 49 | func GetSize(fd int) (width, height int, err error) { 50 | return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 51 | } 52 | 53 | // ReadPassword reads a line of input from a terminal without local echo. This 54 | // is commonly used for inputting passwords and other sensitive data. The slice 55 | // returned does not include the \n. 56 | func ReadPassword(fd int) ([]byte, error) { 57 | return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | // AppendStr appends string to slice with no duplicates. 22 | func AppendStr(strs []string, str string) []string { 23 | for _, s := range strs { 24 | if s == str { 25 | return strs 26 | } 27 | } 28 | return append(strs, str) 29 | } 30 | 31 | // CompareSliceStr compares two 'string' type slices. 32 | // It returns true if elements and order are both the same. 33 | func CompareSliceStr(s1, s2 []string) bool { 34 | if len(s1) != len(s2) { 35 | return false 36 | } 37 | 38 | for i := range s1 { 39 | if s1[i] != s2[i] { 40 | return false 41 | } 42 | } 43 | 44 | return true 45 | } 46 | 47 | // CompareSliceStr compares two 'string' type slices. 48 | // It returns true if elements are the same, and ignores the order. 49 | func CompareSliceStrU(s1, s2 []string) bool { 50 | if len(s1) != len(s2) { 51 | return false 52 | } 53 | 54 | for i := range s1 { 55 | for j := len(s2) - 1; j >= 0; j-- { 56 | if s1[i] == s2[j] { 57 | s2 = append(s2[:j], s2[j+1:]...) 58 | break 59 | } 60 | } 61 | } 62 | if len(s2) > 0 { 63 | return false 64 | } 65 | return true 66 | } 67 | 68 | // IsSliceContainsStr returns true if the string exists in given slice, ignore case. 69 | func IsSliceContainsStr(sl []string, str string) bool { 70 | str = strings.ToLower(str) 71 | for _, s := range sl { 72 | if strings.ToLower(s) == str { 73 | return true 74 | } 75 | } 76 | return false 77 | } 78 | 79 | // IsSliceContainsInt64 returns true if the int64 exists in given slice. 80 | func IsSliceContainsInt64(sl []int64, i int64) bool { 81 | for _, s := range sl { 82 | if s == i { 83 | return true 84 | } 85 | } 86 | return false 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/confirms.go: -------------------------------------------------------------------------------- 1 | package amqp 2 | 3 | import "sync" 4 | 5 | // confirms resequences and notifies one or multiple publisher confirmation listeners 6 | type confirms struct { 7 | m sync.Mutex 8 | listeners []chan Confirmation 9 | sequencer map[uint64]Confirmation 10 | published uint64 11 | expecting uint64 12 | } 13 | 14 | // newConfirms allocates a confirms 15 | func newConfirms() *confirms { 16 | return &confirms{ 17 | sequencer: map[uint64]Confirmation{}, 18 | published: 0, 19 | expecting: 1, 20 | } 21 | } 22 | 23 | func (c *confirms) Listen(l chan Confirmation) { 24 | c.m.Lock() 25 | defer c.m.Unlock() 26 | 27 | c.listeners = append(c.listeners, l) 28 | } 29 | 30 | // publish increments the publishing counter 31 | func (c *confirms) Publish() uint64 { 32 | c.m.Lock() 33 | defer c.m.Unlock() 34 | 35 | c.published++ 36 | return c.published 37 | } 38 | 39 | // confirm confirms one publishing, increments the expecting delivery tag, and 40 | // removes bookkeeping for that delivery tag. 41 | func (c *confirms) confirm(confirmation Confirmation) { 42 | delete(c.sequencer, c.expecting) 43 | c.expecting++ 44 | for _, l := range c.listeners { 45 | l <- confirmation 46 | } 47 | } 48 | 49 | // resequence confirms any out of order delivered confirmations 50 | func (c *confirms) resequence() { 51 | for c.expecting <= c.published { 52 | sequenced, found := c.sequencer[c.expecting] 53 | if !found { 54 | return 55 | } 56 | c.confirm(sequenced) 57 | } 58 | } 59 | 60 | // one confirms one publishing and all following in the publishing sequence 61 | func (c *confirms) One(confirmed Confirmation) { 62 | c.m.Lock() 63 | defer c.m.Unlock() 64 | 65 | if c.expecting == confirmed.DeliveryTag { 66 | c.confirm(confirmed) 67 | } else { 68 | c.sequencer[confirmed.DeliveryTag] = confirmed 69 | } 70 | c.resequence() 71 | } 72 | 73 | // multiple confirms all publishings up until the delivery tag 74 | func (c *confirms) Multiple(confirmed Confirmation) { 75 | c.m.Lock() 76 | defer c.m.Unlock() 77 | 78 | for c.expecting <= confirmed.DeliveryTag { 79 | c.confirm(Confirmation{c.expecting, confirmed.Ack}) 80 | } 81 | } 82 | 83 | // Close closes all listeners, discarding any out of sequence confirmations 84 | func (c *confirms) Close() error { 85 | c.m.Lock() 86 | defer c.m.Unlock() 87 | 88 | for _, l := range c.listeners { 89 | close(l) 90 | } 91 | c.listeners = nil 92 | return nil 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/Unknwon/com/path.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 com authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package com 16 | 17 | import ( 18 | "errors" 19 | "os" 20 | "path/filepath" 21 | "runtime" 22 | "strings" 23 | ) 24 | 25 | // GetGOPATHs returns all paths in GOPATH variable. 26 | func GetGOPATHs() []string { 27 | gopath := os.Getenv("GOPATH") 28 | var paths []string 29 | if runtime.GOOS == "windows" { 30 | gopath = strings.Replace(gopath, "\\", "/", -1) 31 | paths = strings.Split(gopath, ";") 32 | } else { 33 | paths = strings.Split(gopath, ":") 34 | } 35 | return paths 36 | } 37 | 38 | // GetSrcPath returns app. source code path. 39 | // It only works when you have src. folder in GOPATH, 40 | // it returns error not able to locate source folder path. 41 | func GetSrcPath(importPath string) (appPath string, err error) { 42 | paths := GetGOPATHs() 43 | for _, p := range paths { 44 | if IsExist(p + "/src/" + importPath + "/") { 45 | appPath = p + "/src/" + importPath + "/" 46 | break 47 | } 48 | } 49 | 50 | if len(appPath) == 0 { 51 | return "", errors.New("Unable to locate source folder path") 52 | } 53 | 54 | appPath = filepath.Dir(appPath) + "/" 55 | if runtime.GOOS == "windows" { 56 | // Replace all '\' to '/'. 57 | appPath = strings.Replace(appPath, "\\", "/", -1) 58 | } 59 | 60 | return appPath, nil 61 | } 62 | 63 | // HomeDir returns path of '~'(in Linux) on Windows, 64 | // it returns error when the variable does not exist. 65 | func HomeDir() (home string, err error) { 66 | if runtime.GOOS == "windows" { 67 | home = os.Getenv("USERPROFILE") 68 | if len(home) == 0 { 69 | home = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") 70 | } 71 | } else { 72 | home = os.Getenv("HOME") 73 | } 74 | 75 | if len(home) == 0 { 76 | return "", errors.New("Cannot specify home directory because it's empty") 77 | } 78 | 79 | return home, nil 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/rows.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | import ( 12 | "database/sql/driver" 13 | "io" 14 | ) 15 | 16 | type mysqlField struct { 17 | tableName string 18 | name string 19 | flags fieldFlag 20 | fieldType byte 21 | decimals byte 22 | } 23 | 24 | type mysqlRows struct { 25 | mc *mysqlConn 26 | columns []mysqlField 27 | } 28 | 29 | type binaryRows struct { 30 | mysqlRows 31 | } 32 | 33 | type textRows struct { 34 | mysqlRows 35 | } 36 | 37 | type emptyRows struct{} 38 | 39 | func (rows *mysqlRows) Columns() []string { 40 | columns := make([]string, len(rows.columns)) 41 | if rows.mc.cfg.columnsWithAlias { 42 | for i := range columns { 43 | columns[i] = rows.columns[i].tableName + "." + rows.columns[i].name 44 | } 45 | } else { 46 | for i := range columns { 47 | columns[i] = rows.columns[i].name 48 | } 49 | } 50 | return columns 51 | } 52 | 53 | func (rows *mysqlRows) Close() error { 54 | mc := rows.mc 55 | if mc == nil { 56 | return nil 57 | } 58 | if mc.netConn == nil { 59 | return ErrInvalidConn 60 | } 61 | 62 | // Remove unread packets from stream 63 | err := mc.readUntilEOF() 64 | rows.mc = nil 65 | return err 66 | } 67 | 68 | func (rows *binaryRows) Next(dest []driver.Value) error { 69 | if mc := rows.mc; mc != nil { 70 | if mc.netConn == nil { 71 | return ErrInvalidConn 72 | } 73 | 74 | // Fetch next row from stream 75 | return rows.readRow(dest) 76 | } 77 | return io.EOF 78 | } 79 | 80 | func (rows *textRows) Next(dest []driver.Value) error { 81 | if mc := rows.mc; mc != nil { 82 | if mc.netConn == nil { 83 | return ErrInvalidConn 84 | } 85 | 86 | // Fetch next row from stream 87 | return rows.readRow(dest) 88 | } 89 | return io.EOF 90 | } 91 | 92 | func (rows emptyRows) Columns() []string { 93 | return nil 94 | } 95 | 96 | func (rows emptyRows) Close() error { 97 | return nil 98 | } 99 | 100 | func (rows emptyRows) Next(dest []driver.Value) error { 101 | return io.EOF 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/logs/entry.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/data" 5 | ) 6 | 7 | type Entry struct { 8 | Logger Log 9 | Level Level 10 | Fields data.Fields 11 | Message string 12 | Err error 13 | } 14 | 15 | func WithError(err error) *Entry { 16 | return &Entry{ 17 | Logger: GetDefaultLog(), 18 | Err: err, 19 | } 20 | } 21 | 22 | func WithField(name string, value interface{}) *Entry { 23 | return &Entry{ 24 | Logger: GetDefaultLog(), 25 | Fields: data.WithField(name, value), 26 | } 27 | } 28 | 29 | func WithFields(fields data.Fields) *Entry { 30 | return &Entry{ 31 | Logger: GetDefaultLog(), 32 | Fields: fields, 33 | } 34 | } 35 | 36 | func WithEF(err error, fields data.Fields) *Entry { 37 | return &Entry{ 38 | Logger: GetDefaultLog(), 39 | Err: err, 40 | Fields: fields, 41 | } 42 | } 43 | 44 | func WithF(fields data.Fields) *Entry { 45 | return WithFields(fields) 46 | } 47 | 48 | func WithE(err error) *Entry { 49 | return WithError(err) 50 | } 51 | 52 | 53 | /////////////////////////////////// 54 | 55 | func (e *Entry) WithFields(data data.Fields) *Entry { 56 | e.Fields = data 57 | return e 58 | } 59 | 60 | func (e *Entry) WithField(name string, value interface{}) *Entry { 61 | if e.Fields == nil { 62 | e.Fields = data.WithField(name, value) 63 | } else { 64 | e.Fields = e.Fields.WithField(name, value) 65 | } 66 | return e 67 | } 68 | 69 | func (e *Entry) WithLog(logger Log) *Entry { 70 | e.Logger = logger 71 | return e 72 | } 73 | 74 | func (e *Entry) Trace(msg string) { 75 | e.Level = TRACE 76 | e.Message = msg 77 | e.Logger.LogEntry(e) 78 | } 79 | 80 | func (e *Entry) Debug(msg string) { 81 | e.Level = DEBUG 82 | e.Message = msg 83 | e.Logger.LogEntry(e) 84 | } 85 | 86 | func (e *Entry) Info(msg string) { 87 | e.Level = INFO 88 | e.Message = msg 89 | e.Logger.LogEntry(e) 90 | } 91 | 92 | func (e *Entry) Warn(msg string) { 93 | e.Level = WARN 94 | e.Message = msg 95 | e.Logger.LogEntry(e) 96 | } 97 | 98 | func (e *Entry) Error(msg string) { 99 | e.Level = ERROR 100 | e.Message = msg 101 | e.Logger.LogEntry(e) 102 | } 103 | 104 | func (e *Entry) Panic(msg string) { 105 | e.Level = PANIC 106 | e.Message = msg 107 | e.Logger.LogEntry(e) 108 | } 109 | 110 | func (e *Entry) Fatal(msg string) { 111 | e.Level = FATAL 112 | e.Message = msg 113 | e.Logger.LogEntry(e) 114 | } 115 | -------------------------------------------------------------------------------- /vendor/gopkg.in/macaron.v1/return_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Martini Authors 2 | // Copyright 2014 The Macaron Authors 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 5 | // not use this file except in compliance with the License. You may obtain 6 | // a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | // License for the specific language governing permissions and limitations 14 | // under the License. 15 | 16 | package macaron 17 | 18 | import ( 19 | "net/http" 20 | "reflect" 21 | 22 | "github.com/go-macaron/inject" 23 | ) 24 | 25 | // ReturnHandler is a service that Martini provides that is called 26 | // when a route handler returns something. The ReturnHandler is 27 | // responsible for writing to the ResponseWriter based on the values 28 | // that are passed into this function. 29 | type ReturnHandler func(*Context, []reflect.Value) 30 | 31 | func canDeref(val reflect.Value) bool { 32 | return val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr 33 | } 34 | 35 | func isError(val reflect.Value) bool { 36 | _, ok := val.Interface().(error) 37 | return ok 38 | } 39 | 40 | func isByteSlice(val reflect.Value) bool { 41 | return val.Kind() == reflect.Slice && val.Type().Elem().Kind() == reflect.Uint8 42 | } 43 | 44 | func defaultReturnHandler() ReturnHandler { 45 | return func(ctx *Context, vals []reflect.Value) { 46 | rv := ctx.GetVal(inject.InterfaceOf((*http.ResponseWriter)(nil))) 47 | resp := rv.Interface().(http.ResponseWriter) 48 | var respVal reflect.Value 49 | if len(vals) > 1 && vals[0].Kind() == reflect.Int { 50 | resp.WriteHeader(int(vals[0].Int())) 51 | respVal = vals[1] 52 | } else if len(vals) > 0 { 53 | respVal = vals[0] 54 | 55 | if isError(respVal) { 56 | err := respVal.Interface().(error) 57 | if err != nil { 58 | ctx.internalServerError(ctx, err) 59 | } 60 | return 61 | } else if canDeref(respVal) { 62 | if respVal.IsNil() { 63 | return // Ignore nil error 64 | } 65 | } 66 | } 67 | if canDeref(respVal) { 68 | respVal = respVal.Elem() 69 | } 70 | if isByteSlice(respVal) { 71 | resp.Write(respVal.Bytes()) 72 | } else { 73 | resp.Write([]byte(respVal.String())) 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/samuel/go-zookeeper/zk/dnshostprovider.go: -------------------------------------------------------------------------------- 1 | package zk 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "sync" 7 | ) 8 | 9 | // DNSHostProvider is the default HostProvider. It currently matches 10 | // the Java StaticHostProvider, resolving hosts from DNS once during 11 | // the call to Init. It could be easily extended to re-query DNS 12 | // periodically or if there is trouble connecting. 13 | type DNSHostProvider struct { 14 | mu sync.Mutex // Protects everything, so we can add asynchronous updates later. 15 | servers []string 16 | curr int 17 | last int 18 | lookupHost func(string) ([]string, error) // Override of net.LookupHost, for testing. 19 | } 20 | 21 | // Init is called first, with the servers specified in the connection 22 | // string. It uses DNS to look up addresses for each server, then 23 | // shuffles them all together. 24 | func (hp *DNSHostProvider) Init(servers []string) error { 25 | hp.mu.Lock() 26 | defer hp.mu.Unlock() 27 | 28 | lookupHost := hp.lookupHost 29 | if lookupHost == nil { 30 | lookupHost = net.LookupHost 31 | } 32 | 33 | found := []string{} 34 | for _, server := range servers { 35 | host, port, err := net.SplitHostPort(server) 36 | if err != nil { 37 | return err 38 | } 39 | addrs, err := lookupHost(host) 40 | if err != nil { 41 | return err 42 | } 43 | for _, addr := range addrs { 44 | found = append(found, net.JoinHostPort(addr, port)) 45 | } 46 | } 47 | 48 | if len(found) == 0 { 49 | return fmt.Errorf("No hosts found for addresses %q", servers) 50 | } 51 | 52 | // Randomize the order of the servers to avoid creating hotspots 53 | stringShuffle(found) 54 | 55 | hp.servers = found 56 | hp.curr = -1 57 | hp.last = -1 58 | 59 | return nil 60 | } 61 | 62 | func (hp *DNSHostProvider) Len() int { 63 | hp.mu.Lock() 64 | defer hp.mu.Unlock() 65 | return len(hp.servers) 66 | } 67 | 68 | // Next returns the next server to connect to. retryStart will be true 69 | // if we've looped through all known servers without Connected() being 70 | // called. 71 | func (hp *DNSHostProvider) Next() (server string, retryStart bool) { 72 | hp.mu.Lock() 73 | defer hp.mu.Unlock() 74 | hp.curr = (hp.curr + 1) % len(hp.servers) 75 | retryStart = hp.curr == hp.last 76 | if hp.last == -1 { 77 | hp.last = 0 78 | } 79 | return hp.servers[hp.curr], retryStart 80 | } 81 | 82 | // Notify the HostProvider of a successful connection. 83 | func (hp *DNSHostProvider) Connected() { 84 | hp.mu.Lock() 85 | defer hp.mu.Unlock() 86 | hp.last = hp.curr 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/utils.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "bytes" 5 | "github.com/n0rad/go-erlog/data" 6 | "github.com/n0rad/go-erlog/errs" 7 | "github.com/n0rad/go-erlog/logs" 8 | "net" 9 | "os/exec" 10 | "strings" 11 | "time" 12 | ) 13 | 14 | func IpLookupNoError(host string, preferIPv4 bool) net.IP { 15 | ip, err := IpLookup(host, preferIPv4) 16 | if err != nil { 17 | logs.WithE(err).WithField("host", host).Error("Host lookup failed, assume localhost can replace it") 18 | ip = net.IPv4(127, 0, 0, 1) 19 | } 20 | return ip 21 | } 22 | 23 | func IpLookup(host string, preferIPv4 bool) (net.IP, error) { 24 | ips, err := net.LookupIP(host) 25 | if err != nil || len(ips) == 0 || len(ips[0]) == 0 || len(ips[0]) != net.IPv6len { 26 | return []byte{}, errs.WithEF(err, data.WithField("host", host), "Lookup failed or empty lookup result") 27 | } 28 | 29 | return processIPs(preferIPv4, ips) 30 | } 31 | 32 | func processIPs(preferIpv4 bool, ips []net.IP) (net.IP, error) { 33 | res := ips[0] 34 | for _, addr := range ips { 35 | if preferIpv4 && addr.To4() != nil { 36 | res = addr 37 | break 38 | } 39 | } 40 | return res, nil 41 | } 42 | 43 | func max(val1 int, val2 int) int { 44 | if val1 > val2 { 45 | return val1 46 | } 47 | return val2 48 | } 49 | 50 | func ExecCommand(cmd []string, timeoutInMilli int) error { 51 | return ExecCommandFull(cmd, []string{}, timeoutInMilli) 52 | } 53 | 54 | func ExecCommandFull(cmd []string, env []string, timeoutInMilli int) error { 55 | command := exec.Command(cmd[0], cmd[1:]...) 56 | var b bytes.Buffer 57 | command.Stdout = &b 58 | command.Stderr = &b 59 | command.Env = env 60 | 61 | if err := command.Start(); err != nil { 62 | return errs.WithEF(err, data.WithField("cmd", cmd), "Failed to start command") 63 | } 64 | 65 | var after *errs.EntryError 66 | timer := time.AfterFunc(time.Duration(timeoutInMilli)*time.Millisecond, func() { 67 | data := data.WithField("command", strings.Join(cmd, " ")).WithField("timeout", timeoutInMilli) 68 | logs.WithF(data).Debug("Command timeout") 69 | after = errs.WithF(data, "Exec command timeout") 70 | command.Process.Kill() 71 | }) 72 | 73 | err := command.Wait() 74 | timer.Stop() 75 | if logs.IsTraceEnabled() { 76 | logs.WithField("cmd", cmd).WithField("output", string(b.Bytes())).Trace("Command output") 77 | } 78 | if err != nil { 79 | return errs.WithEF(err, data.WithField("cmd", cmd). 80 | WithField("output", string(b.Bytes())), "Command failed"). 81 | WithErr(after) 82 | } 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/n0rad/go-erlog/logs/dummy.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | type DummyLog struct { 11 | Out io.Writer 12 | } 13 | 14 | func (d *DummyLog) GetLog(name string) Log { return d } 15 | 16 | func (d *DummyLog) Tracef(format string, msg ...interface{}) { 17 | d.log(TRACE, fmt.Sprintf(format, msg...)) 18 | } 19 | func (d *DummyLog) Debugf(format string, msg ...interface{}) { 20 | d.log(DEBUG, fmt.Sprintf(format, msg...)) 21 | } 22 | func (d *DummyLog) Infof(format string, msg ...interface{}) { 23 | d.log(INFO, fmt.Sprintf(format, msg...)) 24 | } 25 | func (d *DummyLog) Warnf(format string, msg ...interface{}) { 26 | d.log(WARN, fmt.Sprintf(format, msg...)) 27 | } 28 | func (d *DummyLog) Errorf(format string, msg ...interface{}) { 29 | d.log(ERROR, fmt.Sprintf(format, msg...)) 30 | } 31 | func (d *DummyLog) Panicf(format string, msg ...interface{}) { 32 | d.log(PANIC, fmt.Sprintf(format, msg...)) 33 | } 34 | func (d *DummyLog) Fatalf(format string, msg ...interface{}) { 35 | d.log(FATAL, fmt.Sprintf(format, msg...)) 36 | } 37 | 38 | func (d *DummyLog) Trace(msg ...string) { d.log(TRACE, msg...) } 39 | func (d *DummyLog) Debug(msg ...string) { d.log(DEBUG, msg...) } 40 | func (d *DummyLog) Info(msg ...string) { d.log(INFO, msg...) } 41 | func (d *DummyLog) Warn(msg ...string) { d.log(WARN, msg...) } 42 | func (d *DummyLog) Error(msg ...string) { d.log(ERROR, msg...) } 43 | func (d *DummyLog) Panic(msg ...string) { d.log(PANIC, msg...); panic(msg) } 44 | func (d *DummyLog) Fatal(msg ...string) { d.log(FATAL, msg...); os.Exit(1) } 45 | func (d *DummyLog) log(level Level, msg ...string) { 46 | d.LogEntry(&Entry{Level: level, Message: strings.Join(msg, " ")}) 47 | } 48 | func (d *DummyLog) LogEntry(entry *Entry) { fmt.Fprintf(d.Out, "%s: %s\n", entry.Level, entry.Message) } 49 | func (d *DummyLog) GetLevel() Level { return TRACE } 50 | func (d *DummyLog) SetLevel(lvl Level) { d.Error("Dummy log cannot set level") } 51 | func (d *DummyLog) IsLevelEnabled(lvl Level) bool { return true } 52 | func (d *DummyLog) IsTraceEnabled() bool { return true } 53 | func (d *DummyLog) IsDebugEnabled() bool { return true } 54 | func (d *DummyLog) IsInfoEnabled() bool { return true } 55 | func (d *DummyLog) IsWarnEnabled() bool { return true } 56 | func (d *DummyLog) IsErrorEnabled() bool { return true } 57 | func (d *DummyLog) IsPanicEnabled() bool { return true } 58 | func (d *DummyLog) IsFatalEnabled() bool { return true } 59 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/return.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Sean Treadway, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | // Source code and contact info at http://github.com/streadway/amqp 5 | 6 | package amqp 7 | 8 | import ( 9 | "time" 10 | ) 11 | 12 | // Return captures a flattened struct of fields returned by the server when a 13 | // Publishing is unable to be delivered either due to the `mandatory` flag set 14 | // and no route found, or `immediate` flag set and no free consumer. 15 | type Return struct { 16 | ReplyCode uint16 // reason 17 | ReplyText string // description 18 | Exchange string // basic.publish exchange 19 | RoutingKey string // basic.publish routing key 20 | 21 | // Properties 22 | ContentType string // MIME content type 23 | ContentEncoding string // MIME content encoding 24 | Headers Table // Application or header exchange table 25 | DeliveryMode uint8 // queue implemention use - non-persistent (1) or persistent (2) 26 | Priority uint8 // queue implementation use - 0 to 9 27 | CorrelationId string // application use - correlation identifier 28 | ReplyTo string // application use - address to to reply to (ex: RPC) 29 | Expiration string // implementation use - message expiration spec 30 | MessageId string // application use - message identifier 31 | Timestamp time.Time // application use - message timestamp 32 | Type string // application use - message type name 33 | UserId string // application use - creating user id 34 | AppId string // application use - creating application 35 | 36 | Body []byte 37 | } 38 | 39 | func newReturn(msg basicReturn) *Return { 40 | props, body := msg.getContent() 41 | 42 | return &Return{ 43 | ReplyCode: msg.ReplyCode, 44 | ReplyText: msg.ReplyText, 45 | Exchange: msg.Exchange, 46 | RoutingKey: msg.RoutingKey, 47 | 48 | Headers: props.Headers, 49 | ContentType: props.ContentType, 50 | ContentEncoding: props.ContentEncoding, 51 | DeliveryMode: props.DeliveryMode, 52 | Priority: props.Priority, 53 | CorrelationId: props.CorrelationId, 54 | ReplyTo: props.ReplyTo, 55 | Expiration: props.Expiration, 56 | MessageId: props.MessageId, 57 | Timestamp: props.Timestamp, 58 | Type: props.Type, 59 | UserId: props.UserId, 60 | AppId: props.AppId, 61 | 62 | Body: body, 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/README.txt: -------------------------------------------------------------------------------- 1 | PACKAGE 2 | 3 | package goautoneg 4 | import "bitbucket.org/ww/goautoneg" 5 | 6 | HTTP Content-Type Autonegotiation. 7 | 8 | The functions in this package implement the behaviour specified in 9 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 10 | 11 | Copyright (c) 2011, Open Knowledge Foundation Ltd. 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in 23 | the documentation and/or other materials provided with the 24 | distribution. 25 | 26 | Neither the name of the Open Knowledge Foundation Ltd. nor the 27 | names of its contributors may be used to endorse or promote 28 | products derived from this software without specific prior written 29 | permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | 43 | 44 | FUNCTIONS 45 | 46 | func Negotiate(header string, alternatives []string) (content_type string) 47 | Negotiate the most appropriate content_type given the accept header 48 | and a list of alternatives. 49 | 50 | func ParseAccept(header string) (accept []Accept) 51 | Parse an Accept Header string returning a sorted list 52 | of clauses 53 | 54 | 55 | TYPES 56 | 57 | type Accept struct { 58 | Type, SubType string 59 | Q float32 60 | Params map[string]string 61 | } 62 | Structure to represent a clause in an HTTP Accept Header 63 | 64 | 65 | SUBDIRECTORIES 66 | 67 | .hg 68 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/md_docs.md: -------------------------------------------------------------------------------- 1 | # Generating Markdown Docs For Your Own cobra.Command 2 | 3 | ## Generate markdown docs for the entire command tree 4 | 5 | This program can actually generate docs for the kubectl command in the kubernetes project 6 | 7 | ```go 8 | package main 9 | 10 | import ( 11 | "io/ioutil" 12 | "os" 13 | 14 | "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd" 15 | "github.com/spf13/cobra" 16 | ) 17 | 18 | func main() { 19 | kubectl := cmd.NewFactory(nil).NewKubectlCommand(os.Stdin, ioutil.Discard, ioutil.Discard) 20 | cobra.GenMarkdownTree(kubectl, "./") 21 | } 22 | ``` 23 | 24 | This will generate a whole series of files, one for each command in the tree, in the directory specified (in this case "./") 25 | 26 | ## Generate markdown docs for a single command 27 | 28 | You may wish to have more control over the output, or only generate for a single command, instead of the entire command tree. If this is the case you may prefer to `GenMarkdown` instead of `GenMarkdownTree` 29 | 30 | ```go 31 | out := new(bytes.Buffer) 32 | cobra.GenMarkdown(cmd, out) 33 | ``` 34 | 35 | This will write the markdown doc for ONLY "cmd" into the out, buffer. 36 | 37 | ## Customize the output 38 | 39 | Both `GenMarkdown` and `GenMarkdownTree` have alternate versions with callbacks to get some control of the output: 40 | 41 | ```go 42 | func GenMarkdownTreeCustom(cmd *Command, dir string, filePrepender func(string) string, linkHandler func(string) string) { 43 | //... 44 | } 45 | ``` 46 | 47 | ```go 48 | func GenMarkdownCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) string) { 49 | //... 50 | } 51 | ``` 52 | 53 | The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): 54 | 55 | ```go 56 | const fmTemplate = `--- 57 | date: %s 58 | title: "%s" 59 | slug: %s 60 | url: %s 61 | --- 62 | ` 63 | 64 | filePrepender := func(filename string) string { 65 | now := time.Now().Format(time.RFC3339) 66 | name := filepath.Base(filename) 67 | base := strings.TrimSuffix(name, path.Ext(name)) 68 | url := "/commands/" + strings.ToLower(base) + "/" 69 | return fmt.Sprintf(fmTemplate, now, strings.Replace(base, "_", " ", -1), base, url) 70 | } 71 | ``` 72 | 73 | The `linkHandler` can be used to customize the rendered internal links to the commands, given a filename: 74 | 75 | ```go 76 | linkHandler := func(name string) string { 77 | base := strings.TrimSuffix(name, path.Ext(name)) 78 | return "/commands/" + strings.ToLower(base) + "/" 79 | } 80 | ``` 81 | 82 | -------------------------------------------------------------------------------- /vendor/github.com/ghodss/yaml/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sam Ghods 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 | 24 | Copyright (c) 2012 The Go Authors. All rights reserved. 25 | 26 | Redistribution and use in source and binary forms, with or without 27 | modification, are permitted provided that the following conditions are 28 | met: 29 | 30 | * Redistributions of source code must retain the above copyright 31 | notice, this list of conditions and the following disclaimer. 32 | * Redistributions in binary form must reproduce the above 33 | copyright notice, this list of conditions and the following disclaimer 34 | in the documentation and/or other materials provided with the 35 | distribution. 36 | * Neither the name of Google Inc. nor the names of its 37 | contributors may be used to endorse or promote products derived from 38 | this software without specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/allocator.go: -------------------------------------------------------------------------------- 1 | package amqp 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "math/big" 7 | ) 8 | 9 | const ( 10 | free = 0 11 | allocated = 1 12 | ) 13 | 14 | // allocator maintains a bitset of allocated numbers. 15 | type allocator struct { 16 | pool *big.Int 17 | last int 18 | low int 19 | high int 20 | } 21 | 22 | // NewAllocator reserves and frees integers out of a range between low and 23 | // high. 24 | // 25 | // O(N) worst case space used, where N is maximum allocated, divided by 26 | // sizeof(big.Word) 27 | func newAllocator(low, high int) *allocator { 28 | return &allocator{ 29 | pool: big.NewInt(0), 30 | last: low, 31 | low: low, 32 | high: high, 33 | } 34 | } 35 | 36 | // String returns a string describing the contents of the allocator like 37 | // "allocator[low..high] reserved..until" 38 | // 39 | // O(N) where N is high-low 40 | func (a allocator) String() string { 41 | b := &bytes.Buffer{} 42 | fmt.Fprintf(b, "allocator[%d..%d]", a.low, a.high) 43 | 44 | for low := a.low; low <= a.high; low++ { 45 | high := low 46 | for a.reserved(high) && high <= a.high { 47 | high++ 48 | } 49 | 50 | if high > low+1 { 51 | fmt.Fprintf(b, " %d..%d", low, high-1) 52 | } else if high > low { 53 | fmt.Fprintf(b, " %d", high-1) 54 | } 55 | 56 | low = high 57 | } 58 | return b.String() 59 | } 60 | 61 | // Next reserves and returns the next available number out of the range between 62 | // low and high. If no number is available, false is returned. 63 | // 64 | // O(N) worst case runtime where N is allocated, but usually O(1) due to a 65 | // rolling index into the oldest allocation. 66 | func (a *allocator) next() (int, bool) { 67 | wrapped := a.last 68 | 69 | // Find trailing bit 70 | for ; a.last <= a.high; a.last++ { 71 | if a.reserve(a.last) { 72 | return a.last, true 73 | } 74 | } 75 | 76 | // Find preceeding free'd pool 77 | a.last = a.low 78 | 79 | for ; a.last < wrapped; a.last++ { 80 | if a.reserve(a.last) { 81 | return a.last, true 82 | } 83 | } 84 | 85 | return 0, false 86 | } 87 | 88 | // reserve claims the bit if it is not already claimed, returning true if 89 | // succesfully claimed. 90 | func (a *allocator) reserve(n int) bool { 91 | if a.reserved(n) { 92 | return false 93 | } 94 | a.pool.SetBit(a.pool, n-a.low, allocated) 95 | return true 96 | } 97 | 98 | // reserved returns true if the integer has been allocated 99 | func (a *allocator) reserved(n int) bool { 100 | return a.pool.Bit(n-a.low) == allocated 101 | } 102 | 103 | // release frees the use of the number for another allocation 104 | func (a *allocator) release(n int) { 105 | a.pool.SetBit(a.pool, n-a.low, free) 106 | } 107 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | // If the output encoding is UTF-8, we don't need to recode the buffer. 22 | if emitter.encoding == yaml_UTF8_ENCODING { 23 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 24 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 25 | } 26 | emitter.buffer_pos = 0 27 | return true 28 | } 29 | 30 | // Recode the buffer into the raw buffer. 31 | var low, high int 32 | if emitter.encoding == yaml_UTF16LE_ENCODING { 33 | low, high = 0, 1 34 | } else { 35 | high, low = 1, 0 36 | } 37 | 38 | pos := 0 39 | for pos < emitter.buffer_pos { 40 | // See the "reader.c" code for more details on UTF-8 encoding. Note 41 | // that we assume that the buffer contains a valid UTF-8 sequence. 42 | 43 | // Read the next UTF-8 character. 44 | octet := emitter.buffer[pos] 45 | 46 | var w int 47 | var value rune 48 | switch { 49 | case octet&0x80 == 0x00: 50 | w, value = 1, rune(octet&0x7F) 51 | case octet&0xE0 == 0xC0: 52 | w, value = 2, rune(octet&0x1F) 53 | case octet&0xF0 == 0xE0: 54 | w, value = 3, rune(octet&0x0F) 55 | case octet&0xF8 == 0xF0: 56 | w, value = 4, rune(octet&0x07) 57 | } 58 | for k := 1; k < w; k++ { 59 | octet = emitter.buffer[pos+k] 60 | value = (value << 6) + (rune(octet) & 0x3F) 61 | } 62 | pos += w 63 | 64 | // Write the character. 65 | if value < 0x10000 { 66 | var b [2]byte 67 | b[high] = byte(value >> 8) 68 | b[low] = byte(value & 0xFF) 69 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1]) 70 | } else { 71 | // Write the character using a surrogate pair (check "reader.c"). 72 | var b [4]byte 73 | value -= 0x10000 74 | b[high] = byte(0xD8 + (value >> 18)) 75 | b[low] = byte((value >> 10) & 0xFF) 76 | b[high+2] = byte(0xDC + ((value >> 8) & 0xFF)) 77 | b[low+2] = byte(value & 0xFF) 78 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1], b[2], b[3]) 79 | } 80 | } 81 | 82 | // Write the raw buffer. 83 | if err := emitter.write_handler(emitter, emitter.raw_buffer); err != nil { 84 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 85 | } 86 | emitter.buffer_pos = 0 87 | emitter.raw_buffer = emitter.raw_buffer[:0] 88 | return true 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_amqp.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "bytes" 5 | "github.com/n0rad/go-erlog/errs" 6 | "github.com/n0rad/go-erlog/logs" 7 | "github.com/streadway/amqp" 8 | "sync" 9 | "text/template" 10 | ) 11 | 12 | const checkMessage = "nerve" 13 | 14 | type CheckAmqp struct { 15 | CheckCommon 16 | Datasource string 17 | Vhost string 18 | Queue string 19 | Username string 20 | Password string 21 | 22 | templatedDatasource string 23 | } 24 | 25 | func NewCheckAmqp() *CheckAmqp { 26 | return &CheckAmqp{ 27 | Datasource: "amqp://{{.Username}}:{{.Password}}@{{.Host}}:{{.Port}}/{{.Vhost}}", 28 | Queue: "nerve", 29 | } 30 | } 31 | 32 | func (x *CheckAmqp) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 33 | x.CommonRun(x, statusChange, stop, doneWait) 34 | } 35 | 36 | func (x *CheckAmqp) Init(s *Service) error { 37 | if err := x.CheckCommon.CommonInit(s); err != nil { 38 | return err 39 | } 40 | 41 | template, err := template.New("datasource").Parse(x.Datasource) 42 | if err != nil { 43 | return errs.WithEF(err, x.fields, "Failed to parse datasource template") 44 | } 45 | 46 | var buff bytes.Buffer 47 | if err := template.Execute(&buff, x); err != nil { 48 | return errs.WithEF(err, x.fields, "Datasource templating failed") 49 | } 50 | x.templatedDatasource = buff.String() 51 | logs.WithF(x.fields.WithField("datasource", x.templatedDatasource)).Debug("datasource templated") 52 | return nil 53 | } 54 | 55 | func (x *CheckAmqp) Check() error { 56 | conn, err := amqp.Dial(x.templatedDatasource) 57 | if err != nil { 58 | return errs.WithEF(err, x.fields, "Unable to connect to amqp server") 59 | } 60 | defer conn.Close() 61 | 62 | channel, err := conn.Channel() 63 | if err != nil { 64 | return errs.WithEF(err, x.fields, "Unable to open channel") 65 | } 66 | defer channel.Close() 67 | 68 | if x.Queue == "" { 69 | return nil 70 | } 71 | 72 | queue, err := channel.QueueDeclare(x.Queue, false, false, false, false, nil) 73 | if err != nil { 74 | return errs.WithEF(err, x.fields, "Unable to declare queue") 75 | } 76 | 77 | if err := channel.Publish("", queue.Name, true, false, amqp.Publishing{ 78 | ContentType: "text/plain", 79 | Body: []byte(checkMessage), 80 | }); err != nil { 81 | return errs.WithEF(err, x.fields, "Failed to publish message") 82 | } 83 | delivery, ok, err := channel.Get(queue.Name, true) 84 | if !ok || err != nil { 85 | msg := "Failed to get test message" 86 | if err == nil { 87 | msg += ". No message in queue" 88 | } 89 | return errs.WithEF(err, x.fields, msg) 90 | } 91 | if delivery.Body == nil || string(delivery.Body) != checkMessage { 92 | return errs.WithEF(err, x.fields.WithField("received", delivery.Body), "Body received do not match sent") 93 | } 94 | delivery.Ack(false) 95 | return nil 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/streadway/amqp/consumers.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, Sean Treadway, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | // Source code and contact info at http://github.com/streadway/amqp 5 | 6 | package amqp 7 | 8 | import ( 9 | "fmt" 10 | "os" 11 | "sync" 12 | "sync/atomic" 13 | ) 14 | 15 | var consumerSeq uint64 16 | 17 | func uniqueConsumerTag() string { 18 | return fmt.Sprintf("ctag-%s-%d", os.Args[0], atomic.AddUint64(&consumerSeq, 1)) 19 | } 20 | 21 | type consumerBuffers map[string]chan *Delivery 22 | 23 | // Concurrent type that manages the consumerTag -> 24 | // ingress consumerBuffer mapping 25 | type consumers struct { 26 | sync.Mutex 27 | chans consumerBuffers 28 | } 29 | 30 | func makeConsumers() *consumers { 31 | return &consumers{chans: make(consumerBuffers)} 32 | } 33 | 34 | func bufferDeliveries(in chan *Delivery, out chan Delivery) { 35 | var queue []*Delivery 36 | var queueIn = in 37 | 38 | for delivery := range in { 39 | select { 40 | case out <- *delivery: 41 | // delivered immediately while the consumer chan can receive 42 | default: 43 | queue = append(queue, delivery) 44 | } 45 | 46 | for len(queue) > 0 { 47 | select { 48 | case out <- *queue[0]: 49 | queue = queue[1:] 50 | case delivery, open := <-queueIn: 51 | if open { 52 | queue = append(queue, delivery) 53 | } else { 54 | // stop receiving to drain the queue 55 | queueIn = nil 56 | } 57 | } 58 | } 59 | } 60 | 61 | close(out) 62 | } 63 | 64 | // On key conflict, close the previous channel. 65 | func (me *consumers) add(tag string, consumer chan Delivery) { 66 | me.Lock() 67 | defer me.Unlock() 68 | 69 | if prev, found := me.chans[tag]; found { 70 | close(prev) 71 | } 72 | 73 | in := make(chan *Delivery) 74 | go bufferDeliveries(in, consumer) 75 | 76 | me.chans[tag] = in 77 | } 78 | 79 | func (me *consumers) close(tag string) (found bool) { 80 | me.Lock() 81 | defer me.Unlock() 82 | 83 | ch, found := me.chans[tag] 84 | 85 | if found { 86 | delete(me.chans, tag) 87 | close(ch) 88 | } 89 | 90 | return found 91 | } 92 | 93 | func (me *consumers) closeAll() { 94 | me.Lock() 95 | defer me.Unlock() 96 | 97 | for _, ch := range me.chans { 98 | close(ch) 99 | } 100 | 101 | me.chans = make(consumerBuffers) 102 | } 103 | 104 | // Sends a delivery to a the consumer identified by `tag`. 105 | // If unbuffered channels are used for Consume this method 106 | // could block all deliveries until the consumer 107 | // receives on the other end of the channel. 108 | func (me *consumers) send(tag string, msg *Delivery) bool { 109 | me.Lock() 110 | defer me.Unlock() 111 | 112 | buffer, found := me.chans[tag] 113 | if found { 114 | buffer <- msg 115 | } 116 | 117 | return found 118 | } 119 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package expfmt 15 | 16 | import ( 17 | "fmt" 18 | "io" 19 | "net/http" 20 | 21 | "github.com/golang/protobuf/proto" 22 | "github.com/matttproud/golang_protobuf_extensions/pbutil" 23 | "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg" 24 | 25 | dto "github.com/prometheus/client_model/go" 26 | ) 27 | 28 | // Encoder types encode metric families into an underlying wire protocol. 29 | type Encoder interface { 30 | Encode(*dto.MetricFamily) error 31 | } 32 | 33 | type encoder func(*dto.MetricFamily) error 34 | 35 | func (e encoder) Encode(v *dto.MetricFamily) error { 36 | return e(v) 37 | } 38 | 39 | // Negotiate returns the Content-Type based on the given Accept header. 40 | // If no appropriate accepted type is found, FmtText is returned. 41 | func Negotiate(h http.Header) Format { 42 | for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) { 43 | // Check for protocol buffer 44 | if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol { 45 | switch ac.Params["encoding"] { 46 | case "delimited": 47 | return FmtProtoDelim 48 | case "text": 49 | return FmtProtoText 50 | case "compact-text": 51 | return FmtProtoCompact 52 | } 53 | } 54 | // Check for text format. 55 | ver := ac.Params["version"] 56 | if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") { 57 | return FmtText 58 | } 59 | } 60 | return FmtText 61 | } 62 | 63 | // NewEncoder returns a new encoder based on content type negotiation. 64 | func NewEncoder(w io.Writer, format Format) Encoder { 65 | switch format { 66 | case FmtProtoDelim: 67 | return encoder(func(v *dto.MetricFamily) error { 68 | _, err := pbutil.WriteDelimited(w, v) 69 | return err 70 | }) 71 | case FmtProtoCompact: 72 | return encoder(func(v *dto.MetricFamily) error { 73 | _, err := fmt.Fprintln(w, v.String()) 74 | return err 75 | }) 76 | case FmtProtoText: 77 | return encoder(func(v *dto.MetricFamily) error { 78 | _, err := fmt.Fprintln(w, proto.MarshalTextString(v)) 79 | return err 80 | }) 81 | case FmtText: 82 | return encoder(func(v *dto.MetricFamily) error { 83 | _, err := MetricFamilyToText(w, v) 84 | return err 85 | }) 86 | } 87 | panic("expfmt.NewEncoder: unknown format") 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/metric.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "regexp" 19 | "sort" 20 | "strings" 21 | ) 22 | 23 | var ( 24 | separator = []byte{0} 25 | MetricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`) 26 | ) 27 | 28 | // A Metric is similar to a LabelSet, but the key difference is that a Metric is 29 | // a singleton and refers to one and only one stream of samples. 30 | type Metric LabelSet 31 | 32 | // Equal compares the metrics. 33 | func (m Metric) Equal(o Metric) bool { 34 | return LabelSet(m).Equal(LabelSet(o)) 35 | } 36 | 37 | // Before compares the metrics' underlying label sets. 38 | func (m Metric) Before(o Metric) bool { 39 | return LabelSet(m).Before(LabelSet(o)) 40 | } 41 | 42 | // Clone returns a copy of the Metric. 43 | func (m Metric) Clone() Metric { 44 | clone := Metric{} 45 | for k, v := range m { 46 | clone[k] = v 47 | } 48 | return clone 49 | } 50 | 51 | func (m Metric) String() string { 52 | metricName, hasName := m[MetricNameLabel] 53 | numLabels := len(m) - 1 54 | if !hasName { 55 | numLabels = len(m) 56 | } 57 | labelStrings := make([]string, 0, numLabels) 58 | for label, value := range m { 59 | if label != MetricNameLabel { 60 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 61 | } 62 | } 63 | 64 | switch numLabels { 65 | case 0: 66 | if hasName { 67 | return string(metricName) 68 | } 69 | return "{}" 70 | default: 71 | sort.Strings(labelStrings) 72 | return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", ")) 73 | } 74 | } 75 | 76 | // Fingerprint returns a Metric's Fingerprint. 77 | func (m Metric) Fingerprint() Fingerprint { 78 | return LabelSet(m).Fingerprint() 79 | } 80 | 81 | // FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing 82 | // algorithm, which is, however, more susceptible to hash collisions. 83 | func (m Metric) FastFingerprint() Fingerprint { 84 | return LabelSet(m).FastFingerprint() 85 | } 86 | 87 | // IsValidMetricName returns true iff name matches the pattern of MetricNameRE. 88 | func IsValidMetricName(n LabelValue) bool { 89 | if len(n) == 0 { 90 | return false 91 | } 92 | for i, b := range n { 93 | if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) { 94 | return false 95 | } 96 | } 97 | return true 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/bcicen/go-haproxy/kvcodec/unmarshal.go: -------------------------------------------------------------------------------- 1 | package kvcodec 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io" 7 | "reflect" 8 | "regexp" 9 | "strings" 10 | "sync" 11 | ) 12 | 13 | const ( 14 | tagLabel = "kv" 15 | kvDelim = ":" 16 | ) 17 | 18 | type structFields map[string]fieldMeta 19 | 20 | type fieldMeta struct { 21 | Key string 22 | Name string 23 | OmitAlways bool 24 | OmitEmpty bool 25 | } 26 | 27 | func newfieldMeta(field reflect.StructField) (meta fieldMeta) { 28 | meta = fieldMeta{ 29 | Name: field.Name, 30 | } 31 | fieldTags := strings.Split(field.Tag.Get(tagLabel), ",") 32 | for _, tag := range fieldTags { 33 | if tag == "-" { 34 | meta.OmitAlways = true 35 | return meta 36 | } 37 | if tag == "omitempty" { 38 | meta.OmitEmpty = true 39 | } else if tag != "" { 40 | meta.Key = tag 41 | } else { 42 | meta.Key = field.Name 43 | } 44 | } 45 | return meta 46 | } 47 | 48 | var err error 49 | var structMap = make(map[reflect.Type]structFields) 50 | var structMapMutex sync.RWMutex 51 | 52 | func getStructFields(rType reflect.Type) (structFields, error) { 53 | structMapMutex.RLock() 54 | stInfo, ok := structMap[rType] 55 | if !ok { 56 | stInfo, err = newStructFields(rType) 57 | if err != nil { 58 | return nil, err 59 | } 60 | structMap[rType] = stInfo 61 | } 62 | structMapMutex.RUnlock() 63 | return stInfo, nil 64 | } 65 | 66 | func newStructFields(rType reflect.Type) (structFields, error) { 67 | fieldsCount := rType.NumField() 68 | fieldMap := make(structFields) 69 | 70 | for i := 0; i < fieldsCount; i++ { 71 | field := rType.Field(i) 72 | meta := newfieldMeta(field) 73 | 74 | if field.PkgPath != "" { 75 | continue 76 | } 77 | 78 | if field.Anonymous && field.Type.Kind() == reflect.Struct { 79 | return nil, fmt.Errorf("embedded structs not supported") 80 | } 81 | 82 | if !meta.OmitAlways { 83 | fieldMap[meta.Key] = meta 84 | } 85 | } 86 | 87 | return fieldMap, nil 88 | } 89 | 90 | func trim(s string) string { 91 | re := regexp.MustCompile("(\\S+|\\S+)") 92 | return strings.Join(re.FindAllString(s, -1), " ") 93 | } 94 | 95 | func Unmarshal(in io.Reader, out interface{}) error { 96 | outValue := reflect.ValueOf(out) 97 | if outValue.Kind() == reflect.Ptr { 98 | outValue = outValue.Elem() 99 | } 100 | 101 | fields, err := getStructFields(outValue.Type()) 102 | if fields == nil { 103 | panic(err) 104 | } 105 | if err != nil { 106 | return err 107 | } 108 | 109 | scanner := bufio.NewScanner(in) 110 | for scanner.Scan() { 111 | if strings.Contains(scanner.Text(), kvDelim) { 112 | s := strings.Split(scanner.Text(), kvDelim) 113 | k, v := trim(s[0]), trim(s[1]) 114 | if meta, ok := fields[k]; ok { 115 | field := outValue.FieldByName(meta.Name) 116 | err = setField(field, v) 117 | if err != nil { 118 | return err 119 | } 120 | } 121 | } 122 | } 123 | return nil 124 | } 125 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/sorter.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "reflect" 5 | "unicode" 6 | ) 7 | 8 | type keyList []reflect.Value 9 | 10 | func (l keyList) Len() int { return len(l) } 11 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 12 | func (l keyList) Less(i, j int) bool { 13 | a := l[i] 14 | b := l[j] 15 | ak := a.Kind() 16 | bk := b.Kind() 17 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 18 | a = a.Elem() 19 | ak = a.Kind() 20 | } 21 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 22 | b = b.Elem() 23 | bk = b.Kind() 24 | } 25 | af, aok := keyFloat(a) 26 | bf, bok := keyFloat(b) 27 | if aok && bok { 28 | if af != bf { 29 | return af < bf 30 | } 31 | if ak != bk { 32 | return ak < bk 33 | } 34 | return numLess(a, b) 35 | } 36 | if ak != reflect.String || bk != reflect.String { 37 | return ak < bk 38 | } 39 | ar, br := []rune(a.String()), []rune(b.String()) 40 | for i := 0; i < len(ar) && i < len(br); i++ { 41 | if ar[i] == br[i] { 42 | continue 43 | } 44 | al := unicode.IsLetter(ar[i]) 45 | bl := unicode.IsLetter(br[i]) 46 | if al && bl { 47 | return ar[i] < br[i] 48 | } 49 | if al || bl { 50 | return bl 51 | } 52 | var ai, bi int 53 | var an, bn int64 54 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 55 | an = an*10 + int64(ar[ai]-'0') 56 | } 57 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 58 | bn = bn*10 + int64(br[bi]-'0') 59 | } 60 | if an != bn { 61 | return an < bn 62 | } 63 | if ai != bi { 64 | return ai < bi 65 | } 66 | return ar[i] < br[i] 67 | } 68 | return len(ar) < len(br) 69 | } 70 | 71 | // keyFloat returns a float value for v if it is a number/bool 72 | // and whether it is a number/bool or not. 73 | func keyFloat(v reflect.Value) (f float64, ok bool) { 74 | switch v.Kind() { 75 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 76 | return float64(v.Int()), true 77 | case reflect.Float32, reflect.Float64: 78 | return v.Float(), true 79 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 80 | return float64(v.Uint()), true 81 | case reflect.Bool: 82 | if v.Bool() { 83 | return 1, true 84 | } 85 | return 0, true 86 | } 87 | return 0, false 88 | } 89 | 90 | // numLess returns whether a < b. 91 | // a and b must necessarily have the same kind. 92 | func numLess(a, b reflect.Value) bool { 93 | switch a.Kind() { 94 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 95 | return a.Int() < b.Int() 96 | case reflect.Float32, reflect.Float64: 97 | return a.Float() < b.Float() 98 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 99 | return a.Uint() < b.Uint() 100 | case reflect.Bool: 101 | return !a.Bool() && b.Bool() 102 | } 103 | panic("not a number") 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/mgutz/ansi/README.md: -------------------------------------------------------------------------------- 1 | # ansi 2 | 3 | Package ansi is a small, fast library to create ANSI colored strings and codes. 4 | 5 | ## Install 6 | 7 | This install the color viewer and the package itself 8 | 9 | ```sh 10 | go get -u github.com/mgutz/ansi/cmd/ansi-mgutz 11 | ``` 12 | 13 | ## Example 14 | 15 | ```go 16 | import "github.com/mgutz/ansi" 17 | 18 | // colorize a string, SLOW 19 | msg := ansi.Color("foo", "red+b:white") 20 | 21 | // create a closure to avoid recalculating ANSI code compilation 22 | phosphorize := ansi.ColorFunc("green+h:black") 23 | msg = phosphorize("Bring back the 80s!") 24 | msg2 := phospohorize("Look, I'm a CRT!") 25 | 26 | // cache escape codes and build strings manually 27 | lime := ansi.ColorCode("green+h:black") 28 | reset := ansi.ColorCode("reset") 29 | 30 | fmt.Println(lime, "Bring back the 80s!", reset) 31 | ``` 32 | 33 | Other examples 34 | 35 | ```go 36 | Color(s, "red") // red 37 | Color(s, "red+b") // red bold 38 | Color(s, "red+B") // red blinking 39 | Color(s, "red+u") // red underline 40 | Color(s, "red+bh") // red bold bright 41 | Color(s, "red:white") // red on white 42 | Color(s, "red+b:white+h") // red bold on white bright 43 | Color(s, "red+B:white+h") // red blink on white bright 44 | Color(s, "off") // turn off ansi codes 45 | ``` 46 | 47 | To view color combinations, from terminal. 48 | 49 | ```sh 50 | ansi-mgutz 51 | ``` 52 | 53 | ## Style format 54 | 55 | ```go 56 | "foregroundColor+attributes:backgroundColor+attributes" 57 | ``` 58 | 59 | Colors 60 | 61 | * black 62 | * red 63 | * green 64 | * yellow 65 | * blue 66 | * magenta 67 | * cyan 68 | * white 69 | * 0...255 (256 colors) 70 | 71 | Attributes 72 | 73 | * b = bold foreground 74 | * B = Blink foreground 75 | * u = underline foreground 76 | * i = inverse 77 | * h = high intensity (bright) foreground, background 78 | 79 | does not work with 256 colors 80 | 81 | ## Constants 82 | 83 | * ansi.Reset 84 | * ansi.DefaultBG 85 | * ansi.DefaultFG 86 | * ansi.Black 87 | * ansi.Red 88 | * ansi.Green 89 | * ansi.Yellow 90 | * ansi.Blue 91 | * ansi.Magenta 92 | * ansi.Cyan 93 | * ansi.White 94 | * ansi.LightBlack 95 | * ansi.LightRed 96 | * ansi.LightGreen 97 | * ansi.LightYellow 98 | * ansi.LightBlue 99 | * ansi.LightMagenta 100 | * ansi.LightCyan 101 | * ansi.LightWhite 102 | 103 | 104 | ## References 105 | 106 | Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) 107 | 108 | General [tips and formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting) 109 | 110 | What about support on Windows? Use [colorable by mattn](https://github.com/mattn/go-colorable). 111 | Ansi and colorable are used by [logxi](https://github.com/mgutz/logxi) to support logging in 112 | color on Windows. 113 | 114 | ## MIT License 115 | 116 | Copyright (c) 2013 Mario Gutierrez mario@mgutz.com 117 | 118 | See the file LICENSE for copying permission. 119 | 120 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/push.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Copyright (c) 2013, The Prometheus Authors 15 | // All rights reserved. 16 | // 17 | // Use of this source code is governed by a BSD-style license that can be found 18 | // in the LICENSE file. 19 | 20 | package prometheus 21 | 22 | // Push triggers a metric collection by the default registry and pushes all 23 | // collected metrics to the Pushgateway specified by url. See the Pushgateway 24 | // documentation for detailed implications of the job and instance 25 | // parameter. instance can be left empty. You can use just host:port or ip:port 26 | // as url, in which case 'http://' is added automatically. You can also include 27 | // the schema in the URL. However, do not include the '/metrics/jobs/...' part. 28 | // 29 | // Note that all previously pushed metrics with the same job and instance will 30 | // be replaced with the metrics pushed by this call. (It uses HTTP method 'PUT' 31 | // to push to the Pushgateway.) 32 | func Push(job, instance, url string) error { 33 | return defRegistry.Push(job, instance, url, "PUT") 34 | } 35 | 36 | // PushAdd works like Push, but only previously pushed metrics with the same 37 | // name (and the same job and instance) will be replaced. (It uses HTTP method 38 | // 'POST' to push to the Pushgateway.) 39 | func PushAdd(job, instance, url string) error { 40 | return defRegistry.Push(job, instance, url, "POST") 41 | } 42 | 43 | // PushCollectors works like Push, but it does not collect from the default 44 | // registry. Instead, it collects from the provided collectors. It is a 45 | // convenient way to push only a few metrics. 46 | func PushCollectors(job, instance, url string, collectors ...Collector) error { 47 | return pushCollectors(job, instance, url, "PUT", collectors...) 48 | } 49 | 50 | // PushAddCollectors works like PushAdd, but it does not collect from the 51 | // default registry. Instead, it collects from the provided collectors. It is a 52 | // convenient way to push only a few metrics. 53 | func PushAddCollectors(job, instance, url string, collectors ...Collector) error { 54 | return pushCollectors(job, instance, url, "POST", collectors...) 55 | } 56 | 57 | func pushCollectors(job, instance, url, method string, collectors ...Collector) error { 58 | r := newRegistry() 59 | for _, collector := range collectors { 60 | if _, err := r.Register(collector); err != nil { 61 | return err 62 | } 63 | } 64 | return r.Push(job, instance, url, method) 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/check_proxyhttp.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "github.com/n0rad/go-erlog/errs" 5 | "github.com/n0rad/go-erlog/logs" 6 | "io/ioutil" 7 | "net/http" 8 | "net/url" 9 | "strconv" 10 | "strings" 11 | "sync" 12 | "time" 13 | ) 14 | 15 | type CheckProxyHttp struct { 16 | CheckCommon 17 | ProxyHost string 18 | ProxyPort int 19 | ProxyUsername string 20 | ProxyPassword string 21 | Urls []string 22 | FailOnAnyUnreachable bool 23 | 24 | client http.Client 25 | } 26 | 27 | func (x *CheckProxyHttp) Run(statusChange chan Check, stop <-chan struct{}, doneWait *sync.WaitGroup) { 28 | x.CommonRun(x, statusChange, stop, doneWait) 29 | } 30 | 31 | func NewCheckProxyHttp() *CheckProxyHttp { 32 | return &CheckProxyHttp{} 33 | } 34 | 35 | func (x *CheckProxyHttp) Init(s *Service) error { 36 | if err := x.CheckCommon.CommonInit(s); err != nil { 37 | return err 38 | } 39 | 40 | if x.ProxyHost == "" { 41 | x.ProxyHost = s.Host 42 | } 43 | if x.ProxyPort == 0 { 44 | x.ProxyPort = s.Port 45 | } 46 | 47 | proxyUrl, err := url.Parse("http://" + x.ProxyUsername + ":" + x.ProxyPassword + "@" + x.ProxyHost + ":" + strconv.Itoa(x.ProxyPort)) 48 | if err != nil { 49 | return errs.WithEF(err, x.fields, "failed to prepare proxy url") 50 | } 51 | 52 | for i, url := range x.Urls { 53 | if !(strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")) { 54 | x.Urls[i] = "http://" + url 55 | } 56 | } 57 | 58 | x.client = http.Client{ 59 | Transport: &http.Transport{ 60 | Proxy: http.ProxyURL(proxyUrl), 61 | }, 62 | Timeout: time.Duration(x.TimeoutInMilli) * time.Millisecond, 63 | } 64 | 65 | return nil 66 | } 67 | 68 | func (x *CheckProxyHttp) Check() error { 69 | result := make(chan error) 70 | for _, url := range x.Urls { 71 | go func(url string) { 72 | var res error 73 | resp, err := x.client.Get(url) 74 | if err != nil || (resp.StatusCode >= 500 && resp.StatusCode < 600) { 75 | ff := x.fields.WithField("url", url) 76 | if err == nil { 77 | ff = ff.WithField("status_code", resp.StatusCode) 78 | if content, err := ioutil.ReadAll(resp.Body); err == nil { 79 | ff = ff.WithField("content", string(content)) 80 | } 81 | resp.Body.Close() 82 | } 83 | res = errs.WithEF(err, ff, "Url check failed") 84 | logs.WithEF(err, x.fields).Trace("Url check failed") 85 | } 86 | if err == nil { 87 | resp.Body.Close() 88 | } 89 | result <- res 90 | }(url) 91 | } 92 | 93 | errors := errs.WithF(x.fields, "Url(s) unreachable") 94 | for i := 0; i < len(x.Urls); i++ { 95 | res := <-result 96 | if res != nil { 97 | errors.WithErr(res) 98 | } 99 | } 100 | 101 | if (x.FailOnAnyUnreachable && len(errors.Errs) > 0) || (!x.FailOnAnyUnreachable && len(errors.Errs) == len(x.Urls)) { 102 | logs.WithEF(errors, x.fields).Trace("Enough failed received") 103 | return errs.WithEF(errors, x.fields, "Enough failed received") 104 | } 105 | return nil 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- int Value 9 | type intValue int 10 | 11 | func newIntValue(val int, p *int) *intValue { 12 | *p = val 13 | return (*intValue)(p) 14 | } 15 | 16 | func (i *intValue) Set(s string) error { 17 | v, err := strconv.ParseInt(s, 0, 64) 18 | *i = intValue(v) 19 | return err 20 | } 21 | 22 | func (i *intValue) Type() string { 23 | return "int" 24 | } 25 | 26 | func (i *intValue) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func intConv(sval string) (interface{}, error) { 29 | return strconv.Atoi(sval) 30 | } 31 | 32 | // GetInt return the int value of a flag with the given name 33 | func (f *FlagSet) GetInt(name string) (int, error) { 34 | val, err := f.getFlagType(name, "int", intConv) 35 | if err != nil { 36 | return 0, err 37 | } 38 | return val.(int), nil 39 | } 40 | 41 | // IntVar defines an int flag with specified name, default value, and usage string. 42 | // The argument p points to an int variable in which to store the value of the flag. 43 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 44 | f.VarP(newIntValue(value, p), name, "", usage) 45 | } 46 | 47 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash. 48 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 49 | f.VarP(newIntValue(value, p), name, shorthand, usage) 50 | } 51 | 52 | // IntVar defines an int flag with specified name, default value, and usage string. 53 | // The argument p points to an int variable in which to store the value of the flag. 54 | func IntVar(p *int, name string, value int, usage string) { 55 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 56 | } 57 | 58 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash. 59 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 60 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // Int defines an int flag with specified name, default value, and usage string. 64 | // The return value is the address of an int variable that stores the value of the flag. 65 | func (f *FlagSet) Int(name string, value int, usage string) *int { 66 | p := new(int) 67 | f.IntVarP(p, name, "", value, usage) 68 | return p 69 | } 70 | 71 | // Like Int, but accepts a shorthand letter that can be used after a single dash. 72 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 73 | p := new(int) 74 | f.IntVarP(p, name, shorthand, value, usage) 75 | return p 76 | } 77 | 78 | // Int defines an int flag with specified name, default value, and usage string. 79 | // The return value is the address of an int variable that stores the value of the flag. 80 | func Int(name string, value int, usage string) *int { 81 | return CommandLine.IntP(name, "", value, usage) 82 | } 83 | 84 | // Like Int, but accepts a shorthand letter that can be used after a single dash. 85 | func IntP(name, shorthand string, value int, usage string) *int { 86 | return CommandLine.IntP(name, shorthand, value, usage) 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fingerprinting.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "strconv" 19 | ) 20 | 21 | // Fingerprint provides a hash-capable representation of a Metric. 22 | // For our purposes, FNV-1A 64-bit is used. 23 | type Fingerprint uint64 24 | 25 | // FingerprintFromString transforms a string representation into a Fingerprint. 26 | func FingerprintFromString(s string) (Fingerprint, error) { 27 | num, err := strconv.ParseUint(s, 16, 64) 28 | return Fingerprint(num), err 29 | } 30 | 31 | // ParseFingerprint parses the input string into a fingerprint. 32 | func ParseFingerprint(s string) (Fingerprint, error) { 33 | num, err := strconv.ParseUint(s, 16, 64) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return Fingerprint(num), nil 38 | } 39 | 40 | func (f Fingerprint) String() string { 41 | return fmt.Sprintf("%016x", uint64(f)) 42 | } 43 | 44 | // Fingerprints represents a collection of Fingerprint subject to a given 45 | // natural sorting scheme. It implements sort.Interface. 46 | type Fingerprints []Fingerprint 47 | 48 | // Len implements sort.Interface. 49 | func (f Fingerprints) Len() int { 50 | return len(f) 51 | } 52 | 53 | // Less implements sort.Interface. 54 | func (f Fingerprints) Less(i, j int) bool { 55 | return f[i] < f[j] 56 | } 57 | 58 | // Swap implements sort.Interface. 59 | func (f Fingerprints) Swap(i, j int) { 60 | f[i], f[j] = f[j], f[i] 61 | } 62 | 63 | // FingerprintSet is a set of Fingerprints. 64 | type FingerprintSet map[Fingerprint]struct{} 65 | 66 | // Equal returns true if both sets contain the same elements (and not more). 67 | func (s FingerprintSet) Equal(o FingerprintSet) bool { 68 | if len(s) != len(o) { 69 | return false 70 | } 71 | 72 | for k := range s { 73 | if _, ok := o[k]; !ok { 74 | return false 75 | } 76 | } 77 | 78 | return true 79 | } 80 | 81 | // Intersection returns the elements contained in both sets. 82 | func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet { 83 | myLength, otherLength := len(s), len(o) 84 | if myLength == 0 || otherLength == 0 { 85 | return FingerprintSet{} 86 | } 87 | 88 | subSet := s 89 | superSet := o 90 | 91 | if otherLength < myLength { 92 | subSet = o 93 | superSet = s 94 | } 95 | 96 | out := FingerprintSet{} 97 | 98 | for k := range subSet { 99 | if _, ok := superSet[k]; ok { 100 | out[k] = struct{}{} 101 | } 102 | } 103 | 104 | return out 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/blablacar/go-nerve/nerve/report.go: -------------------------------------------------------------------------------- 1 | package nerve 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/n0rad/go-erlog/data" 8 | "github.com/n0rad/go-erlog/errs" 9 | "strconv" 10 | ) 11 | 12 | type Port int 13 | 14 | func (p *Port) UnmarshalJSON(b []byte) error { 15 | var i int 16 | if err := json.Unmarshal(b, &i); err == nil { 17 | *p = Port(i) 18 | return nil 19 | } 20 | var s string 21 | if err := json.Unmarshal(b, &s); err == nil { 22 | si, err := strconv.Atoi(s) 23 | if err != nil { 24 | return errs.WithEF(err, data.WithField("content", string(b)), "Invalid port value") 25 | } 26 | *p = Port(si) 27 | return nil 28 | } else { 29 | return errs.WithEF(err, data.WithField("content", string(b)), "Failed to parse port") 30 | } 31 | } 32 | 33 | type Report struct { 34 | Available *bool `json:"available"` 35 | UnavailableReason string `json:"unavailable_reason,omitempty"` 36 | Host string `json:"host,omitempty"` 37 | Port Port `json:"port,omitempty"` 38 | Name string `json:"name,omitempty"` 39 | HaProxyServerOptions string `json:"haproxy_server_options,omitempty"` 40 | Weight *uint8 `json:"weight"` 41 | Labels map[string]string `json:"labels,omitempty"` 42 | } 43 | 44 | type report Report 45 | 46 | func NewReport(content []byte) (*Report, error) { 47 | var r Report 48 | err := json.Unmarshal(content, &r) 49 | return &r, err 50 | } 51 | 52 | func (r *Report) UnmarshalJSON(b []byte) error { 53 | var rr report 54 | if err := json.Unmarshal(b, &rr); err != nil { 55 | return err 56 | } 57 | if rr.Available != nil && *rr.Available == false { 58 | w := uint8(0) 59 | rr.Weight = &w 60 | } 61 | *r = Report(rr) 62 | return nil 63 | } 64 | 65 | func (r *Report) toJson() ([]byte, error) { 66 | return json.Marshal(r) 67 | } 68 | 69 | func toReport(status error, s *Service) Report { 70 | weight := s.CurrentWeight() 71 | boolStatus := status == nil 72 | r := Report{ 73 | Available: &boolStatus, 74 | Host: s.Host, 75 | Port: Port(s.Port), 76 | Name: s.ReporterServiceName, 77 | Weight: &weight, 78 | HaProxyServerOptions: s.HaproxyServerOptions, 79 | Labels: s.Labels, 80 | } 81 | if status != nil { 82 | r.UnavailableReason = status.Error() 83 | } 84 | return r 85 | } 86 | 87 | func (r *Report) String() string { 88 | var buffer bytes.Buffer 89 | if r.Available == nil { 90 | buffer.WriteString(fmt.Sprint(true)) 91 | } else { 92 | buffer.WriteString(fmt.Sprint(*r.Available)) 93 | } 94 | buffer.WriteString(" ") 95 | buffer.WriteString(r.Name) 96 | buffer.WriteString(" ") 97 | buffer.WriteString(r.Host) 98 | buffer.WriteString(":") 99 | buffer.WriteString(strconv.Itoa(int(r.Port))) 100 | if r.Weight != nil { 101 | buffer.WriteString(" ") 102 | buffer.WriteString(strconv.Itoa(int(*r.Weight))) 103 | } 104 | return buffer.String() 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "errors" 20 | "io" 21 | 22 | "github.com/golang/protobuf/proto" 23 | ) 24 | 25 | var errInvalidVarint = errors.New("invalid varint32 encountered") 26 | 27 | // ReadDelimited decodes a message from the provided length-delimited stream, 28 | // where the length is encoded as 32-bit varint prefix to the message body. 29 | // It returns the total number of bytes read and any applicable error. This is 30 | // roughly equivalent to the companion Java API's 31 | // MessageLite#parseDelimitedFrom. As per the reader contract, this function 32 | // calls r.Read repeatedly as required until exactly one message including its 33 | // prefix is read and decoded (or an error has occurred). The function never 34 | // reads more bytes from the stream than required. The function never returns 35 | // an error if a message has been read and decoded correctly, even if the end 36 | // of the stream has been reached in doing so. In that case, any subsequent 37 | // calls return (0, io.EOF). 38 | func ReadDelimited(r io.Reader, m proto.Message) (n int, err error) { 39 | // Per AbstractParser#parsePartialDelimitedFrom with 40 | // CodedInputStream#readRawVarint32. 41 | var headerBuf [binary.MaxVarintLen32]byte 42 | var bytesRead, varIntBytes int 43 | var messageLength uint64 44 | for varIntBytes == 0 { // i.e. no varint has been decoded yet. 45 | if bytesRead >= len(headerBuf) { 46 | return bytesRead, errInvalidVarint 47 | } 48 | // We have to read byte by byte here to avoid reading more bytes 49 | // than required. Each read byte is appended to what we have 50 | // read before. 51 | newBytesRead, err := r.Read(headerBuf[bytesRead : bytesRead+1]) 52 | if newBytesRead == 0 { 53 | if err != nil { 54 | return bytesRead, err 55 | } 56 | // A Reader should not return (0, nil), but if it does, 57 | // it should be treated as no-op (according to the 58 | // Reader contract). So let's go on... 59 | continue 60 | } 61 | bytesRead += newBytesRead 62 | // Now present everything read so far to the varint decoder and 63 | // see if a varint can be decoded already. 64 | messageLength, varIntBytes = proto.DecodeVarint(headerBuf[:bytesRead]) 65 | } 66 | 67 | messageBuf := make([]byte, messageLength) 68 | newBytesRead, err := io.ReadFull(r, messageBuf) 69 | bytesRead += newBytesRead 70 | if err != nil { 71 | return bytesRead, err 72 | } 73 | 74 | return bytesRead, proto.Unmarshal(messageBuf, m) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "fmt" 4 | 5 | // -- string Value 6 | type stringValue string 7 | 8 | func newStringValue(val string, p *string) *stringValue { 9 | *p = val 10 | return (*stringValue)(p) 11 | } 12 | 13 | func (s *stringValue) Set(val string) error { 14 | *s = stringValue(val) 15 | return nil 16 | } 17 | func (s *stringValue) Type() string { 18 | return "string" 19 | } 20 | 21 | func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) } 22 | 23 | func stringConv(sval string) (interface{}, error) { 24 | return sval, nil 25 | } 26 | 27 | // GetString return the string value of a flag with the given name 28 | func (f *FlagSet) GetString(name string) (string, error) { 29 | val, err := f.getFlagType(name, "string", stringConv) 30 | if err != nil { 31 | return "", err 32 | } 33 | return val.(string), nil 34 | } 35 | 36 | // StringVar defines a string flag with specified name, default value, and usage string. 37 | // The argument p points to a string variable in which to store the value of the flag. 38 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 39 | f.VarP(newStringValue(value, p), name, "", usage) 40 | } 41 | 42 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash. 43 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 44 | f.VarP(newStringValue(value, p), name, shorthand, usage) 45 | } 46 | 47 | // StringVar defines a string flag with specified name, default value, and usage string. 48 | // The argument p points to a string variable in which to store the value of the flag. 49 | func StringVar(p *string, name string, value string, usage string) { 50 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 51 | } 52 | 53 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash. 54 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 55 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 56 | } 57 | 58 | // String defines a string flag with specified name, default value, and usage string. 59 | // The return value is the address of a string variable that stores the value of the flag. 60 | func (f *FlagSet) String(name string, value string, usage string) *string { 61 | p := new(string) 62 | f.StringVarP(p, name, "", value, usage) 63 | return p 64 | } 65 | 66 | // Like String, but accepts a shorthand letter that can be used after a single dash. 67 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 68 | p := new(string) 69 | f.StringVarP(p, name, shorthand, value, usage) 70 | return p 71 | } 72 | 73 | // String defines a string flag with specified name, default value, and usage string. 74 | // The return value is the address of a string variable that stores the value of the flag. 75 | func String(name string, value string, usage string) *string { 76 | return CommandLine.StringP(name, "", value, usage) 77 | } 78 | 79 | // Like String, but accepts a shorthand letter that can be used after a single dash. 80 | func StringP(name, shorthand string, value string, usage string) *string { 81 | return CommandLine.StringP(name, shorthand, value, usage) 82 | } 83 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/README.md: -------------------------------------------------------------------------------- 1 | # YAML support for the Go language 2 | 3 | Introduction 4 | ------------ 5 | 6 | The yaml package enables Go programs to comfortably encode and decode YAML 7 | values. It was developed within [Canonical](https://www.canonical.com) as 8 | part of the [juju](https://juju.ubuntu.com) project, and is based on a 9 | pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) 10 | C library to parse and generate YAML data quickly and reliably. 11 | 12 | Compatibility 13 | ------------- 14 | 15 | The yaml package supports most of YAML 1.1 and 1.2, including support for 16 | anchors, tags, map merging, etc. Multi-document unmarshalling is not yet 17 | implemented, and base-60 floats from YAML 1.1 are purposefully not 18 | supported since they're a poor design and are gone in YAML 1.2. 19 | 20 | Installation and usage 21 | ---------------------- 22 | 23 | The import path for the package is *gopkg.in/yaml.v2*. 24 | 25 | To install it, run: 26 | 27 | go get gopkg.in/yaml.v2 28 | 29 | API documentation 30 | ----------------- 31 | 32 | If opened in a browser, the import path itself leads to the API documentation: 33 | 34 | * [https://gopkg.in/yaml.v2](https://gopkg.in/yaml.v2) 35 | 36 | API stability 37 | ------------- 38 | 39 | The package API for yaml v2 will remain stable as described in [gopkg.in](https://gopkg.in). 40 | 41 | 42 | License 43 | ------- 44 | 45 | The yaml package is licensed under the LGPL with an exception that allows it to be linked statically. Please see the LICENSE file for details. 46 | 47 | 48 | Example 49 | ------- 50 | 51 | ```Go 52 | package main 53 | 54 | import ( 55 | "fmt" 56 | "log" 57 | 58 | "gopkg.in/yaml.v2" 59 | ) 60 | 61 | var data = ` 62 | a: Easy! 63 | b: 64 | c: 2 65 | d: [3, 4] 66 | ` 67 | 68 | type T struct { 69 | A string 70 | B struct{C int; D []int ",flow"} 71 | } 72 | 73 | func main() { 74 | t := T{} 75 | 76 | err := yaml.Unmarshal([]byte(data), &t) 77 | if err != nil { 78 | log.Fatalf("error: %v", err) 79 | } 80 | fmt.Printf("--- t:\n%v\n\n", t) 81 | 82 | d, err := yaml.Marshal(&t) 83 | if err != nil { 84 | log.Fatalf("error: %v", err) 85 | } 86 | fmt.Printf("--- t dump:\n%s\n\n", string(d)) 87 | 88 | m := make(map[interface{}]interface{}) 89 | 90 | err = yaml.Unmarshal([]byte(data), &m) 91 | if err != nil { 92 | log.Fatalf("error: %v", err) 93 | } 94 | fmt.Printf("--- m:\n%v\n\n", m) 95 | 96 | d, err = yaml.Marshal(&m) 97 | if err != nil { 98 | log.Fatalf("error: %v", err) 99 | } 100 | fmt.Printf("--- m dump:\n%s\n\n", string(d)) 101 | } 102 | ``` 103 | 104 | This example will generate the following output: 105 | 106 | ``` 107 | --- t: 108 | {Easy! {2 [3 4]}} 109 | 110 | --- t dump: 111 | a: Easy! 112 | b: 113 | c: 2 114 | d: [3, 4] 115 | 116 | 117 | --- m: 118 | map[a:Easy! b:map[c:2 d:[3 4]]] 119 | 120 | --- m dump: 121 | a: Easy! 122 | b: 123 | c: 2 124 | d: 125 | - 3 126 | - 4 127 | ``` 128 | 129 | --------------------------------------------------------------------------------