├── .envrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── cmd └── docker-volume-ipfs │ └── docker-volume-ipfs.go ├── codecov.yml ├── default.nix ├── doc.go ├── driver ├── driver.go └── driver_test.go ├── integration ├── fake_test.go └── integration.test ├── vendor.conf ├── vendor ├── github.com │ ├── Sirupsen │ │ └── logrus │ │ │ ├── LICENSE │ │ │ ├── alt_exit.go │ │ │ ├── doc.go │ │ │ ├── entry.go │ │ │ ├── exported.go │ │ │ ├── formatter.go │ │ │ ├── hooks.go │ │ │ ├── json_formatter.go │ │ │ ├── logger.go │ │ │ ├── logrus.go │ │ │ ├── terminal_appengine.go │ │ │ ├── terminal_bsd.go │ │ │ ├── terminal_linux.go │ │ │ ├── terminal_notwindows.go │ │ │ ├── terminal_solaris.go │ │ │ ├── terminal_windows.go │ │ │ ├── text_formatter.go │ │ │ └── writer.go │ ├── coreos │ │ ├── go-systemd │ │ │ ├── LICENSE │ │ │ ├── activation │ │ │ │ ├── files.go │ │ │ │ ├── listeners.go │ │ │ │ └── packetconns.go │ │ │ └── util │ │ │ │ ├── util.go │ │ │ │ ├── util_cgo.go │ │ │ │ └── util_stub.go │ │ └── pkg │ │ │ ├── LICENSE │ │ │ ├── NOTICE │ │ │ └── dlopen │ │ │ ├── dlopen.go │ │ │ └── dlopen_example.go │ ├── docker │ │ ├── go-connections │ │ │ ├── LICENSE │ │ │ └── sockets │ │ │ │ ├── inmem_socket.go │ │ │ │ ├── proxy.go │ │ │ │ ├── sockets.go │ │ │ │ ├── sockets_unix.go │ │ │ │ ├── sockets_windows.go │ │ │ │ ├── tcp_socket.go │ │ │ │ └── unix_socket.go │ │ └── go-plugins-helpers │ │ │ ├── LICENSE │ │ │ ├── NOTICE │ │ │ ├── sdk │ │ │ ├── encoder.go │ │ │ ├── handler.go │ │ │ ├── tcp_listener.go │ │ │ ├── unix_listener.go │ │ │ └── unix_listener_unsupported.go │ │ │ └── volume │ │ │ └── api.go │ ├── inconshreveable │ │ └── mousetrap │ │ │ ├── LICENSE │ │ │ ├── trap_others.go │ │ │ ├── trap_windows.go │ │ │ └── trap_windows_1.4.go │ ├── opencontainers │ │ └── runc │ │ │ ├── LICENSE │ │ │ ├── NOTICE │ │ │ └── libcontainer │ │ │ ├── nsenter │ │ │ ├── namespace.h │ │ │ ├── nsenter.go │ │ │ ├── nsenter_gccgo.go │ │ │ ├── nsenter_unsupported.go │ │ │ └── nsexec.c │ │ │ └── user │ │ │ ├── lookup.go │ │ │ ├── lookup_unix.go │ │ │ ├── lookup_unsupported.go │ │ │ └── user.go │ └── spf13 │ │ ├── cobra │ │ ├── bash_completions.go │ │ ├── cobra.go │ │ ├── command.go │ │ ├── command_notwin.go │ │ └── command_win.go │ │ └── pflag │ │ ├── LICENSE │ │ ├── bool.go │ │ ├── count.go │ │ ├── duration.go │ │ ├── flag.go │ │ ├── float32.go │ │ ├── float64.go │ │ ├── golangflag.go │ │ ├── int.go │ │ ├── int32.go │ │ ├── int64.go │ │ ├── int8.go │ │ ├── int_slice.go │ │ ├── ip.go │ │ ├── ipmask.go │ │ ├── ipnet.go │ │ ├── string.go │ │ ├── string_array.go │ │ ├── string_slice.go │ │ ├── uint.go │ │ ├── uint16.go │ │ ├── uint32.go │ │ ├── uint64.go │ │ └── uint8.go └── golang.org │ └── x │ └── net │ ├── LICENSE │ ├── PATENTS │ └── proxy │ ├── direct.go │ ├── per_host.go │ ├── proxy.go │ └── socks5.go └── version ├── cmd.go ├── print.go ├── version.go └── version.sh /.envrc: -------------------------------------------------------------------------------- 1 | use_nix -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .idea 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7 7 | - tip 8 | 9 | services: 10 | - docker 11 | 12 | notifications: 13 | email: false 14 | 15 | install: 16 | - make setup 17 | 18 | script: 19 | - make ci 20 | - bash <(curl -s https://codecov.io/bash) 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Antonio Murdaca 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 NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Root directory of the project (absolute path). 2 | ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 3 | 4 | # Base path used to install. 5 | DESTDIR=/usr/local 6 | 7 | # Used to populate version variable in main package. 8 | VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always) 9 | 10 | PROJECT_ROOT=github.com/vdemeester/docker-volume-ipfs 11 | 12 | # Race detector is only supported on amd64. 13 | RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race")) 14 | 15 | # Project packages. 16 | PACKAGES=$(shell go list ./... | grep -v /vendor/) 17 | INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration 18 | 19 | # Project binaries. 20 | COMMANDS=docker-volume-ipfs 21 | BINARIES=$(addprefix bin/,$(COMMANDS)) 22 | 23 | GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)" 24 | 25 | .PHONY: clean all fmt vet lint build binaries test integration setup coverage ci check help install uninstall 26 | .DEFAULT: default 27 | 28 | all: check binaries test integration ## run fmt, vet, lint, build the binaries and run the tests 29 | 30 | check: fmt vet lint ineffassign ## run fmt, vet, lint, ineffassign 31 | 32 | ci: check binaries coverage coverage-integration ## to be used by the CI 33 | 34 | setup: ## install dependencies 35 | @echo "🐳 $@" 36 | @go get -u github.com/golang/lint/golint 37 | @go get -u github.com/golang/mock/mockgen 38 | @go get -u github.com/gordonklaus/ineffassign 39 | 40 | # Depends on binaries because vet will silently fail if it can't load compiled 41 | # imports 42 | vet: binaries ## run go vet 43 | @echo "🐳 $@" 44 | @test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | egrep -v '(timestamp_test.go|duration_test.go|exit status 1)' | tee /dev/stderr)" 45 | 46 | fmt: ## run go fmt 47 | @echo "🐳 $@" 48 | @test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)" || \ 49 | (echo "👹 please format Go code with 'gofmt -s -w'" && false) 50 | 51 | lint: ## run go lint 52 | @echo "🐳 $@" 53 | @test -z "$$(golint ./... | grep -v vendor/ | tee /dev/stderr)" 54 | 55 | ineffassign: ## run ineffassign 56 | @echo "🐳 $@" 57 | @test -z "$$(ineffassign . | grep -v vendor/ | tee /dev/stderr)" 58 | 59 | build: ## build the go packages 60 | @echo "🐳 $@" 61 | @go build -i -tags "${BUILDTAGS}" -v ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES} 62 | 63 | test: ## run tests, except integration tests 64 | @echo "🐳 $@" 65 | @go test -parallel 8 ${RACE} -tags "${BUILDTAGS}" $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 66 | 67 | integration: ## run integration tests 68 | @echo "🐳 $@" 69 | @go test -parallel 8 ${RACE} -tags "${BUILDTAGS}" ${INTEGRATION_PACKAGE} 70 | 71 | FORCE: 72 | 73 | # Build a binary from a cmd. 74 | bin/%: cmd/% FORCE 75 | @test $$(go list) = "${PROJECT_ROOT}" || \ 76 | (echo "👹 Please correctly set up your Go build environment. This project must be located at /src/${PROJECT_ROOT}" && false) 77 | @echo "🐳 $@" 78 | @go build -i -tags "${BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./$< 79 | 80 | binaries: $(BINARIES) ## build binaries 81 | @echo "🐳 $@" 82 | 83 | clean: ## clean up binaries 84 | @echo "🐳 $@" 85 | @rm -f $(BINARIES) 86 | 87 | coverage: ## generate coverprofiles from the unit tests 88 | @echo "🐳 $@" 89 | @for pkg in $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}); do \ 90 | go test ${RACE} -tags "${BUILDTAGS}" -test.short -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \ 91 | done 92 | 93 | coverage-integration: ## generate coverprofiles from the integration tests 94 | @echo "🐳 $@" 95 | go test ${RACE} -tags "${BUILDTAGS}" -test.short -coverprofile="../../../${INTEGRATION_PACKAGE}/coverage.txt" -covermode=atomic ${INTEGRATION_PACKAGE} 96 | 97 | help: ## this help 98 | @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 99 | 100 | install: $(BINARIES) ## install binaries 101 | @echo "🐳 $@" 102 | @mkdir -p $(DESTDIR)/bin 103 | @install $(BINARIES) $(DESTDIR)/bin 104 | 105 | uninstall: 106 | @echo "🐳 $@" 107 | @rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES))) 108 | 109 | # This only needs to be generated by hand when cutting full releases. 110 | version/version.go: 111 | ./version/version.sh > $@ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🐳 docker-volume-ipfs 2 | 3 | [![GoDoc](https://godoc.org/github.com/vdemeester/docker-volume-ipfs?status.png)](https://godoc.org/github.com/vdemeester/docker-volume-ipfs) 4 | [![Build Status](https://travis-ci.org/vdemeester/docker-volume-ipfs.svg?branch=master)](https://travis-ci.org/vdemeester/docker-volume-ipfs) 5 | [![Go Report Card](https://goreportcard.com/badge/github.com/vdemeester/docker-volume-ipfs)](https://goreportcard.com/report/github.com/vdemeester/docker-volume-ipfs) 6 | [![License](https://img.shields.io/github/license/vdemeester/docker-volume-ipfs.svg)]() 7 | [![codecov](https://codecov.io/gh/vdemeester/docker-volume-ipfs/branch/master/graph/badge.svg)](https://codecov.io/gh/vdemeester/docker-volume-ipfs) 8 | 9 | This is an open source volume plugin that allows using an 10 | [ipfs](https://ipfs.io/) filesystem as a volume. 11 | 12 | ```bash 13 | $ docker-volume-ipfs & 14 | $ docker run -it --rm -v QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT/readme:/data --volume-driver=ipfs busybox cat data 15 | Hello and Welcome to IPFS! 16 | 17 | ██╗██████╗ ███████╗███████╗ 18 | ██║██╔══██╗██╔════╝██╔════╝ 19 | ██║██████╔╝█████╗ ███████╗ 20 | ██║██╔═══╝ ██╔══╝ ╚════██║ 21 | ██║██║ ██║ ███████║ 22 | ╚═╝╚═╝ ╚═╝ ╚══════╝ 23 | 24 | If you're seeing this, you have successfully installed 25 | IPFS and are now interfacing with the ipfs merkledag! 26 | 27 | ------------------------------------------------------- 28 | | Warning: | 29 | | This is alpha software. use at your own discretion! | 30 | | Much is missing or lacking polish. There are bugs. | 31 | | Not yet secure. Read the security notes for more. | 32 | ------------------------------------------------------- 33 | 34 | Check out some of the other files in this directory: 35 | 36 | ./about 37 | ./help 38 | ./quick-start <-- usage examples 39 | ./readme <-- this file 40 | ./security-notes 41 | ``` 42 | 43 | ## Goals 44 | 45 | The main goal is to be able to create docker volumes that are backed by the IPFS filesystem. They could be named volumes, 46 | anonymous volumes. The plugin should also work in a cluster / swarm environment (but by its nature it should be built-in). 47 | 48 | First, let's define a "format" for creating volumes. There is two cases: `docker volume create` and `docker run -v`. 49 | 50 | For `docker volume create`, it could be an option `ipfs=`, `ipns=`... 51 | 52 | ```bash 53 | $ docker volume create --driver=ipfs --opt ipfs=QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT --name ipfs-welcome 54 | $ docker run -v ipfs-welcome:/ipfs/welcome busybox cat /ipfs/welcome/readme 55 | Hello and Welcome to IPFS! 56 | 57 | ██╗██████╗ ███████╗███████╗ 58 | ██║██╔══██╗██╔════╝██╔════╝ 59 | ██║██████╔╝█████╗ ███████╗ 60 | ██║██╔═══╝ ██╔══╝ ╚════██║ 61 | ██║██║ ██║ ███████║ 62 | ╚═╝╚═╝ ╚═╝ ╚══════╝ 63 | 64 | If you're seeing this, you have successfully installed 65 | # […] 66 | # would also work with ipns 67 | $ docker volume create --driver=ipfs --opt ipns=ipfs.io --name ipfs-io-website 68 | $ docker run -v ipfs-io-website:/var/www/html nginx 69 | ``` 70 | 71 | For `-v` directly in `docker run` (a.k.a. anonymous volume), we could namespace it somehow. 72 | 73 | ``` 74 | # Default to ipfs 75 | $ docker run -it --rm -v QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT/readme:/data --volume-driver=ipfs busybox cat data 76 | Hello and Welcome to IPFS! 77 | # […] 78 | $ docker run -it --rm -v $(docker volume create --driver=ipfs --opt ipns=ipfs.io):/var/www/html --volume-driver=ipfs nginx 79 | ``` 80 | 81 | ## TODO(s) 82 | 83 | - [ ] Use `ipfs daemon` API instead of making the assumption that a daemon is running and mounting ipfs using fuse 84 | - [ ] Support ipfs mounts (via fuse) 85 | - [ ] Support ipns mounts 86 | - [ ] Create a volume v2 plugin -------------------------------------------------------------------------------- /cmd/docker-volume-ipfs/docker-volume-ipfs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "os" 8 | "os/exec" 9 | "os/signal" 10 | "path/filepath" 11 | 12 | "github.com/docker/go-plugins-helpers/volume" 13 | "github.com/vdemeester/docker-volume-ipfs/driver" 14 | ) 15 | 16 | const ipfsID = "_ipfs" 17 | 18 | var ( 19 | defaultDir = filepath.Join(volume.DefaultDockerRootDirectory, ipfsID) 20 | // ipfs fuse mountpoint 21 | ipfsMountPoint = flag.String("mount", "/ipfs", "ipfs mount point") 22 | ) 23 | 24 | func main() { 25 | // Set up channel on which to send signal notifications. 26 | // We must use a buffered channel or risk missing the signal 27 | // if we're not ready to receive when the signal is sent. 28 | sigs := make(chan os.Signal, 1) 29 | signal.Notify(sigs, os.Interrupt, os.Kill) 30 | 31 | // var Usage = func() { 32 | // fmt.Fprintf(os.Stderr, "Usage %s [options]\n", os.Args[0]) 33 | // flag.PrintDefaults() 34 | // } 35 | 36 | flag.Parse() 37 | 38 | _, err := os.Lstat(*ipfsMountPoint) 39 | if err != nil { 40 | fmt.Fprintf(os.Stderr, "%v\n%s does not exists, can't start..\n Please use ipfs command line to mount it\n", err, *ipfsMountPoint) 41 | os.Exit(1) 42 | } 43 | 44 | d := driver.New(*ipfsMountPoint) 45 | h := volume.NewHandler(d) 46 | go func() { 47 | if err := h.ServeUnix("root", "ipfs"); err != nil { 48 | fmt.Println(err) 49 | } 50 | }() 51 | cmd := startIPFSDaemon() 52 | cmd.Wait() 53 | } 54 | 55 | func startIPFSDaemon() *exec.Cmd { 56 | cmd := exec.Command("ipfs", "daemon", "--mount") 57 | stdout, err := cmd.StdoutPipe() 58 | if err != nil { 59 | fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for IPFS", err) 60 | os.Exit(1) 61 | } 62 | 63 | scannerOut := bufio.NewScanner(stdout) 64 | go func() { 65 | for scannerOut.Scan() { 66 | fmt.Printf("IPFS > %s\n", scannerOut.Text()) 67 | } 68 | }() 69 | 70 | stderr, err := cmd.StderrPipe() 71 | if err != nil { 72 | fmt.Fprintln(os.Stderr, "Error creating StderrPipe for IPFS", err) 73 | os.Exit(1) 74 | } 75 | 76 | scannerErr := bufio.NewScanner(stderr) 77 | go func() { 78 | for scannerErr.Scan() { 79 | fmt.Printf("IPFS > %s\n", scannerErr.Text()) 80 | } 81 | }() 82 | 83 | err = cmd.Start() 84 | if err != nil { 85 | fmt.Fprintln(os.Stderr, "Error starting IPFS", err) 86 | os.Exit(1) 87 | } 88 | 89 | return cmd 90 | } 91 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: header, changes, diff, sunburst 3 | coverage: 4 | status: 5 | patch: false 6 | project: 7 | default: 8 | enabled: yes 9 | target: 0 10 | changes: false 11 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | let 2 | _pkgs = import {}; 3 | in 4 | { pkgs ? import (_pkgs.fetchFromGitHub { owner = "NixOS"; 5 | repo = "nixpkgs-channels"; 6 | rev = "0afb6d789c8bf74825e8cdf6a5d3b9ab8bde4f2d"; 7 | sha256 = "147vhzrnwcy0v77kgbap31698qbda8rn09n5fnjp740svmkjpaiz"; 8 | }) {} 9 | }: 10 | 11 | pkgs.stdenv.mkDerivation rec { 12 | name = "docker-pipeline-dev"; 13 | env = pkgs.buildEnv { name = name; paths = buildInputs; }; 14 | buildInputs = [ 15 | pkgs.go_1_8 16 | pkgs.vndr 17 | pkgs.docker 18 | pkgs.gnumake 19 | pkgs.gcc 20 | pkgs.gotools 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | package dockervolumeipfs 2 | -------------------------------------------------------------------------------- /driver/driver.go: -------------------------------------------------------------------------------- 1 | package driver 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "sync" 8 | 9 | "github.com/docker/go-plugins-helpers/volume" 10 | ) 11 | 12 | // IPFS represent the IPFS volume driver 13 | type IPFS struct { 14 | mountPoint string 15 | volumes map[string]string 16 | m *sync.Mutex 17 | } 18 | 19 | // New create an IPFS driver 20 | func New(ipfsMountPoint string) IPFS { 21 | d := IPFS{ 22 | mountPoint: ipfsMountPoint, 23 | volumes: make(map[string]string), 24 | m: &sync.Mutex{}, 25 | } 26 | return d 27 | } 28 | 29 | // Create implements /VolumeDriver.Create 30 | func (d IPFS) Create(r volume.Request) volume.Response { 31 | fmt.Printf("Create %v\n", r) 32 | 33 | d.m.Lock() 34 | defer d.m.Unlock() 35 | 36 | volumeName := r.Name 37 | 38 | if _, ok := d.volumes[volumeName]; ok { 39 | return volume.Response{} 40 | } 41 | 42 | volumePath := filepath.Join(d.mountPoint, volumeName) 43 | 44 | _, err := os.Lstat(volumePath) 45 | if err != nil { 46 | fmt.Println("Error", volumePath, err.Error()) 47 | return volume.Response{Err: fmt.Sprintf("Error while looking for volumePath %s: %s", volumePath, err.Error())} 48 | } 49 | 50 | d.volumes[volumeName] = volumePath 51 | 52 | return volume.Response{} 53 | } 54 | 55 | // Path implements /VolumeDriver.Path 56 | func (d IPFS) Path(r volume.Request) volume.Response { 57 | fmt.Printf("Path %v\n", r) 58 | fmt.Printf("%v", d.volumes) 59 | volumeName := r.Name 60 | 61 | if volumePath, ok := d.volumes[volumeName]; ok { 62 | return volume.Response{Mountpoint: volumePath} 63 | } 64 | 65 | return volume.Response{} 66 | } 67 | 68 | // Remove implements /VolumeDriver.Remove 69 | func (d IPFS) Remove(r volume.Request) volume.Response { 70 | fmt.Printf("Remove %v", r) 71 | 72 | d.m.Lock() 73 | defer d.m.Unlock() 74 | 75 | volumeName := r.Name 76 | 77 | if _, ok := d.volumes[volumeName]; ok { 78 | delete(d.volumes, volumeName) 79 | } 80 | 81 | return volume.Response{} 82 | } 83 | 84 | // Mount implements /VolumeDriver.Mount 85 | func (d IPFS) Mount(r volume.MountRequest) volume.Response { 86 | fmt.Printf("Mount %v\n", r) 87 | volumeName := r.Name 88 | 89 | if volumePath, ok := d.volumes[volumeName]; ok { 90 | return volume.Response{Mountpoint: volumePath} 91 | } 92 | 93 | return volume.Response{} 94 | } 95 | 96 | // Unmount implements /VolumeDriver.Mount 97 | func (d IPFS) Unmount(r volume.UnmountRequest) volume.Response { 98 | fmt.Printf("Unmount %v: nothing to do\n", r) 99 | return volume.Response{} 100 | } 101 | 102 | // Get implements /VolumeDriver.Get 103 | func (d IPFS) Get(r volume.Request) volume.Response { 104 | fmt.Printf("Get %v\n", r) 105 | volumeName := r.Name 106 | 107 | if volumePath, ok := d.volumes[volumeName]; ok { 108 | return volume.Response{Volume: &volume.Volume{Name: volumeName, Mountpoint: volumePath}} 109 | } 110 | 111 | return volume.Response{Err: fmt.Sprintf("volume %s does not exists", volumeName)} 112 | } 113 | 114 | // List implements /VolumeDriver.List 115 | func (d IPFS) List(r volume.Request) volume.Response { 116 | fmt.Printf("List %v\n", r) 117 | 118 | volumes := []*volume.Volume{} 119 | 120 | for name, path := range d.volumes { 121 | volumes = append(volumes, &volume.Volume{Name: name, Mountpoint: path}) 122 | } 123 | 124 | return volume.Response{Volumes: volumes} 125 | } 126 | 127 | // Capabilities implements /VolumeDriver.Capabilities 128 | func (d IPFS) Capabilities(r volume.Request) volume.Response { 129 | // FIXME(vdemeester) handle capabilities better 130 | return volume.Response{ 131 | Capabilities: volume.Capability{ 132 | Scope: "local", 133 | }, 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /driver/driver_test.go: -------------------------------------------------------------------------------- 1 | package driver 2 | 3 | import "testing" 4 | 5 | func TestFoo(t *testing.T) { 6 | } 7 | -------------------------------------------------------------------------------- /integration/fake_test.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import "testing" 4 | 5 | func TestFake(t *testing.T) { 6 | } 7 | -------------------------------------------------------------------------------- /integration/integration.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vdemeester/docker-volume-ipfs/c0da20ea0bcea240473c7d9c47904eaa3bf89a60/integration/integration.test -------------------------------------------------------------------------------- /vendor.conf: -------------------------------------------------------------------------------- 1 | 2 | github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9 3 | github.com/spf13/cobra 6b74a60562f5c1c920299b8f02d153e16f4897fc 4 | github.com/spf13/pflag dabebe21bf790f782ea4c7bbd2efc430de182afd 5 | github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 6 | 7 | golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://github.com/tonistiigi/net.git 8 | 9 | github.com/docker/go-plugins-helpers 77bfeec724ac5ae33f6a820c7ee6c98301b5a121 10 | github.com/docker/go-connections 4ccf312bf1d35e5dbda654e57a9be4c3f3cd0366 11 | github.com/Sirupsen/logrus f76d643702a30fbffecdfe50831e11881c96ceb3 https://github.com/aaronlehmann/logrus 12 | github.com/opencontainers/runc 51371867a01c467f08af739783b8beafc15 # libcontainer 13 | 14 | github.com/coreos/go-systemd 7c9533367ef925dc1078d75e5b7141e10da2c4e8 15 | github.com/coreos/pkg 447b7ec906e523386d9c53be15b55a8ae86ea944 -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/alt_exit.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | // The following code was sourced and modified from the 4 | // https://bitbucket.org/tebeka/atexit package governed by the following license: 5 | // 6 | // Copyright (c) 2012 Miki Tebeka . 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | // this software and associated documentation files (the "Software"), to deal in 10 | // the Software without restriction, including without limitation the rights to 11 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | // the Software, and to permit persons to whom the Software is furnished to do so, 13 | // subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | import ( 26 | "fmt" 27 | "os" 28 | ) 29 | 30 | var handlers = []func(){} 31 | 32 | func runHandler(handler func()) { 33 | defer func() { 34 | if err := recover(); err != nil { 35 | fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err) 36 | } 37 | }() 38 | 39 | handler() 40 | } 41 | 42 | func runHandlers() { 43 | for _, handler := range handlers { 44 | runHandler(handler) 45 | } 46 | } 47 | 48 | // Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code) 49 | func Exit(code int) { 50 | runHandlers() 51 | os.Exit(code) 52 | } 53 | 54 | // RegisterExitHandler adds a Logrus Exit handler, call logrus.Exit to invoke 55 | // all handlers. The handlers will also be invoked when any Fatal log entry is 56 | // made. 57 | // 58 | // This method is useful when a caller wishes to use logrus to log a fatal 59 | // message but also needs to gracefully shutdown. An example usecase could be 60 | // closing database connections, or sending a alert that the application is 61 | // closing. 62 | func RegisterExitHandler(handler func()) { 63 | handlers = append(handlers, handler) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package logrus is a structured logger for Go, completely API compatible with the standard library logger. 3 | 4 | 5 | The simplest way to use Logrus is simply the package-level exported logger: 6 | 7 | package main 8 | 9 | import ( 10 | log "github.com/Sirupsen/logrus" 11 | ) 12 | 13 | func main() { 14 | log.WithFields(log.Fields{ 15 | "animal": "walrus", 16 | "number": 1, 17 | "size": 10, 18 | }).Info("A walrus appears") 19 | } 20 | 21 | Output: 22 | time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 23 | 24 | For a full guide visit https://github.com/Sirupsen/logrus 25 | */ 26 | package logrus 27 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/entry.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "sync" 8 | "time" 9 | ) 10 | 11 | var bufferPool *sync.Pool 12 | 13 | func init() { 14 | bufferPool = &sync.Pool{ 15 | New: func() interface{} { 16 | return new(bytes.Buffer) 17 | }, 18 | } 19 | } 20 | 21 | // Defines the key when adding errors using WithError. 22 | var ErrorKey = "error" 23 | 24 | // An entry is the final or intermediate Logrus logging entry. It contains all 25 | // the fields passed with WithField{,s}. It's finally logged when Debug, Info, 26 | // Warn, Error, Fatal or Panic is called on it. These objects can be reused and 27 | // passed around as much as you wish to avoid field duplication. 28 | type Entry struct { 29 | Logger *Logger 30 | 31 | // Contains all the fields set by the user. 32 | Data Fields 33 | 34 | // Time at which the log entry was created 35 | Time time.Time 36 | 37 | // Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic 38 | Level Level 39 | 40 | // Message passed to Debug, Info, Warn, Error, Fatal or Panic 41 | Message string 42 | 43 | // When formatter is called in entry.log(), an Buffer may be set to entry 44 | Buffer *bytes.Buffer 45 | } 46 | 47 | func NewEntry(logger *Logger) *Entry { 48 | return &Entry{ 49 | Logger: logger, 50 | // Default is three fields, give a little extra room 51 | Data: make(Fields, 5), 52 | } 53 | } 54 | 55 | // Returns the string representation from the reader and ultimately the 56 | // formatter. 57 | func (entry *Entry) String() (string, error) { 58 | serialized, err := entry.Logger.Formatter.Format(entry) 59 | if err != nil { 60 | return "", err 61 | } 62 | str := string(serialized) 63 | return str, nil 64 | } 65 | 66 | // Add an error as single field (using the key defined in ErrorKey) to the Entry. 67 | func (entry *Entry) WithError(err error) *Entry { 68 | return entry.WithField(ErrorKey, err) 69 | } 70 | 71 | // Add a single field to the Entry. 72 | func (entry *Entry) WithField(key string, value interface{}) *Entry { 73 | return entry.WithFields(Fields{key: value}) 74 | } 75 | 76 | // Add a map of fields to the Entry. 77 | func (entry *Entry) WithFields(fields Fields) *Entry { 78 | data := make(Fields, len(entry.Data)+len(fields)) 79 | for k, v := range entry.Data { 80 | data[k] = v 81 | } 82 | for k, v := range fields { 83 | data[k] = v 84 | } 85 | return &Entry{Logger: entry.Logger, Data: data} 86 | } 87 | 88 | // This function is not declared with a pointer value because otherwise 89 | // race conditions will occur when using multiple goroutines 90 | func (entry Entry) log(level Level, msg string) { 91 | var buffer *bytes.Buffer 92 | entry.Time = time.Now() 93 | entry.Level = level 94 | entry.Message = msg 95 | 96 | if err := entry.Logger.Hooks.Fire(level, &entry); err != nil { 97 | entry.Logger.mu.Lock() 98 | fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) 99 | entry.Logger.mu.Unlock() 100 | } 101 | buffer = bufferPool.Get().(*bytes.Buffer) 102 | buffer.Reset() 103 | defer bufferPool.Put(buffer) 104 | entry.Buffer = buffer 105 | serialized, err := entry.Logger.Formatter.Format(&entry) 106 | entry.Buffer = nil 107 | if err != nil { 108 | entry.Logger.mu.Lock() 109 | fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) 110 | entry.Logger.mu.Unlock() 111 | } else { 112 | entry.Logger.mu.Lock() 113 | _, err = entry.Logger.Out.Write(serialized) 114 | if err != nil { 115 | fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) 116 | } 117 | entry.Logger.mu.Unlock() 118 | } 119 | 120 | // To avoid Entry#log() returning a value that only would make sense for 121 | // panic() to use in Entry#Panic(), we avoid the allocation by checking 122 | // directly here. 123 | if level <= PanicLevel { 124 | panic(&entry) 125 | } 126 | } 127 | 128 | func (entry *Entry) Debug(args ...interface{}) { 129 | if entry.Logger.Level >= DebugLevel { 130 | entry.log(DebugLevel, fmt.Sprint(args...)) 131 | } 132 | } 133 | 134 | func (entry *Entry) Print(args ...interface{}) { 135 | entry.Info(args...) 136 | } 137 | 138 | func (entry *Entry) Info(args ...interface{}) { 139 | if entry.Logger.Level >= InfoLevel { 140 | entry.log(InfoLevel, fmt.Sprint(args...)) 141 | } 142 | } 143 | 144 | func (entry *Entry) Warn(args ...interface{}) { 145 | if entry.Logger.Level >= WarnLevel { 146 | entry.log(WarnLevel, fmt.Sprint(args...)) 147 | } 148 | } 149 | 150 | func (entry *Entry) Warning(args ...interface{}) { 151 | entry.Warn(args...) 152 | } 153 | 154 | func (entry *Entry) Error(args ...interface{}) { 155 | if entry.Logger.Level >= ErrorLevel { 156 | entry.log(ErrorLevel, fmt.Sprint(args...)) 157 | } 158 | } 159 | 160 | func (entry *Entry) Fatal(args ...interface{}) { 161 | if entry.Logger.Level >= FatalLevel { 162 | entry.log(FatalLevel, fmt.Sprint(args...)) 163 | } 164 | Exit(1) 165 | } 166 | 167 | func (entry *Entry) Panic(args ...interface{}) { 168 | if entry.Logger.Level >= PanicLevel { 169 | entry.log(PanicLevel, fmt.Sprint(args...)) 170 | } 171 | panic(fmt.Sprint(args...)) 172 | } 173 | 174 | // Entry Printf family functions 175 | 176 | func (entry *Entry) Debugf(format string, args ...interface{}) { 177 | if entry.Logger.Level >= DebugLevel { 178 | entry.Debug(fmt.Sprintf(format, args...)) 179 | } 180 | } 181 | 182 | func (entry *Entry) Infof(format string, args ...interface{}) { 183 | if entry.Logger.Level >= InfoLevel { 184 | entry.Info(fmt.Sprintf(format, args...)) 185 | } 186 | } 187 | 188 | func (entry *Entry) Printf(format string, args ...interface{}) { 189 | entry.Infof(format, args...) 190 | } 191 | 192 | func (entry *Entry) Warnf(format string, args ...interface{}) { 193 | if entry.Logger.Level >= WarnLevel { 194 | entry.Warn(fmt.Sprintf(format, args...)) 195 | } 196 | } 197 | 198 | func (entry *Entry) Warningf(format string, args ...interface{}) { 199 | entry.Warnf(format, args...) 200 | } 201 | 202 | func (entry *Entry) Errorf(format string, args ...interface{}) { 203 | if entry.Logger.Level >= ErrorLevel { 204 | entry.Error(fmt.Sprintf(format, args...)) 205 | } 206 | } 207 | 208 | func (entry *Entry) Fatalf(format string, args ...interface{}) { 209 | if entry.Logger.Level >= FatalLevel { 210 | entry.Fatal(fmt.Sprintf(format, args...)) 211 | } 212 | Exit(1) 213 | } 214 | 215 | func (entry *Entry) Panicf(format string, args ...interface{}) { 216 | if entry.Logger.Level >= PanicLevel { 217 | entry.Panic(fmt.Sprintf(format, args...)) 218 | } 219 | } 220 | 221 | // Entry Println family functions 222 | 223 | func (entry *Entry) Debugln(args ...interface{}) { 224 | if entry.Logger.Level >= DebugLevel { 225 | entry.Debug(entry.sprintlnn(args...)) 226 | } 227 | } 228 | 229 | func (entry *Entry) Infoln(args ...interface{}) { 230 | if entry.Logger.Level >= InfoLevel { 231 | entry.Info(entry.sprintlnn(args...)) 232 | } 233 | } 234 | 235 | func (entry *Entry) Println(args ...interface{}) { 236 | entry.Infoln(args...) 237 | } 238 | 239 | func (entry *Entry) Warnln(args ...interface{}) { 240 | if entry.Logger.Level >= WarnLevel { 241 | entry.Warn(entry.sprintlnn(args...)) 242 | } 243 | } 244 | 245 | func (entry *Entry) Warningln(args ...interface{}) { 246 | entry.Warnln(args...) 247 | } 248 | 249 | func (entry *Entry) Errorln(args ...interface{}) { 250 | if entry.Logger.Level >= ErrorLevel { 251 | entry.Error(entry.sprintlnn(args...)) 252 | } 253 | } 254 | 255 | func (entry *Entry) Fatalln(args ...interface{}) { 256 | if entry.Logger.Level >= FatalLevel { 257 | entry.Fatal(entry.sprintlnn(args...)) 258 | } 259 | Exit(1) 260 | } 261 | 262 | func (entry *Entry) Panicln(args ...interface{}) { 263 | if entry.Logger.Level >= PanicLevel { 264 | entry.Panic(entry.sprintlnn(args...)) 265 | } 266 | } 267 | 268 | // Sprintlnn => Sprint no newline. This is to get the behavior of how 269 | // fmt.Sprintln where spaces are always added between operands, regardless of 270 | // their type. Instead of vendoring the Sprintln implementation to spare a 271 | // string allocation, we do the simplest thing. 272 | func (entry *Entry) sprintlnn(args ...interface{}) string { 273 | msg := fmt.Sprintln(args...) 274 | return msg[:len(msg)-1] 275 | } 276 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/exported.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | var ( 8 | // std is the name of the standard logger in stdlib `log` 9 | std = New() 10 | ) 11 | 12 | func StandardLogger() *Logger { 13 | return std 14 | } 15 | 16 | // SetOutput sets the standard logger output. 17 | func SetOutput(out io.Writer) { 18 | std.mu.Lock() 19 | defer std.mu.Unlock() 20 | std.Out = out 21 | } 22 | 23 | // SetFormatter sets the standard logger formatter. 24 | func SetFormatter(formatter Formatter) { 25 | std.mu.Lock() 26 | defer std.mu.Unlock() 27 | std.Formatter = formatter 28 | } 29 | 30 | // SetLevel sets the standard logger level. 31 | func SetLevel(level Level) { 32 | std.mu.Lock() 33 | defer std.mu.Unlock() 34 | std.Level = level 35 | } 36 | 37 | // GetLevel returns the standard logger level. 38 | func GetLevel() Level { 39 | std.mu.Lock() 40 | defer std.mu.Unlock() 41 | return std.Level 42 | } 43 | 44 | // AddHook adds a hook to the standard logger hooks. 45 | func AddHook(hook Hook) { 46 | std.mu.Lock() 47 | defer std.mu.Unlock() 48 | std.Hooks.Add(hook) 49 | } 50 | 51 | // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. 52 | func WithError(err error) *Entry { 53 | return std.WithField(ErrorKey, err) 54 | } 55 | 56 | // WithField creates an entry from the standard logger and adds a field to 57 | // it. If you want multiple fields, use `WithFields`. 58 | // 59 | // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal 60 | // or Panic on the Entry it returns. 61 | func WithField(key string, value interface{}) *Entry { 62 | return std.WithField(key, value) 63 | } 64 | 65 | // WithFields creates an entry from the standard logger and adds multiple 66 | // fields to it. This is simply a helper for `WithField`, invoking it 67 | // once for each field. 68 | // 69 | // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal 70 | // or Panic on the Entry it returns. 71 | func WithFields(fields Fields) *Entry { 72 | return std.WithFields(fields) 73 | } 74 | 75 | // Debug logs a message at level Debug on the standard logger. 76 | func Debug(args ...interface{}) { 77 | std.Debug(args...) 78 | } 79 | 80 | // Print logs a message at level Info on the standard logger. 81 | func Print(args ...interface{}) { 82 | std.Print(args...) 83 | } 84 | 85 | // Info logs a message at level Info on the standard logger. 86 | func Info(args ...interface{}) { 87 | std.Info(args...) 88 | } 89 | 90 | // Warn logs a message at level Warn on the standard logger. 91 | func Warn(args ...interface{}) { 92 | std.Warn(args...) 93 | } 94 | 95 | // Warning logs a message at level Warn on the standard logger. 96 | func Warning(args ...interface{}) { 97 | std.Warning(args...) 98 | } 99 | 100 | // Error logs a message at level Error on the standard logger. 101 | func Error(args ...interface{}) { 102 | std.Error(args...) 103 | } 104 | 105 | // Panic logs a message at level Panic on the standard logger. 106 | func Panic(args ...interface{}) { 107 | std.Panic(args...) 108 | } 109 | 110 | // Fatal logs a message at level Fatal on the standard logger. 111 | func Fatal(args ...interface{}) { 112 | std.Fatal(args...) 113 | } 114 | 115 | // Debugf logs a message at level Debug on the standard logger. 116 | func Debugf(format string, args ...interface{}) { 117 | std.Debugf(format, args...) 118 | } 119 | 120 | // Printf logs a message at level Info on the standard logger. 121 | func Printf(format string, args ...interface{}) { 122 | std.Printf(format, args...) 123 | } 124 | 125 | // Infof logs a message at level Info on the standard logger. 126 | func Infof(format string, args ...interface{}) { 127 | std.Infof(format, args...) 128 | } 129 | 130 | // Warnf logs a message at level Warn on the standard logger. 131 | func Warnf(format string, args ...interface{}) { 132 | std.Warnf(format, args...) 133 | } 134 | 135 | // Warningf logs a message at level Warn on the standard logger. 136 | func Warningf(format string, args ...interface{}) { 137 | std.Warningf(format, args...) 138 | } 139 | 140 | // Errorf logs a message at level Error on the standard logger. 141 | func Errorf(format string, args ...interface{}) { 142 | std.Errorf(format, args...) 143 | } 144 | 145 | // Panicf logs a message at level Panic on the standard logger. 146 | func Panicf(format string, args ...interface{}) { 147 | std.Panicf(format, args...) 148 | } 149 | 150 | // Fatalf logs a message at level Fatal on the standard logger. 151 | func Fatalf(format string, args ...interface{}) { 152 | std.Fatalf(format, args...) 153 | } 154 | 155 | // Debugln logs a message at level Debug on the standard logger. 156 | func Debugln(args ...interface{}) { 157 | std.Debugln(args...) 158 | } 159 | 160 | // Println logs a message at level Info on the standard logger. 161 | func Println(args ...interface{}) { 162 | std.Println(args...) 163 | } 164 | 165 | // Infoln logs a message at level Info on the standard logger. 166 | func Infoln(args ...interface{}) { 167 | std.Infoln(args...) 168 | } 169 | 170 | // Warnln logs a message at level Warn on the standard logger. 171 | func Warnln(args ...interface{}) { 172 | std.Warnln(args...) 173 | } 174 | 175 | // Warningln logs a message at level Warn on the standard logger. 176 | func Warningln(args ...interface{}) { 177 | std.Warningln(args...) 178 | } 179 | 180 | // Errorln logs a message at level Error on the standard logger. 181 | func Errorln(args ...interface{}) { 182 | std.Errorln(args...) 183 | } 184 | 185 | // Panicln logs a message at level Panic on the standard logger. 186 | func Panicln(args ...interface{}) { 187 | std.Panicln(args...) 188 | } 189 | 190 | // Fatalln logs a message at level Fatal on the standard logger. 191 | func Fatalln(args ...interface{}) { 192 | std.Fatalln(args...) 193 | } 194 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/formatter.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import "time" 4 | 5 | const DefaultTimestampFormat = time.RFC3339 6 | 7 | // The Formatter interface is used to implement a custom Formatter. It takes an 8 | // `Entry`. It exposes all the fields, including the default ones: 9 | // 10 | // * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. 11 | // * `entry.Data["time"]`. The timestamp. 12 | // * `entry.Data["level"]. The level the entry was logged at. 13 | // 14 | // Any additional fields added with `WithField` or `WithFields` are also in 15 | // `entry.Data`. Format is expected to return an array of bytes which are then 16 | // logged to `logger.Out`. 17 | type Formatter interface { 18 | Format(*Entry) ([]byte, error) 19 | } 20 | 21 | // This is to not silently overwrite `time`, `msg` and `level` fields when 22 | // dumping it. If this code wasn't there doing: 23 | // 24 | // logrus.WithField("level", 1).Info("hello") 25 | // 26 | // Would just silently drop the user provided level. Instead with this code 27 | // it'll logged as: 28 | // 29 | // {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} 30 | // 31 | // It's not exported because it's still using Data in an opinionated way. It's to 32 | // avoid code duplication between the two default formatters. 33 | func prefixFieldClashes(data Fields) { 34 | if t, ok := data["time"]; ok { 35 | data["fields.time"] = t 36 | } 37 | 38 | if m, ok := data["msg"]; ok { 39 | data["fields.msg"] = m 40 | } 41 | 42 | if l, ok := data["level"]; ok { 43 | data["fields.level"] = l 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/hooks.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | // A hook to be fired when logging on the logging levels returned from 4 | // `Levels()` on your implementation of the interface. Note that this is not 5 | // fired in a goroutine or a channel with workers, you should handle such 6 | // functionality yourself if your call is non-blocking and you don't wish for 7 | // the logging calls for levels returned from `Levels()` to block. 8 | type Hook interface { 9 | Levels() []Level 10 | Fire(*Entry) error 11 | } 12 | 13 | // Internal type for storing the hooks on a logger instance. 14 | type LevelHooks map[Level][]Hook 15 | 16 | // Add a hook to an instance of logger. This is called with 17 | // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. 18 | func (hooks LevelHooks) Add(hook Hook) { 19 | for _, level := range hook.Levels() { 20 | hooks[level] = append(hooks[level], hook) 21 | } 22 | } 23 | 24 | // Fire all the hooks for the passed level. Used by `entry.log` to fire 25 | // appropriate hooks for a log entry. 26 | func (hooks LevelHooks) Fire(level Level, entry *Entry) error { 27 | for _, hook := range hooks[level] { 28 | if err := hook.Fire(entry); err != nil { 29 | return err 30 | } 31 | } 32 | 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/json_formatter.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type JSONFormatter struct { 9 | // TimestampFormat sets the format used for marshaling timestamps. 10 | TimestampFormat string 11 | } 12 | 13 | func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { 14 | data := make(Fields, len(entry.Data)+3) 15 | for k, v := range entry.Data { 16 | switch v := v.(type) { 17 | case error: 18 | // Otherwise errors are ignored by `encoding/json` 19 | // https://github.com/Sirupsen/logrus/issues/137 20 | data[k] = v.Error() 21 | default: 22 | data[k] = v 23 | } 24 | } 25 | prefixFieldClashes(data) 26 | 27 | timestampFormat := f.TimestampFormat 28 | if timestampFormat == "" { 29 | timestampFormat = DefaultTimestampFormat 30 | } 31 | 32 | data["time"] = entry.Time.Format(timestampFormat) 33 | data["msg"] = entry.Message 34 | data["level"] = entry.Level.String() 35 | 36 | serialized, err := json.Marshal(data) 37 | if err != nil { 38 | return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) 39 | } 40 | return append(serialized, '\n'), nil 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/logrus.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "strings" 7 | ) 8 | 9 | // Fields type, used to pass to `WithFields`. 10 | type Fields map[string]interface{} 11 | 12 | // Level type 13 | type Level uint8 14 | 15 | // Convert the Level to a string. E.g. PanicLevel becomes "panic". 16 | func (level Level) String() string { 17 | switch level { 18 | case DebugLevel: 19 | return "debug" 20 | case InfoLevel: 21 | return "info" 22 | case WarnLevel: 23 | return "warning" 24 | case ErrorLevel: 25 | return "error" 26 | case FatalLevel: 27 | return "fatal" 28 | case PanicLevel: 29 | return "panic" 30 | } 31 | 32 | return "unknown" 33 | } 34 | 35 | // ParseLevel takes a string level and returns the Logrus log level constant. 36 | func ParseLevel(lvl string) (Level, error) { 37 | switch strings.ToLower(lvl) { 38 | case "panic": 39 | return PanicLevel, nil 40 | case "fatal": 41 | return FatalLevel, nil 42 | case "error": 43 | return ErrorLevel, nil 44 | case "warn", "warning": 45 | return WarnLevel, nil 46 | case "info": 47 | return InfoLevel, nil 48 | case "debug": 49 | return DebugLevel, nil 50 | } 51 | 52 | var l Level 53 | return l, fmt.Errorf("not a valid logrus Level: %q", lvl) 54 | } 55 | 56 | // A constant exposing all logging levels 57 | var AllLevels = []Level{ 58 | PanicLevel, 59 | FatalLevel, 60 | ErrorLevel, 61 | WarnLevel, 62 | InfoLevel, 63 | DebugLevel, 64 | } 65 | 66 | // These are the different logging levels. You can set the logging level to log 67 | // on your instance of logger, obtained with `logrus.New()`. 68 | const ( 69 | // PanicLevel level, highest level of severity. Logs and then calls panic with the 70 | // message passed to Debug, Info, ... 71 | PanicLevel Level = iota 72 | // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the 73 | // logging level is set to Panic. 74 | FatalLevel 75 | // ErrorLevel level. Logs. Used for errors that should definitely be noted. 76 | // Commonly used for hooks to send errors to an error tracking service. 77 | ErrorLevel 78 | // WarnLevel level. Non-critical entries that deserve eyes. 79 | WarnLevel 80 | // InfoLevel level. General operational entries about what's going on inside the 81 | // application. 82 | InfoLevel 83 | // DebugLevel level. Usually only enabled when debugging. Very verbose logging. 84 | DebugLevel 85 | ) 86 | 87 | // Won't compile if StdLogger can't be realized by a log.Logger 88 | var ( 89 | _ StdLogger = &log.Logger{} 90 | _ StdLogger = &Entry{} 91 | _ StdLogger = &Logger{} 92 | ) 93 | 94 | // StdLogger is what your logrus-enabled library should take, that way 95 | // it'll accept a stdlib logger and a logrus logger. There's no standard 96 | // interface, this is the closest we get, unfortunately. 97 | type StdLogger interface { 98 | Print(...interface{}) 99 | Printf(string, ...interface{}) 100 | Println(...interface{}) 101 | 102 | Fatal(...interface{}) 103 | Fatalf(string, ...interface{}) 104 | Fatalln(...interface{}) 105 | 106 | Panic(...interface{}) 107 | Panicf(string, ...interface{}) 108 | Panicln(...interface{}) 109 | } 110 | 111 | // The FieldLogger interface generalizes the Entry and Logger types 112 | type FieldLogger interface { 113 | WithField(key string, value interface{}) *Entry 114 | WithFields(fields Fields) *Entry 115 | WithError(err error) *Entry 116 | 117 | Debugf(format string, args ...interface{}) 118 | Infof(format string, args ...interface{}) 119 | Printf(format string, args ...interface{}) 120 | Warnf(format string, args ...interface{}) 121 | Warningf(format string, args ...interface{}) 122 | Errorf(format string, args ...interface{}) 123 | Fatalf(format string, args ...interface{}) 124 | Panicf(format string, args ...interface{}) 125 | 126 | Debug(args ...interface{}) 127 | Info(args ...interface{}) 128 | Print(args ...interface{}) 129 | Warn(args ...interface{}) 130 | Warning(args ...interface{}) 131 | Error(args ...interface{}) 132 | Fatal(args ...interface{}) 133 | Panic(args ...interface{}) 134 | 135 | Debugln(args ...interface{}) 136 | Infoln(args ...interface{}) 137 | Println(args ...interface{}) 138 | Warnln(args ...interface{}) 139 | Warningln(args ...interface{}) 140 | Errorln(args ...interface{}) 141 | Fatalln(args ...interface{}) 142 | Panicln(args ...interface{}) 143 | } 144 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_appengine.go: -------------------------------------------------------------------------------- 1 | // +build appengine 2 | 3 | package logrus 4 | 5 | // IsTerminal returns true if stderr's file descriptor is a terminal. 6 | func IsTerminal() bool { 7 | return true 8 | } 9 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_bsd.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd openbsd netbsd dragonfly 2 | // +build !appengine 3 | 4 | package logrus 5 | 6 | import "syscall" 7 | 8 | const ioctlReadTermios = syscall.TIOCGETA 9 | 10 | type Termios syscall.Termios 11 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_linux.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build !appengine 7 | 8 | package logrus 9 | 10 | import "syscall" 11 | 12 | const ioctlReadTermios = syscall.TCGETS 13 | 14 | type Termios syscall.Termios 15 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_notwindows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build linux darwin freebsd openbsd netbsd dragonfly 7 | // +build !appengine 8 | 9 | package logrus 10 | 11 | import ( 12 | "syscall" 13 | "unsafe" 14 | ) 15 | 16 | // IsTerminal returns true if stderr's file descriptor is a terminal. 17 | func IsTerminal() bool { 18 | fd := syscall.Stderr 19 | var termios Termios 20 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 21 | return err == 0 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris,!appengine 2 | 3 | package logrus 4 | 5 | import ( 6 | "os" 7 | 8 | "golang.org/x/sys/unix" 9 | ) 10 | 11 | // IsTerminal returns true if the given file descriptor is a terminal. 12 | func IsTerminal() bool { 13 | _, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TCGETA) 14 | return err == nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_windows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build windows,!appengine 7 | 8 | package logrus 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | var kernel32 = syscall.NewLazyDLL("kernel32.dll") 16 | 17 | var ( 18 | procGetConsoleMode = kernel32.NewProc("GetConsoleMode") 19 | ) 20 | 21 | // IsTerminal returns true if stderr's file descriptor is a terminal. 22 | func IsTerminal() bool { 23 | fd := syscall.Stderr 24 | var st uint32 25 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0) 26 | return r != 0 && e == 0 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/text_formatter.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "runtime" 7 | "sort" 8 | "strings" 9 | "time" 10 | ) 11 | 12 | const ( 13 | nocolor = 0 14 | red = 31 15 | green = 32 16 | yellow = 33 17 | blue = 34 18 | gray = 37 19 | ) 20 | 21 | var ( 22 | baseTimestamp time.Time 23 | isTerminal bool 24 | ) 25 | 26 | func init() { 27 | baseTimestamp = time.Now() 28 | isTerminal = IsTerminal() 29 | } 30 | 31 | func miniTS() int { 32 | return int(time.Since(baseTimestamp) / time.Second) 33 | } 34 | 35 | type TextFormatter struct { 36 | // Set to true to bypass checking for a TTY before outputting colors. 37 | ForceColors bool 38 | 39 | // Force disabling colors. 40 | DisableColors bool 41 | 42 | // Disable timestamp logging. useful when output is redirected to logging 43 | // system that already adds timestamps. 44 | DisableTimestamp bool 45 | 46 | // Enable logging the full timestamp when a TTY is attached instead of just 47 | // the time passed since beginning of execution. 48 | FullTimestamp bool 49 | 50 | // TimestampFormat to use for display when a full timestamp is printed 51 | TimestampFormat string 52 | 53 | // The fields are sorted by default for a consistent output. For applications 54 | // that log extremely frequently and don't use the JSON formatter this may not 55 | // be desired. 56 | DisableSorting bool 57 | } 58 | 59 | func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { 60 | var b *bytes.Buffer 61 | var keys []string = make([]string, 0, len(entry.Data)) 62 | for k := range entry.Data { 63 | keys = append(keys, k) 64 | } 65 | 66 | if !f.DisableSorting { 67 | sort.Strings(keys) 68 | } 69 | if entry.Buffer != nil { 70 | b = entry.Buffer 71 | } else { 72 | b = &bytes.Buffer{} 73 | } 74 | 75 | prefixFieldClashes(entry.Data) 76 | 77 | isColorTerminal := isTerminal && (runtime.GOOS != "windows") 78 | isColored := (f.ForceColors || isColorTerminal) && !f.DisableColors 79 | 80 | timestampFormat := f.TimestampFormat 81 | if timestampFormat == "" { 82 | timestampFormat = DefaultTimestampFormat 83 | } 84 | if isColored { 85 | f.printColored(b, entry, keys, timestampFormat) 86 | } else { 87 | if !f.DisableTimestamp { 88 | f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat)) 89 | } 90 | f.appendKeyValue(b, "level", entry.Level.String()) 91 | if entry.Message != "" { 92 | f.appendKeyValue(b, "msg", entry.Message) 93 | } 94 | for _, key := range keys { 95 | f.appendKeyValue(b, key, entry.Data[key]) 96 | } 97 | } 98 | 99 | b.WriteByte('\n') 100 | return b.Bytes(), nil 101 | } 102 | 103 | func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, timestampFormat string) { 104 | var levelColor int 105 | switch entry.Level { 106 | case DebugLevel: 107 | levelColor = gray 108 | case WarnLevel: 109 | levelColor = yellow 110 | case ErrorLevel, FatalLevel, PanicLevel: 111 | levelColor = red 112 | default: 113 | levelColor = blue 114 | } 115 | 116 | levelText := strings.ToUpper(entry.Level.String())[0:4] 117 | 118 | if !f.FullTimestamp { 119 | fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message) 120 | } else { 121 | fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) 122 | } 123 | for _, k := range keys { 124 | v := entry.Data[k] 125 | fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) 126 | f.appendValue(b, v) 127 | } 128 | } 129 | 130 | func needsQuoting(text string) bool { 131 | for _, ch := range text { 132 | if !((ch >= 'a' && ch <= 'z') || 133 | (ch >= 'A' && ch <= 'Z') || 134 | (ch >= '0' && ch <= '9') || 135 | ch == '-' || ch == '.') { 136 | return true 137 | } 138 | } 139 | return false 140 | } 141 | 142 | func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { 143 | 144 | b.WriteString(key) 145 | b.WriteByte('=') 146 | f.appendValue(b, value) 147 | b.WriteByte(' ') 148 | } 149 | 150 | func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { 151 | switch value := value.(type) { 152 | case string: 153 | if !needsQuoting(value) { 154 | b.WriteString(value) 155 | } else { 156 | fmt.Fprintf(b, "%q", value) 157 | } 158 | case error: 159 | errmsg := value.Error() 160 | if !needsQuoting(errmsg) { 161 | b.WriteString(errmsg) 162 | } else { 163 | fmt.Fprintf(b, "%q", errmsg) 164 | } 165 | default: 166 | fmt.Fprint(b, value) 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/writer.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "runtime" 7 | ) 8 | 9 | func (logger *Logger) Writer() *io.PipeWriter { 10 | return logger.WriterLevel(InfoLevel) 11 | } 12 | 13 | func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { 14 | reader, writer := io.Pipe() 15 | 16 | var printFunc func(args ...interface{}) 17 | switch level { 18 | case DebugLevel: 19 | printFunc = logger.Debug 20 | case InfoLevel: 21 | printFunc = logger.Info 22 | case WarnLevel: 23 | printFunc = logger.Warn 24 | case ErrorLevel: 25 | printFunc = logger.Error 26 | case FatalLevel: 27 | printFunc = logger.Fatal 28 | case PanicLevel: 29 | printFunc = logger.Panic 30 | default: 31 | printFunc = logger.Print 32 | } 33 | 34 | go logger.writerScanner(reader, printFunc) 35 | runtime.SetFinalizer(writer, writerFinalizer) 36 | 37 | return writer 38 | } 39 | 40 | func (logger *Logger) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { 41 | scanner := bufio.NewScanner(reader) 42 | for scanner.Scan() { 43 | printFunc(scanner.Text()) 44 | } 45 | if err := scanner.Err(); err != nil { 46 | logger.Errorf("Error while reading from Writer: %s", err) 47 | } 48 | reader.Close() 49 | } 50 | 51 | func writerFinalizer(writer *io.PipeWriter) { 52 | writer.Close() 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/files.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation implements primitives for systemd socket activation. 16 | package activation 17 | 18 | import ( 19 | "os" 20 | "strconv" 21 | "syscall" 22 | ) 23 | 24 | // based on: https://gist.github.com/alberts/4640792 25 | const ( 26 | listenFdsStart = 3 27 | ) 28 | 29 | func Files(unsetEnv bool) []*os.File { 30 | if unsetEnv { 31 | defer os.Unsetenv("LISTEN_PID") 32 | defer os.Unsetenv("LISTEN_FDS") 33 | } 34 | 35 | pid, err := strconv.Atoi(os.Getenv("LISTEN_PID")) 36 | if err != nil || pid != os.Getpid() { 37 | return nil 38 | } 39 | 40 | nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS")) 41 | if err != nil || nfds == 0 { 42 | return nil 43 | } 44 | 45 | files := make([]*os.File, 0, nfds) 46 | for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ { 47 | syscall.CloseOnExec(fd) 48 | files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_"+strconv.Itoa(fd))) 49 | } 50 | 51 | return files 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/listeners.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation 16 | 17 | import ( 18 | "crypto/tls" 19 | "net" 20 | ) 21 | 22 | // Listeners returns a slice containing a net.Listener for each matching socket type 23 | // passed to this process. 24 | // 25 | // The order of the file descriptors is preserved in the returned slice. 26 | // Nil values are used to fill any gaps. For example if systemd were to return file descriptors 27 | // corresponding with "udp, tcp, tcp", then the slice would contain {nil, net.Listener, net.Listener} 28 | func Listeners(unsetEnv bool) ([]net.Listener, error) { 29 | files := Files(unsetEnv) 30 | listeners := make([]net.Listener, len(files)) 31 | 32 | for i, f := range files { 33 | if pc, err := net.FileListener(f); err == nil { 34 | listeners[i] = pc 35 | } 36 | } 37 | return listeners, nil 38 | } 39 | 40 | // TLSListeners returns a slice containing a net.listener for each matching TCP socket type 41 | // passed to this process. 42 | // It uses default Listeners func and forces TCP sockets handlers to use TLS based on tlsConfig. 43 | func TLSListeners(unsetEnv bool, tlsConfig *tls.Config) ([]net.Listener, error) { 44 | listeners, err := Listeners(unsetEnv) 45 | 46 | if listeners == nil || err != nil { 47 | return nil, err 48 | } 49 | 50 | if tlsConfig != nil && err == nil { 51 | for i, l := range listeners { 52 | // Activate TLS only for TCP sockets 53 | if l.Addr().Network() == "tcp" { 54 | listeners[i] = tls.NewListener(l, tlsConfig) 55 | } 56 | } 57 | } 58 | 59 | return listeners, err 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/packetconns.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation 16 | 17 | import ( 18 | "net" 19 | ) 20 | 21 | // PacketConns returns a slice containing a net.PacketConn for each matching socket type 22 | // passed to this process. 23 | // 24 | // The order of the file descriptors is preserved in the returned slice. 25 | // Nil values are used to fill any gaps. For example if systemd were to return file descriptors 26 | // corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn} 27 | func PacketConns(unsetEnv bool) ([]net.PacketConn, error) { 28 | files := Files(unsetEnv) 29 | conns := make([]net.PacketConn, len(files)) 30 | 31 | for i, f := range files { 32 | if pc, err := net.FilePacketConn(f); err == nil { 33 | conns[i] = pc 34 | } 35 | } 36 | return conns, nil 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/util/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 util contains utility functions related to systemd that applications 16 | // can use to check things like whether systemd is running. Note that some of 17 | // these functions attempt to manually load systemd libraries at runtime rather 18 | // than linking against them. 19 | package util 20 | 21 | import ( 22 | "fmt" 23 | "io/ioutil" 24 | "os" 25 | "strings" 26 | ) 27 | 28 | var ( 29 | ErrNoCGO = fmt.Errorf("go-systemd built with CGO disabled") 30 | ) 31 | 32 | // GetRunningSlice attempts to retrieve the name of the systemd slice in which 33 | // the current process is running. 34 | // This function is a wrapper around the libsystemd C library; if it cannot be 35 | // opened, an error is returned. 36 | func GetRunningSlice() (string, error) { 37 | return getRunningSlice() 38 | } 39 | 40 | // RunningFromSystemService tries to detect whether the current process has 41 | // been invoked from a system service. The condition for this is whether the 42 | // process is _not_ a user process. User processes are those running in session 43 | // scopes or under per-user `systemd --user` instances. 44 | // 45 | // To avoid false positives on systems without `pam_systemd` (which is 46 | // responsible for creating user sessions), this function also uses a heuristic 47 | // to detect whether it's being invoked from a session leader process. This is 48 | // the case if the current process is executed directly from a service file 49 | // (e.g. with `ExecStart=/this/cmd`). Note that this heuristic will fail if the 50 | // command is instead launched in a subshell or similar so that it is not 51 | // session leader (e.g. `ExecStart=/bin/bash -c "/this/cmd"`) 52 | // 53 | // This function is a wrapper around the libsystemd C library; if this is 54 | // unable to successfully open a handle to the library for any reason (e.g. it 55 | // cannot be found), an error will be returned. 56 | func RunningFromSystemService() (bool, error) { 57 | return runningFromSystemService() 58 | } 59 | 60 | // CurrentUnitName attempts to retrieve the name of the systemd system unit 61 | // from which the calling process has been invoked. It wraps the systemd 62 | // `sd_pid_get_unit` call, with the same caveat: for processes not part of a 63 | // systemd system unit, this function will return an error. 64 | func CurrentUnitName() (string, error) { 65 | return currentUnitName() 66 | } 67 | 68 | // IsRunningSystemd checks whether the host was booted with systemd as its init 69 | // system. This functions similarly to systemd's `sd_booted(3)`: internally, it 70 | // checks whether /run/systemd/system/ exists and is a directory. 71 | // http://www.freedesktop.org/software/systemd/man/sd_booted.html 72 | func IsRunningSystemd() bool { 73 | fi, err := os.Lstat("/run/systemd/system") 74 | if err != nil { 75 | return false 76 | } 77 | return fi.IsDir() 78 | } 79 | 80 | // GetMachineID returns a host's 128-bit machine ID as a string. This functions 81 | // similarly to systemd's `sd_id128_get_machine`: internally, it simply reads 82 | // the contents of /etc/machine-id 83 | // http://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html 84 | func GetMachineID() (string, error) { 85 | machineID, err := ioutil.ReadFile("/etc/machine-id") 86 | if err != nil { 87 | return "", fmt.Errorf("failed to read /etc/machine-id: %v", err) 88 | } 89 | return strings.TrimSpace(string(machineID)), nil 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/util/util_cgo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CoreOS, Inc. 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 | // +build cgo 16 | 17 | package util 18 | 19 | // #include 20 | // #include 21 | // #include 22 | // 23 | // int 24 | // my_sd_pid_get_owner_uid(void *f, pid_t pid, uid_t *uid) 25 | // { 26 | // int (*sd_pid_get_owner_uid)(pid_t, uid_t *); 27 | // 28 | // sd_pid_get_owner_uid = (int (*)(pid_t, uid_t *))f; 29 | // return sd_pid_get_owner_uid(pid, uid); 30 | // } 31 | // 32 | // int 33 | // my_sd_pid_get_unit(void *f, pid_t pid, char **unit) 34 | // { 35 | // int (*sd_pid_get_unit)(pid_t, char **); 36 | // 37 | // sd_pid_get_unit = (int (*)(pid_t, char **))f; 38 | // return sd_pid_get_unit(pid, unit); 39 | // } 40 | // 41 | // int 42 | // my_sd_pid_get_slice(void *f, pid_t pid, char **slice) 43 | // { 44 | // int (*sd_pid_get_slice)(pid_t, char **); 45 | // 46 | // sd_pid_get_slice = (int (*)(pid_t, char **))f; 47 | // return sd_pid_get_slice(pid, slice); 48 | // } 49 | // 50 | // int 51 | // am_session_leader() 52 | // { 53 | // return (getsid(0) == getpid()); 54 | // } 55 | import "C" 56 | import ( 57 | "fmt" 58 | "syscall" 59 | "unsafe" 60 | 61 | "github.com/coreos/pkg/dlopen" 62 | ) 63 | 64 | var libsystemdNames = []string{ 65 | // systemd < 209 66 | "libsystemd-login.so.0", 67 | "libsystemd-login.so", 68 | 69 | // systemd >= 209 merged libsystemd-login into libsystemd proper 70 | "libsystemd.so.0", 71 | "libsystemd.so", 72 | } 73 | 74 | func getRunningSlice() (slice string, err error) { 75 | var h *dlopen.LibHandle 76 | h, err = dlopen.GetHandle(libsystemdNames) 77 | if err != nil { 78 | return 79 | } 80 | defer func() { 81 | if err1 := h.Close(); err1 != nil { 82 | err = err1 83 | } 84 | }() 85 | 86 | sd_pid_get_slice, err := h.GetSymbolPointer("sd_pid_get_slice") 87 | if err != nil { 88 | return 89 | } 90 | 91 | var s string 92 | sl := C.CString(s) 93 | defer C.free(unsafe.Pointer(sl)) 94 | 95 | ret := C.my_sd_pid_get_slice(sd_pid_get_slice, 0, &sl) 96 | if ret < 0 { 97 | err = fmt.Errorf("error calling sd_pid_get_slice: %v", syscall.Errno(-ret)) 98 | return 99 | } 100 | 101 | return C.GoString(sl), nil 102 | } 103 | 104 | func runningFromSystemService() (ret bool, err error) { 105 | var h *dlopen.LibHandle 106 | h, err = dlopen.GetHandle(libsystemdNames) 107 | if err != nil { 108 | return 109 | } 110 | defer func() { 111 | if err1 := h.Close(); err1 != nil { 112 | err = err1 113 | } 114 | }() 115 | 116 | sd_pid_get_owner_uid, err := h.GetSymbolPointer("sd_pid_get_owner_uid") 117 | if err != nil { 118 | return 119 | } 120 | 121 | var uid C.uid_t 122 | errno := C.my_sd_pid_get_owner_uid(sd_pid_get_owner_uid, 0, &uid) 123 | serrno := syscall.Errno(-errno) 124 | // when we're running from a unit file, sd_pid_get_owner_uid returns 125 | // ENOENT (systemd <220) or ENXIO (systemd >=220) 126 | switch { 127 | case errno >= 0: 128 | ret = false 129 | case serrno == syscall.ENOENT, serrno == syscall.ENXIO: 130 | // Since the implementation of sessions in systemd relies on 131 | // the `pam_systemd` module, using the sd_pid_get_owner_uid 132 | // heuristic alone can result in false positives if that module 133 | // (or PAM itself) is not present or properly configured on the 134 | // system. As such, we also check if we're the session leader, 135 | // which should be the case if we're invoked from a unit file, 136 | // but not if e.g. we're invoked from the command line from a 137 | // user's login session 138 | ret = C.am_session_leader() == 1 139 | default: 140 | err = fmt.Errorf("error calling sd_pid_get_owner_uid: %v", syscall.Errno(-errno)) 141 | } 142 | return 143 | } 144 | 145 | func currentUnitName() (unit string, err error) { 146 | var h *dlopen.LibHandle 147 | h, err = dlopen.GetHandle(libsystemdNames) 148 | if err != nil { 149 | return 150 | } 151 | defer func() { 152 | if err1 := h.Close(); err1 != nil { 153 | err = err1 154 | } 155 | }() 156 | 157 | sd_pid_get_unit, err := h.GetSymbolPointer("sd_pid_get_unit") 158 | if err != nil { 159 | return 160 | } 161 | 162 | var s string 163 | u := C.CString(s) 164 | defer C.free(unsafe.Pointer(u)) 165 | 166 | ret := C.my_sd_pid_get_unit(sd_pid_get_unit, 0, &u) 167 | if ret < 0 { 168 | err = fmt.Errorf("error calling sd_pid_get_unit: %v", syscall.Errno(-ret)) 169 | return 170 | } 171 | 172 | unit = C.GoString(u) 173 | return 174 | } 175 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/util/util_stub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CoreOS, Inc. 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 | // +build !cgo 16 | 17 | package util 18 | 19 | func getRunningSlice() (string, error) { return "", ErrNoCGO } 20 | 21 | func runningFromSystemService() (bool, error) { return false, ErrNoCGO } 22 | 23 | func currentUnitName() (string, error) { return "", ErrNoCGO } 24 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/pkg/NOTICE: -------------------------------------------------------------------------------- 1 | CoreOS Project 2 | Copyright 2014 CoreOS, Inc 3 | 4 | This product includes software developed at CoreOS, Inc. 5 | (http://www.coreos.com/). 6 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/pkg/dlopen/dlopen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CoreOS, Inc. 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 dlopen provides some convenience functions to dlopen a library and 16 | // get its symbols. 17 | package dlopen 18 | 19 | // #cgo LDFLAGS: -ldl 20 | // #include 21 | // #include 22 | import "C" 23 | import ( 24 | "errors" 25 | "fmt" 26 | "unsafe" 27 | ) 28 | 29 | var ErrSoNotFound = errors.New("unable to open a handle to the library") 30 | 31 | // LibHandle represents an open handle to a library (.so) 32 | type LibHandle struct { 33 | Handle unsafe.Pointer 34 | Libname string 35 | } 36 | 37 | // GetHandle tries to get a handle to a library (.so), attempting to access it 38 | // by the names specified in libs and returning the first that is successfully 39 | // opened. Callers are responsible for closing the handler. If no library can 40 | // be successfully opened, an error is returned. 41 | func GetHandle(libs []string) (*LibHandle, error) { 42 | for _, name := range libs { 43 | libname := C.CString(name) 44 | defer C.free(unsafe.Pointer(libname)) 45 | handle := C.dlopen(libname, C.RTLD_LAZY) 46 | if handle != nil { 47 | h := &LibHandle{ 48 | Handle: handle, 49 | Libname: name, 50 | } 51 | return h, nil 52 | } 53 | } 54 | return nil, ErrSoNotFound 55 | } 56 | 57 | // GetSymbolPointer takes a symbol name and returns a pointer to the symbol. 58 | func (l *LibHandle) GetSymbolPointer(symbol string) (unsafe.Pointer, error) { 59 | sym := C.CString(symbol) 60 | defer C.free(unsafe.Pointer(sym)) 61 | 62 | C.dlerror() 63 | p := C.dlsym(l.Handle, sym) 64 | e := C.dlerror() 65 | if e != nil { 66 | return nil, fmt.Errorf("error resolving symbol %q: %v", symbol, errors.New(C.GoString(e))) 67 | } 68 | 69 | return p, nil 70 | } 71 | 72 | // Close closes a LibHandle. 73 | func (l *LibHandle) Close() error { 74 | C.dlerror() 75 | C.dlclose(l.Handle) 76 | e := C.dlerror() 77 | if e != nil { 78 | return fmt.Errorf("error closing %v: %v", l.Libname, errors.New(C.GoString(e))) 79 | } 80 | 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/pkg/dlopen/dlopen_example.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 | // +build linux 16 | 17 | package dlopen 18 | 19 | // #include 20 | // #include 21 | // 22 | // int 23 | // my_strlen(void *f, const char *s) 24 | // { 25 | // size_t (*strlen)(const char *); 26 | // 27 | // strlen = (size_t (*)(const char *))f; 28 | // return strlen(s); 29 | // } 30 | import "C" 31 | 32 | import ( 33 | "fmt" 34 | "unsafe" 35 | ) 36 | 37 | func strlen(libs []string, s string) (int, error) { 38 | h, err := GetHandle(libs) 39 | if err != nil { 40 | return -1, fmt.Errorf(`couldn't get a handle to the library: %v`, err) 41 | } 42 | defer h.Close() 43 | 44 | f := "strlen" 45 | cs := C.CString(s) 46 | defer C.free(unsafe.Pointer(cs)) 47 | 48 | strlen, err := h.GetSymbolPointer(f) 49 | if err != nil { 50 | return -1, fmt.Errorf(`couldn't get symbol %q: %v`, f, err) 51 | } 52 | 53 | len := C.my_strlen(strlen, cs) 54 | 55 | return int(len), nil 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/inmem_socket.go: -------------------------------------------------------------------------------- 1 | package sockets 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "sync" 7 | ) 8 | 9 | var errClosed = errors.New("use of closed network connection") 10 | 11 | // InmemSocket implements net.Listener using in-memory only connections. 12 | type InmemSocket struct { 13 | chConn chan net.Conn 14 | chClose chan struct{} 15 | addr string 16 | mu sync.Mutex 17 | } 18 | 19 | // dummyAddr is used to satisfy net.Addr for the in-mem socket 20 | // it is just stored as a string and returns the string for all calls 21 | type dummyAddr string 22 | 23 | // NewInmemSocket creates an in-memory only net.Listener 24 | // The addr argument can be any string, but is used to satisfy the `Addr()` part 25 | // of the net.Listener interface 26 | func NewInmemSocket(addr string, bufSize int) *InmemSocket { 27 | return &InmemSocket{ 28 | chConn: make(chan net.Conn, bufSize), 29 | chClose: make(chan struct{}), 30 | addr: addr, 31 | } 32 | } 33 | 34 | // Addr returns the socket's addr string to satisfy net.Listener 35 | func (s *InmemSocket) Addr() net.Addr { 36 | return dummyAddr(s.addr) 37 | } 38 | 39 | // Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn. 40 | func (s *InmemSocket) Accept() (net.Conn, error) { 41 | select { 42 | case conn := <-s.chConn: 43 | return conn, nil 44 | case <-s.chClose: 45 | return nil, errClosed 46 | } 47 | } 48 | 49 | // Close closes the listener. It will be unavailable for use once closed. 50 | func (s *InmemSocket) Close() error { 51 | s.mu.Lock() 52 | defer s.mu.Unlock() 53 | select { 54 | case <-s.chClose: 55 | default: 56 | close(s.chClose) 57 | } 58 | return nil 59 | } 60 | 61 | // Dial is used to establish a connection with the in-mem server 62 | func (s *InmemSocket) Dial(network, addr string) (net.Conn, error) { 63 | srvConn, clientConn := net.Pipe() 64 | select { 65 | case s.chConn <- srvConn: 66 | case <-s.chClose: 67 | return nil, errClosed 68 | } 69 | 70 | return clientConn, nil 71 | } 72 | 73 | // Network returns the addr string, satisfies net.Addr 74 | func (a dummyAddr) Network() string { 75 | return string(a) 76 | } 77 | 78 | // String returns the string form 79 | func (a dummyAddr) String() string { 80 | return string(a) 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/proxy.go: -------------------------------------------------------------------------------- 1 | package sockets 2 | 3 | import ( 4 | "net" 5 | "net/url" 6 | "os" 7 | "strings" 8 | 9 | "golang.org/x/net/proxy" 10 | ) 11 | 12 | // GetProxyEnv allows access to the uppercase and the lowercase forms of 13 | // proxy-related variables. See the Go specification for details on these 14 | // variables. https://golang.org/pkg/net/http/ 15 | func GetProxyEnv(key string) string { 16 | proxyValue := os.Getenv(strings.ToUpper(key)) 17 | if proxyValue == "" { 18 | return os.Getenv(strings.ToLower(key)) 19 | } 20 | return proxyValue 21 | } 22 | 23 | // DialerFromEnvironment takes in a "direct" *net.Dialer and returns a 24 | // proxy.Dialer which will route the connections through the proxy using the 25 | // given dialer. 26 | func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) { 27 | allProxy := GetProxyEnv("all_proxy") 28 | if len(allProxy) == 0 { 29 | return direct, nil 30 | } 31 | 32 | proxyURL, err := url.Parse(allProxy) 33 | if err != nil { 34 | return direct, err 35 | } 36 | 37 | proxyFromURL, err := proxy.FromURL(proxyURL, direct) 38 | if err != nil { 39 | return direct, err 40 | } 41 | 42 | noProxy := GetProxyEnv("no_proxy") 43 | if len(noProxy) == 0 { 44 | return proxyFromURL, nil 45 | } 46 | 47 | perHost := proxy.NewPerHost(proxyFromURL, direct) 48 | perHost.AddFromString(noProxy) 49 | 50 | return perHost, nil 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/sockets.go: -------------------------------------------------------------------------------- 1 | // Package sockets provides helper functions to create and configure Unix or TCP sockets. 2 | package sockets 3 | 4 | import ( 5 | "errors" 6 | "net" 7 | "net/http" 8 | "time" 9 | ) 10 | 11 | // Why 32? See https://github.com/docker/docker/pull/8035. 12 | const defaultTimeout = 32 * time.Second 13 | 14 | // ErrProtocolNotAvailable is returned when a given transport protocol is not provided by the operating system. 15 | var ErrProtocolNotAvailable = errors.New("protocol not available") 16 | 17 | // ConfigureTransport configures the specified Transport according to the 18 | // specified proto and addr. 19 | // If the proto is unix (using a unix socket to communicate) or npipe the 20 | // compression is disabled. 21 | func ConfigureTransport(tr *http.Transport, proto, addr string) error { 22 | switch proto { 23 | case "unix": 24 | return configureUnixTransport(tr, proto, addr) 25 | case "npipe": 26 | return configureNpipeTransport(tr, proto, addr) 27 | default: 28 | tr.Proxy = http.ProxyFromEnvironment 29 | dialer, err := DialerFromEnvironment(&net.Dialer{ 30 | Timeout: defaultTimeout, 31 | }) 32 | if err != nil { 33 | return err 34 | } 35 | tr.Dial = dialer.Dial 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/sockets_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package sockets 4 | 5 | import ( 6 | "fmt" 7 | "net" 8 | "net/http" 9 | "syscall" 10 | "time" 11 | ) 12 | 13 | const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path) 14 | 15 | func configureUnixTransport(tr *http.Transport, proto, addr string) error { 16 | if len(addr) > maxUnixSocketPathSize { 17 | return fmt.Errorf("Unix socket path %q is too long", addr) 18 | } 19 | // No need for compression in local communications. 20 | tr.DisableCompression = true 21 | tr.Dial = func(_, _ string) (net.Conn, error) { 22 | return net.DialTimeout(proto, addr, defaultTimeout) 23 | } 24 | return nil 25 | } 26 | 27 | func configureNpipeTransport(tr *http.Transport, proto, addr string) error { 28 | return ErrProtocolNotAvailable 29 | } 30 | 31 | // DialPipe connects to a Windows named pipe. 32 | // This is not supported on other OSes. 33 | func DialPipe(_ string, _ time.Duration) (net.Conn, error) { 34 | return nil, syscall.EAFNOSUPPORT 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/sockets_windows.go: -------------------------------------------------------------------------------- 1 | package sockets 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/Microsoft/go-winio" 9 | ) 10 | 11 | func configureUnixTransport(tr *http.Transport, proto, addr string) error { 12 | return ErrProtocolNotAvailable 13 | } 14 | 15 | func configureNpipeTransport(tr *http.Transport, proto, addr string) error { 16 | // No need for compression in local communications. 17 | tr.DisableCompression = true 18 | tr.Dial = func(_, _ string) (net.Conn, error) { 19 | return DialPipe(addr, defaultTimeout) 20 | } 21 | return nil 22 | } 23 | 24 | // DialPipe connects to a Windows named pipe. 25 | func DialPipe(addr string, timeout time.Duration) (net.Conn, error) { 26 | return winio.DialPipe(addr, &timeout) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/tcp_socket.go: -------------------------------------------------------------------------------- 1 | // Package sockets provides helper functions to create and configure Unix or TCP sockets. 2 | package sockets 3 | 4 | import ( 5 | "crypto/tls" 6 | "net" 7 | ) 8 | 9 | // NewTCPSocket creates a TCP socket listener with the specified address and 10 | // the specified tls configuration. If TLSConfig is set, will encapsulate the 11 | // TCP listener inside a TLS one. 12 | func NewTCPSocket(addr string, tlsConfig *tls.Config) (net.Listener, error) { 13 | l, err := net.Listen("tcp", addr) 14 | if err != nil { 15 | return nil, err 16 | } 17 | if tlsConfig != nil { 18 | tlsConfig.NextProtos = []string{"http/1.1"} 19 | l = tls.NewListener(l, tlsConfig) 20 | } 21 | return l, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-connections/sockets/unix_socket.go: -------------------------------------------------------------------------------- 1 | // +build linux freebsd solaris 2 | 3 | package sockets 4 | 5 | import ( 6 | "fmt" 7 | "net" 8 | "os" 9 | "strconv" 10 | "syscall" 11 | 12 | "github.com/Sirupsen/logrus" 13 | "github.com/opencontainers/runc/libcontainer/user" 14 | ) 15 | 16 | // NewUnixSocket creates a unix socket with the specified path and group. 17 | func NewUnixSocket(path, group string) (net.Listener, error) { 18 | if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) { 19 | return nil, err 20 | } 21 | mask := syscall.Umask(0777) 22 | defer syscall.Umask(mask) 23 | l, err := net.Listen("unix", path) 24 | if err != nil { 25 | return nil, err 26 | } 27 | if err := setSocketGroup(path, group); err != nil { 28 | l.Close() 29 | return nil, err 30 | } 31 | if err := os.Chmod(path, 0660); err != nil { 32 | l.Close() 33 | return nil, err 34 | } 35 | return l, nil 36 | } 37 | 38 | func setSocketGroup(path, group string) error { 39 | if group == "" { 40 | return nil 41 | } 42 | if err := changeGroup(path, group); err != nil { 43 | if group != "docker" { 44 | return err 45 | } 46 | logrus.Debugf("Warning: could not change group %s to docker: %v", path, err) 47 | } 48 | return nil 49 | } 50 | 51 | func changeGroup(path string, nameOrGid string) error { 52 | gid, err := lookupGidByName(nameOrGid) 53 | if err != nil { 54 | return err 55 | } 56 | logrus.Debugf("%s group found. gid: %d", nameOrGid, gid) 57 | return os.Chown(path, 0, gid) 58 | } 59 | 60 | func lookupGidByName(nameOrGid string) (int, error) { 61 | groupFile, err := user.GetGroupPath() 62 | if err != nil { 63 | return -1, err 64 | } 65 | groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool { 66 | return g.Name == nameOrGid || strconv.Itoa(g.Gid) == nameOrGid 67 | }) 68 | if err != nil { 69 | return -1, err 70 | } 71 | if groups != nil && len(groups) > 0 { 72 | return groups[0].Gid, nil 73 | } 74 | gid, err := strconv.Atoi(nameOrGid) 75 | if err == nil { 76 | logrus.Warnf("Could not find GID %d", gid) 77 | return gid, nil 78 | } 79 | return -1, fmt.Errorf("Group %s not found", nameOrGid) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/NOTICE: -------------------------------------------------------------------------------- 1 | Docker 2 | Copyright 2012-2015 Docker, Inc. 3 | 4 | This product includes software developed at Docker, Inc. (https://www.docker.com). 5 | 6 | This product contains software (https://github.com/kr/pty) developed 7 | by Keith Rarick, licensed under the MIT License. 8 | 9 | The following is courtesy of our legal counsel: 10 | 11 | 12 | Use and transfer of Docker may be subject to certain restrictions by the 13 | United States and other governments. 14 | It is your responsibility to ensure that your use and/or transfer does not 15 | violate applicable laws. 16 | 17 | For more information, please see https://www.bis.doc.gov 18 | 19 | See also https://www.apache.org/dev/crypto.html and/or seek legal counsel. 20 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/sdk/encoder.go: -------------------------------------------------------------------------------- 1 | package sdk 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io" 7 | "io/ioutil" 8 | "net/http" 9 | ) 10 | 11 | // DefaultContentTypeV1_1 is the default content type accepted and sent by the plugins. 12 | const DefaultContentTypeV1_1 = "application/vnd.docker.plugins.v1.1+json" 13 | 14 | // DecodeRequest decodes an http request into a given structure. 15 | func DecodeRequest(w http.ResponseWriter, r *http.Request, req interface{}) (err error) { 16 | if err = json.NewDecoder(r.Body).Decode(req); err != nil { 17 | http.Error(w, err.Error(), http.StatusBadRequest) 18 | } 19 | return 20 | } 21 | 22 | // EncodeResponse encodes the given structure into an http response. 23 | func EncodeResponse(w http.ResponseWriter, res interface{}, err string) { 24 | w.Header().Set("Content-Type", DefaultContentTypeV1_1) 25 | if err != "" { 26 | w.WriteHeader(http.StatusInternalServerError) 27 | } 28 | json.NewEncoder(w).Encode(res) 29 | } 30 | 31 | // StreamResponse streams a response object to the client 32 | func StreamResponse(w http.ResponseWriter, data io.ReadCloser) { 33 | w.Header().Set("Content-Type", DefaultContentTypeV1_1) 34 | defer data.Close() 35 | byteStream, err := ioutil.ReadAll(data) 36 | if err != nil { 37 | fmt.Printf("ERROR in stream: %v\n", err) 38 | return 39 | } 40 | w.Write(byteStream) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/sdk/handler.go: -------------------------------------------------------------------------------- 1 | package sdk 2 | 3 | import ( 4 | "crypto/tls" 5 | "fmt" 6 | "net" 7 | "net/http" 8 | "os" 9 | ) 10 | 11 | const activatePath = "/Plugin.Activate" 12 | 13 | // Handler is the base to create plugin handlers. 14 | // It initializes connections and sockets to listen to. 15 | type Handler struct { 16 | mux *http.ServeMux 17 | } 18 | 19 | // NewHandler creates a new Handler with an http mux. 20 | func NewHandler(manifest string) Handler { 21 | mux := http.NewServeMux() 22 | 23 | mux.HandleFunc(activatePath, func(w http.ResponseWriter, r *http.Request) { 24 | w.Header().Set("Content-Type", DefaultContentTypeV1_1) 25 | fmt.Fprintln(w, manifest) 26 | }) 27 | 28 | return Handler{mux: mux} 29 | } 30 | 31 | // Serve sets up the handler to serve requests on the passed in listener 32 | func (h Handler) Serve(l net.Listener) error { 33 | server := http.Server{ 34 | Addr: l.Addr().String(), 35 | Handler: h.mux, 36 | } 37 | return server.Serve(l) 38 | } 39 | 40 | // ServeTCP makes the handler to listen for request in a given TCP address. 41 | // It also writes the spec file on the right directory for docker to read. 42 | func (h Handler) ServeTCP(pluginName, addr string, tlsConfig *tls.Config) error { 43 | return h.listenAndServe("tcp", addr, pluginName, tlsConfig) 44 | } 45 | 46 | // ServeUnix makes the handler to listen for requests in a unix socket. 47 | // It also creates the socket file on the right directory for docker to read. 48 | func (h Handler) ServeUnix(systemGroup, addr string) error { 49 | return h.listenAndServe("unix", addr, systemGroup, nil) 50 | } 51 | 52 | // HandleFunc registers a function to handle a request path with. 53 | func (h Handler) HandleFunc(path string, fn func(w http.ResponseWriter, r *http.Request)) { 54 | h.mux.HandleFunc(path, fn) 55 | } 56 | 57 | func (h Handler) listenAndServe(proto, addr, group string, tlsConfig *tls.Config) error { 58 | var ( 59 | err error 60 | spec string 61 | l net.Listener 62 | ) 63 | 64 | server := http.Server{ 65 | Addr: addr, 66 | Handler: h.mux, 67 | } 68 | 69 | switch proto { 70 | case "tcp": 71 | l, spec, err = newTCPListener(addr, group, tlsConfig) 72 | case "unix": 73 | l, spec, err = newUnixListener(addr, group) 74 | } 75 | 76 | if spec != "" { 77 | defer os.Remove(spec) 78 | } 79 | if err != nil { 80 | return err 81 | } 82 | 83 | return server.Serve(l) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/sdk/tcp_listener.go: -------------------------------------------------------------------------------- 1 | package sdk 2 | 3 | import ( 4 | "crypto/tls" 5 | "io/ioutil" 6 | "net" 7 | "os" 8 | "path/filepath" 9 | 10 | "github.com/docker/go-connections/sockets" 11 | ) 12 | 13 | const ( 14 | pluginSpecDir = "/etc/docker/plugins" 15 | ) 16 | 17 | func newTCPListener(address string, pluginName string, tlsConfig *tls.Config) (net.Listener, string, error) { 18 | listener, err := sockets.NewTCPSocket(address, tlsConfig) 19 | if err != nil { 20 | return nil, "", err 21 | } 22 | spec, err := writeSpec(pluginName, listener.Addr().String()) 23 | if err != nil { 24 | return nil, "", err 25 | } 26 | return listener, spec, nil 27 | } 28 | 29 | func writeSpec(name string, address string) (string, error) { 30 | if err := os.MkdirAll(pluginSpecDir, 0755); err != nil { 31 | return "", err 32 | } 33 | spec := filepath.Join(pluginSpecDir, name+".spec") 34 | url := "tcp://" + address 35 | if err := ioutil.WriteFile(spec, []byte(url), 0644); err != nil { 36 | return "", err 37 | } 38 | return spec, nil 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/sdk/unix_listener.go: -------------------------------------------------------------------------------- 1 | // +build linux freebsd 2 | 3 | package sdk 4 | 5 | import ( 6 | "fmt" 7 | "net" 8 | "os" 9 | "path/filepath" 10 | 11 | "github.com/coreos/go-systemd/activation" 12 | "github.com/coreos/go-systemd/util" 13 | "github.com/docker/go-connections/sockets" 14 | ) 15 | 16 | const ( 17 | pluginSockDir = "/run/docker/plugins" 18 | ) 19 | 20 | func newUnixListener(pluginName string, group string) (net.Listener, string, error) { 21 | path, err := fullSocketAddress(pluginName) 22 | if err != nil { 23 | return nil, "", err 24 | } 25 | listener, err := setupSocketActivation() 26 | if err != nil { 27 | return nil, "", err 28 | } 29 | if listener == nil { 30 | listener, err = sockets.NewUnixSocket(path, group) 31 | if err != nil { 32 | return nil, "", err 33 | } 34 | } 35 | return listener, path, nil 36 | } 37 | 38 | func fullSocketAddress(address string) (string, error) { 39 | if err := os.MkdirAll(pluginSockDir, 0755); err != nil { 40 | return "", err 41 | } 42 | if filepath.IsAbs(address) { 43 | return address, nil 44 | } 45 | return filepath.Join(pluginSockDir, address+".sock"), nil 46 | } 47 | 48 | func setupSocketActivation() (net.Listener, error) { 49 | if !util.IsRunningSystemd() { 50 | return nil, nil 51 | } 52 | listenFds := activation.Files(false) 53 | if len(listenFds) > 1 { 54 | return nil, fmt.Errorf("expected only one socket from systemd, got %d", len(listenFds)) 55 | } 56 | var listener net.Listener 57 | if len(listenFds) == 1 { 58 | l, err := net.FileListener(listenFds[0]) 59 | if err != nil { 60 | return nil, err 61 | } 62 | listener = l 63 | } 64 | return listener, nil 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/sdk/unix_listener_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!freebsd 2 | 3 | package sdk 4 | 5 | import ( 6 | "errors" 7 | "net" 8 | ) 9 | 10 | var ( 11 | errOnlySupportedOnLinuxAndFreeBSD = errors.New("unix socket creation is only supported on linux and freebsd") 12 | ) 13 | 14 | func newUnixListener(pluginName string, group string) (net.Listener, string, error) { 15 | return nil, "", errOnlySupportedOnLinuxAndFreeBSD 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-plugins-helpers/volume/api.go: -------------------------------------------------------------------------------- 1 | package volume 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/docker/go-plugins-helpers/sdk" 7 | ) 8 | 9 | const ( 10 | // DefaultDockerRootDirectory is the default directory where volumes will be created. 11 | DefaultDockerRootDirectory = "/var/lib/docker-volumes" 12 | 13 | manifest = `{"Implements": ["VolumeDriver"]}` 14 | createPath = "/VolumeDriver.Create" 15 | getPath = "/VolumeDriver.Get" 16 | listPath = "/VolumeDriver.List" 17 | removePath = "/VolumeDriver.Remove" 18 | hostVirtualPath = "/VolumeDriver.Path" 19 | mountPath = "/VolumeDriver.Mount" 20 | unmountPath = "/VolumeDriver.Unmount" 21 | capabilitiesPath = "/VolumeDriver.Capabilities" 22 | ) 23 | 24 | // Request is the structure that docker's requests are deserialized to. 25 | type Request struct { 26 | Name string 27 | Options map[string]string `json:"Opts,omitempty"` 28 | } 29 | 30 | // MountRequest structure for a volume mount request 31 | type MountRequest struct { 32 | Name string 33 | ID string 34 | } 35 | 36 | // UnmountRequest structure for a volume unmount request 37 | type UnmountRequest struct { 38 | Name string 39 | ID string 40 | } 41 | 42 | // Response is the strucutre that the plugin's responses are serialized to. 43 | type Response struct { 44 | Mountpoint string 45 | Err string 46 | Volumes []*Volume 47 | Volume *Volume 48 | Capabilities Capability 49 | } 50 | 51 | // Volume represents a volume object for use with `Get` and `List` requests 52 | type Volume struct { 53 | Name string 54 | Mountpoint string 55 | Status map[string]interface{} 56 | } 57 | 58 | // Capability represents the list of capabilities a volume driver can return 59 | type Capability struct { 60 | Scope string 61 | } 62 | 63 | // Driver represent the interface a driver must fulfill. 64 | type Driver interface { 65 | Create(Request) Response 66 | List(Request) Response 67 | Get(Request) Response 68 | Remove(Request) Response 69 | Path(Request) Response 70 | Mount(MountRequest) Response 71 | Unmount(UnmountRequest) Response 72 | Capabilities(Request) Response 73 | } 74 | 75 | // Handler forwards requests and responses between the docker daemon and the plugin. 76 | type Handler struct { 77 | driver Driver 78 | sdk.Handler 79 | } 80 | 81 | type actionHandler func(Request) Response 82 | type mountActionHandler func(MountRequest) Response 83 | type unmountActionHandler func(UnmountRequest) Response 84 | 85 | // NewHandler initializes the request handler with a driver implementation. 86 | func NewHandler(driver Driver) *Handler { 87 | h := &Handler{driver, sdk.NewHandler(manifest)} 88 | h.initMux() 89 | return h 90 | } 91 | 92 | func (h *Handler) initMux() { 93 | h.handle(createPath, func(req Request) Response { 94 | return h.driver.Create(req) 95 | }) 96 | 97 | h.handle(getPath, func(req Request) Response { 98 | return h.driver.Get(req) 99 | }) 100 | 101 | h.handle(listPath, func(req Request) Response { 102 | return h.driver.List(req) 103 | }) 104 | 105 | h.handle(removePath, func(req Request) Response { 106 | return h.driver.Remove(req) 107 | }) 108 | 109 | h.handle(hostVirtualPath, func(req Request) Response { 110 | return h.driver.Path(req) 111 | }) 112 | 113 | h.handleMount(mountPath, func(req MountRequest) Response { 114 | return h.driver.Mount(req) 115 | }) 116 | 117 | h.handleUnmount(unmountPath, func(req UnmountRequest) Response { 118 | return h.driver.Unmount(req) 119 | }) 120 | h.handle(capabilitiesPath, func(req Request) Response { 121 | return h.driver.Capabilities(req) 122 | }) 123 | } 124 | 125 | func (h *Handler) handle(name string, actionCall actionHandler) { 126 | h.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) { 127 | var req Request 128 | if err := sdk.DecodeRequest(w, r, &req); err != nil { 129 | return 130 | } 131 | 132 | res := actionCall(req) 133 | 134 | sdk.EncodeResponse(w, res, res.Err) 135 | }) 136 | } 137 | 138 | func (h *Handler) handleMount(name string, actionCall mountActionHandler) { 139 | h.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) { 140 | var req MountRequest 141 | if err := sdk.DecodeRequest(w, r, &req); err != nil { 142 | return 143 | } 144 | 145 | res := actionCall(req) 146 | sdk.EncodeResponse(w, res, res.Err) 147 | }) 148 | } 149 | 150 | func (h *Handler) handleUnmount(name string, actionCall unmountActionHandler) { 151 | h.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) { 152 | var req UnmountRequest 153 | if err := sdk.DecodeRequest(w, r, &req); err != nil { 154 | return 155 | } 156 | 157 | res := actionCall(req) 158 | sdk.EncodeResponse(w, res, res.Err) 159 | }) 160 | } 161 | -------------------------------------------------------------------------------- /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/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/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/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/github.com/opencontainers/runc/NOTICE: -------------------------------------------------------------------------------- 1 | runc 2 | 3 | Copyright 2012-2015 Docker, Inc. 4 | 5 | This product includes software developed at Docker, Inc. (http://www.docker.com). 6 | 7 | The following is courtesy of our legal counsel: 8 | 9 | 10 | Use and transfer of Docker may be subject to certain restrictions by the 11 | United States and other governments. 12 | It is your responsibility to ensure that your use and/or transfer does not 13 | violate applicable laws. 14 | 15 | For more information, please see http://www.bis.doc.gov 16 | 17 | See also http://www.apache.org/dev/crypto.html and/or seek legal counsel. 18 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/nsenter/namespace.h: -------------------------------------------------------------------------------- 1 | #ifndef NSENTER_NAMESPACE_H 2 | #define NSENTER_NAMESPACE_H 3 | 4 | #ifndef _GNU_SOURCE 5 | # define _GNU_SOURCE 6 | #endif 7 | #include 8 | 9 | /* All of these are taken from include/uapi/linux/sched.h */ 10 | #ifndef CLONE_NEWNS 11 | # define CLONE_NEWNS 0x00020000 /* New mount namespace group */ 12 | #endif 13 | #ifndef CLONE_NEWCGROUP 14 | # define CLONE_NEWCGROUP 0x02000000 /* New cgroup namespace */ 15 | #endif 16 | #ifndef CLONE_NEWUTS 17 | # define CLONE_NEWUTS 0x04000000 /* New utsname namespace */ 18 | #endif 19 | #ifndef CLONE_NEWIPC 20 | # define CLONE_NEWIPC 0x08000000 /* New ipc namespace */ 21 | #endif 22 | #ifndef CLONE_NEWUSER 23 | # define CLONE_NEWUSER 0x10000000 /* New user namespace */ 24 | #endif 25 | #ifndef CLONE_NEWPID 26 | # define CLONE_NEWPID 0x20000000 /* New pid namespace */ 27 | #endif 28 | #ifndef CLONE_NEWNET 29 | # define CLONE_NEWNET 0x40000000 /* New network namespace */ 30 | #endif 31 | 32 | #endif /* NSENTER_NAMESPACE_H */ 33 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/nsenter/nsenter.go: -------------------------------------------------------------------------------- 1 | // +build linux,!gccgo 2 | 3 | package nsenter 4 | 5 | /* 6 | #cgo CFLAGS: -Wall 7 | extern void nsexec(); 8 | void __attribute__((constructor)) init(void) { 9 | nsexec(); 10 | } 11 | */ 12 | import "C" 13 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/nsenter/nsenter_gccgo.go: -------------------------------------------------------------------------------- 1 | // +build linux,gccgo 2 | 3 | package nsenter 4 | 5 | /* 6 | #cgo CFLAGS: -Wall 7 | extern void nsexec(); 8 | void __attribute__((constructor)) init(void) { 9 | nsexec(); 10 | } 11 | */ 12 | import "C" 13 | 14 | // AlwaysFalse is here to stay false 15 | // (and be exported so the compiler doesn't optimize out its reference) 16 | var AlwaysFalse bool 17 | 18 | func init() { 19 | if AlwaysFalse { 20 | // by referencing this C init() in a noop test, it will ensure the compiler 21 | // links in the C function. 22 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65134 23 | C.init() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/nsenter/nsenter_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux !cgo 2 | 3 | package nsenter 4 | 5 | import "C" 6 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/user/lookup.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "errors" 5 | "syscall" 6 | ) 7 | 8 | var ( 9 | // The current operating system does not provide the required data for user lookups. 10 | ErrUnsupported = errors.New("user lookup: operating system does not provide passwd-formatted data") 11 | // No matching entries found in file. 12 | ErrNoPasswdEntries = errors.New("no matching entries in passwd file") 13 | ErrNoGroupEntries = errors.New("no matching entries in group file") 14 | ) 15 | 16 | func lookupUser(filter func(u User) bool) (User, error) { 17 | // Get operating system-specific passwd reader-closer. 18 | passwd, err := GetPasswd() 19 | if err != nil { 20 | return User{}, err 21 | } 22 | defer passwd.Close() 23 | 24 | // Get the users. 25 | users, err := ParsePasswdFilter(passwd, filter) 26 | if err != nil { 27 | return User{}, err 28 | } 29 | 30 | // No user entries found. 31 | if len(users) == 0 { 32 | return User{}, ErrNoPasswdEntries 33 | } 34 | 35 | // Assume the first entry is the "correct" one. 36 | return users[0], nil 37 | } 38 | 39 | // CurrentUser looks up the current user by their user id in /etc/passwd. If the 40 | // user cannot be found (or there is no /etc/passwd file on the filesystem), 41 | // then CurrentUser returns an error. 42 | func CurrentUser() (User, error) { 43 | return LookupUid(syscall.Getuid()) 44 | } 45 | 46 | // LookupUser looks up a user by their username in /etc/passwd. If the user 47 | // cannot be found (or there is no /etc/passwd file on the filesystem), then 48 | // LookupUser returns an error. 49 | func LookupUser(username string) (User, error) { 50 | return lookupUser(func(u User) bool { 51 | return u.Name == username 52 | }) 53 | } 54 | 55 | // LookupUid looks up a user by their user id in /etc/passwd. If the user cannot 56 | // be found (or there is no /etc/passwd file on the filesystem), then LookupId 57 | // returns an error. 58 | func LookupUid(uid int) (User, error) { 59 | return lookupUser(func(u User) bool { 60 | return u.Uid == uid 61 | }) 62 | } 63 | 64 | func lookupGroup(filter func(g Group) bool) (Group, error) { 65 | // Get operating system-specific group reader-closer. 66 | group, err := GetGroup() 67 | if err != nil { 68 | return Group{}, err 69 | } 70 | defer group.Close() 71 | 72 | // Get the users. 73 | groups, err := ParseGroupFilter(group, filter) 74 | if err != nil { 75 | return Group{}, err 76 | } 77 | 78 | // No user entries found. 79 | if len(groups) == 0 { 80 | return Group{}, ErrNoGroupEntries 81 | } 82 | 83 | // Assume the first entry is the "correct" one. 84 | return groups[0], nil 85 | } 86 | 87 | // CurrentGroup looks up the current user's group by their primary group id's 88 | // entry in /etc/passwd. If the group cannot be found (or there is no 89 | // /etc/group file on the filesystem), then CurrentGroup returns an error. 90 | func CurrentGroup() (Group, error) { 91 | return LookupGid(syscall.Getgid()) 92 | } 93 | 94 | // LookupGroup looks up a group by its name in /etc/group. If the group cannot 95 | // be found (or there is no /etc/group file on the filesystem), then LookupGroup 96 | // returns an error. 97 | func LookupGroup(groupname string) (Group, error) { 98 | return lookupGroup(func(g Group) bool { 99 | return g.Name == groupname 100 | }) 101 | } 102 | 103 | // LookupGid looks up a group by its group id in /etc/group. If the group cannot 104 | // be found (or there is no /etc/group file on the filesystem), then LookupGid 105 | // returns an error. 106 | func LookupGid(gid int) (Group, error) { 107 | return lookupGroup(func(g Group) bool { 108 | return g.Gid == gid 109 | }) 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unix.go: -------------------------------------------------------------------------------- 1 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 2 | 3 | package user 4 | 5 | import ( 6 | "io" 7 | "os" 8 | ) 9 | 10 | // Unix-specific path to the passwd and group formatted files. 11 | const ( 12 | unixPasswdPath = "/etc/passwd" 13 | unixGroupPath = "/etc/group" 14 | ) 15 | 16 | func GetPasswdPath() (string, error) { 17 | return unixPasswdPath, nil 18 | } 19 | 20 | func GetPasswd() (io.ReadCloser, error) { 21 | return os.Open(unixPasswdPath) 22 | } 23 | 24 | func GetGroupPath() (string, error) { 25 | return unixGroupPath, nil 26 | } 27 | 28 | func GetGroup() (io.ReadCloser, error) { 29 | return os.Open(unixGroupPath) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris 2 | 3 | package user 4 | 5 | import "io" 6 | 7 | func GetPasswdPath() (string, error) { 8 | return "", ErrUnsupported 9 | } 10 | 11 | func GetPasswd() (io.ReadCloser, error) { 12 | return nil, ErrUnsupported 13 | } 14 | 15 | func GetGroupPath() (string, error) { 16 | return "", ErrUnsupported 17 | } 18 | 19 | func GetGroup() (io.ReadCloser, error) { 20 | return nil, ErrUnsupported 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2013 Steve Francia . 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 | // 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 | // Commands similar to git, go tools and other modern CLI tools 15 | // inspired by go, go-Commander, gh and subcommand 16 | 17 | package cobra 18 | 19 | import ( 20 | "fmt" 21 | "io" 22 | "reflect" 23 | "strconv" 24 | "strings" 25 | "text/template" 26 | "unicode" 27 | ) 28 | 29 | var templateFuncs = template.FuncMap{ 30 | "trim": strings.TrimSpace, 31 | "trimRightSpace": trimRightSpace, 32 | "appendIfNotPresent": appendIfNotPresent, 33 | "rpad": rpad, 34 | "gt": Gt, 35 | "eq": Eq, 36 | } 37 | 38 | var initializers []func() 39 | 40 | // Automatic prefix matching can be a dangerous thing to automatically enable in CLI tools. 41 | // Set this to true to enable it. 42 | var EnablePrefixMatching = false 43 | 44 | // EnableCommandSorting controls sorting of the slice of commands, which is turned on by default. 45 | // To disable sorting, set it to false. 46 | var EnableCommandSorting = true 47 | 48 | // AddTemplateFunc adds a template function that's available to Usage and Help 49 | // template generation. 50 | func AddTemplateFunc(name string, tmplFunc interface{}) { 51 | templateFuncs[name] = tmplFunc 52 | } 53 | 54 | // AddTemplateFuncs adds multiple template functions availalble to Usage and 55 | // Help template generation. 56 | func AddTemplateFuncs(tmplFuncs template.FuncMap) { 57 | for k, v := range tmplFuncs { 58 | templateFuncs[k] = v 59 | } 60 | } 61 | 62 | // OnInitialize takes a series of func() arguments and appends them to a slice of func(). 63 | func OnInitialize(y ...func()) { 64 | initializers = append(initializers, y...) 65 | } 66 | 67 | // Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans, 68 | // Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as 69 | // ints and then compared. 70 | func Gt(a interface{}, b interface{}) bool { 71 | var left, right int64 72 | av := reflect.ValueOf(a) 73 | 74 | switch av.Kind() { 75 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: 76 | left = int64(av.Len()) 77 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 78 | left = av.Int() 79 | case reflect.String: 80 | left, _ = strconv.ParseInt(av.String(), 10, 64) 81 | } 82 | 83 | bv := reflect.ValueOf(b) 84 | 85 | switch bv.Kind() { 86 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: 87 | right = int64(bv.Len()) 88 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 89 | right = bv.Int() 90 | case reflect.String: 91 | right, _ = strconv.ParseInt(bv.String(), 10, 64) 92 | } 93 | 94 | return left > right 95 | } 96 | 97 | // Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic. 98 | func Eq(a interface{}, b interface{}) bool { 99 | av := reflect.ValueOf(a) 100 | bv := reflect.ValueOf(b) 101 | 102 | switch av.Kind() { 103 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: 104 | panic("Eq called on unsupported type") 105 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 106 | return av.Int() == bv.Int() 107 | case reflect.String: 108 | return av.String() == bv.String() 109 | } 110 | return false 111 | } 112 | 113 | func trimRightSpace(s string) string { 114 | return strings.TrimRightFunc(s, unicode.IsSpace) 115 | } 116 | 117 | // appendIfNotPresent will append stringToAppend to the end of s, but only if it's not yet present in s. 118 | func appendIfNotPresent(s, stringToAppend string) string { 119 | if strings.Contains(s, stringToAppend) { 120 | return s 121 | } 122 | return s + " " + stringToAppend 123 | } 124 | 125 | // rpad adds padding to the right of a string. 126 | func rpad(s string, padding int) string { 127 | template := fmt.Sprintf("%%-%ds", padding) 128 | return fmt.Sprintf(template, s) 129 | } 130 | 131 | // tmpl executes the given template text on data, writing the result to w. 132 | func tmpl(w io.Writer, text string, data interface{}) error { 133 | t := template.New("top") 134 | t.Funcs(templateFuncs) 135 | template.Must(t.Parse(text)) 136 | return t.Execute(w, data) 137 | } 138 | 139 | // ld compares two strings and returns the levenshtein distance between them. 140 | func ld(s, t string, ignoreCase bool) int { 141 | if ignoreCase { 142 | s = strings.ToLower(s) 143 | t = strings.ToLower(t) 144 | } 145 | d := make([][]int, len(s)+1) 146 | for i := range d { 147 | d[i] = make([]int, len(t)+1) 148 | } 149 | for i := range d { 150 | d[i][0] = i 151 | } 152 | for j := range d[0] { 153 | d[0][j] = j 154 | } 155 | for j := 1; j <= len(t); j++ { 156 | for i := 1; i <= len(s); i++ { 157 | if s[i-1] == t[j-1] { 158 | d[i][j] = d[i-1][j-1] 159 | } else { 160 | min := d[i-1][j] 161 | if d[i][j-1] < min { 162 | min = d[i][j-1] 163 | } 164 | if d[i-1][j-1] < min { 165 | min = d[i-1][j-1] 166 | } 167 | d[i][j] = min + 1 168 | } 169 | } 170 | 171 | } 172 | return d[len(s)][len(t)] 173 | } 174 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "os" 7 | "time" 8 | 9 | "github.com/inconshreveable/mousetrap" 10 | ) 11 | 12 | var preExecHookFn = preExecHook 13 | 14 | // enables an information splash screen on Windows if the CLI is started from explorer.exe. 15 | var MousetrapHelpText string = `This is a command line tool 16 | 17 | You need to open cmd.exe and run it from there. 18 | ` 19 | 20 | func preExecHook(c *Command) { 21 | if mousetrap.StartedByExplorer() { 22 | c.Print(MousetrapHelpText) 23 | time.Sleep(5 * time.Second) 24 | os.Exit(1) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | // -1 means that no specific value was passed, so increment 16 | if v == -1 { 17 | *i = countValue(*i + 1) 18 | } else { 19 | *i = countValue(v) 20 | } 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "-1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count like Count only the flag is placed on the CommandLine isntead of a given flag set 87 | func Count(name string, usage string) *int { 88 | return CommandLine.CountP(name, "", usage) 89 | } 90 | 91 | // CountP is like Count only takes a shorthand for the flag name. 92 | func CountP(name, shorthand string, usage string) *int { 93 | return CommandLine.CountP(name, shorthand, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 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 pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "fmt" 10 | "reflect" 11 | "strings" 12 | ) 13 | 14 | var _ = fmt.Print 15 | 16 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 17 | // difference here is the addition of the Type method that returns a string 18 | // name of the type. As this is generally unknown, we approximate that with 19 | // reflection. 20 | type flagValueWrapper struct { 21 | inner goflag.Value 22 | flagType string 23 | } 24 | 25 | // We are just copying the boolFlag interface out of goflag as that is what 26 | // they use to decide if a flag should get "true" when no arg is given. 27 | type goBoolFlag interface { 28 | goflag.Value 29 | IsBoolFlag() bool 30 | } 31 | 32 | func wrapFlagValue(v goflag.Value) Value { 33 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 34 | if pv, ok := v.(Value); ok { 35 | return pv 36 | } 37 | 38 | pv := &flagValueWrapper{ 39 | inner: v, 40 | } 41 | 42 | t := reflect.TypeOf(v) 43 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 44 | t = t.Elem() 45 | } 46 | 47 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 48 | return pv 49 | } 50 | 51 | func (v *flagValueWrapper) String() string { 52 | return v.inner.String() 53 | } 54 | 55 | func (v *flagValueWrapper) Set(s string) error { 56 | return v.inner.Set(s) 57 | } 58 | 59 | func (v *flagValueWrapper) Type() string { 60 | return v.flagType 61 | } 62 | 63 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 64 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 65 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 66 | // character (ex: `verbose`) it will only be accessible via `--verbose` 67 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 68 | // Remember the default value as a string; it won't change. 69 | flag := &Flag{ 70 | Name: goflag.Name, 71 | Usage: goflag.Usage, 72 | Value: wrapFlagValue(goflag.Value), 73 | // Looks like golang flags don't set DefValue correctly :-( 74 | //DefValue: goflag.DefValue, 75 | DefValue: goflag.Value.String(), 76 | } 77 | // Ex: if the golang flag was -v, allow both -v and --v to work 78 | if len(flag.Name) == 1 { 79 | flag.Shorthand = flag.Name 80 | } 81 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 82 | flag.NoOptDefVal = "true" 83 | } 84 | return flag 85 | } 86 | 87 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 88 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 89 | if f.Lookup(goflag.Name) != nil { 90 | return 91 | } 92 | newflag := PFlagFromGoFlag(goflag) 93 | f.AddFlag(newflag) 94 | } 95 | 96 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 97 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 98 | if newSet == nil { 99 | return 100 | } 101 | newSet.VisitAll(func(goflag *goflag.Flag) { 102 | f.AddGoFlag(goflag) 103 | }) 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- intSlice Value 10 | type intSliceValue struct { 11 | value *[]int 12 | changed bool 13 | } 14 | 15 | func newIntSliceValue(val []int, p *[]int) *intSliceValue { 16 | isv := new(intSliceValue) 17 | isv.value = p 18 | *isv.value = val 19 | return isv 20 | } 21 | 22 | func (s *intSliceValue) Set(val string) error { 23 | ss := strings.Split(val, ",") 24 | out := make([]int, len(ss)) 25 | for i, d := range ss { 26 | var err error 27 | out[i], err = strconv.Atoi(d) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | } 33 | if !s.changed { 34 | *s.value = out 35 | } else { 36 | *s.value = append(*s.value, out...) 37 | } 38 | s.changed = true 39 | return nil 40 | } 41 | 42 | func (s *intSliceValue) Type() string { 43 | return "intSlice" 44 | } 45 | 46 | func (s *intSliceValue) String() string { 47 | out := make([]string, len(*s.value)) 48 | for i, d := range *s.value { 49 | out[i] = fmt.Sprintf("%d", d) 50 | } 51 | return "[" + strings.Join(out, ",") + "]" 52 | } 53 | 54 | func intSliceConv(val string) (interface{}, error) { 55 | val = strings.Trim(val, "[]") 56 | // Empty string would cause a slice with one (empty) entry 57 | if len(val) == 0 { 58 | return []int{}, nil 59 | } 60 | ss := strings.Split(val, ",") 61 | out := make([]int, len(ss)) 62 | for i, d := range ss { 63 | var err error 64 | out[i], err = strconv.Atoi(d) 65 | if err != nil { 66 | return nil, err 67 | } 68 | 69 | } 70 | return out, nil 71 | } 72 | 73 | // GetIntSlice return the []int value of a flag with the given name 74 | func (f *FlagSet) GetIntSlice(name string) ([]int, error) { 75 | val, err := f.getFlagType(name, "intSlice", intSliceConv) 76 | if err != nil { 77 | return []int{}, err 78 | } 79 | return val.([]int), nil 80 | } 81 | 82 | // IntSliceVar defines a intSlice flag with specified name, default value, and usage string. 83 | // The argument p points to a []int variable in which to store the value of the flag. 84 | func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) { 85 | f.VarP(newIntSliceValue(value, p), name, "", usage) 86 | } 87 | 88 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 89 | func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 90 | f.VarP(newIntSliceValue(value, p), name, shorthand, usage) 91 | } 92 | 93 | // IntSliceVar defines a int[] flag with specified name, default value, and usage string. 94 | // The argument p points to a int[] variable in which to store the value of the flag. 95 | func IntSliceVar(p *[]int, name string, value []int, usage string) { 96 | CommandLine.VarP(newIntSliceValue(value, p), name, "", usage) 97 | } 98 | 99 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 100 | func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 101 | CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage) 102 | } 103 | 104 | // IntSlice defines a []int flag with specified name, default value, and usage string. 105 | // The return value is the address of a []int variable that stores the value of the flag. 106 | func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int { 107 | p := []int{} 108 | f.IntSliceVarP(&p, name, "", value, usage) 109 | return &p 110 | } 111 | 112 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. 113 | func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int { 114 | p := []int{} 115 | f.IntSliceVarP(&p, name, shorthand, value, usage) 116 | return &p 117 | } 118 | 119 | // IntSlice defines a []int flag with specified name, default value, and usage string. 120 | // The return value is the address of a []int variable that stores the value of the flag. 121 | func IntSlice(name string, value []int, usage string) *[]int { 122 | return CommandLine.IntSliceP(name, "", value, usage) 123 | } 124 | 125 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. 126 | func IntSliceP(name, shorthand string, value []int, usage string) *[]int { 127 | return CommandLine.IntSliceP(name, shorthand, value, usage) 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | var _ = strings.TrimSpace 10 | 11 | // -- net.IP value 12 | type ipValue net.IP 13 | 14 | func newIPValue(val net.IP, p *net.IP) *ipValue { 15 | *p = val 16 | return (*ipValue)(p) 17 | } 18 | 19 | func (i *ipValue) String() string { return net.IP(*i).String() } 20 | func (i *ipValue) Set(s string) error { 21 | ip := net.ParseIP(strings.TrimSpace(s)) 22 | if ip == nil { 23 | return fmt.Errorf("failed to parse IP: %q", s) 24 | } 25 | *i = ipValue(ip) 26 | return nil 27 | } 28 | 29 | func (i *ipValue) Type() string { 30 | return "ip" 31 | } 32 | 33 | func ipConv(sval string) (interface{}, error) { 34 | ip := net.ParseIP(sval) 35 | if ip != nil { 36 | return ip, nil 37 | } 38 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 39 | } 40 | 41 | // GetIP return the net.IP value of a flag with the given name 42 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 43 | val, err := f.getFlagType(name, "ip", ipConv) 44 | if err != nil { 45 | return nil, err 46 | } 47 | return val.(net.IP), nil 48 | } 49 | 50 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 51 | // The argument p points to an net.IP variable in which to store the value of the flag. 52 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 53 | f.VarP(newIPValue(value, p), name, "", usage) 54 | } 55 | 56 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 57 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 58 | f.VarP(newIPValue(value, p), name, shorthand, usage) 59 | } 60 | 61 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 62 | // The argument p points to an net.IP variable in which to store the value of the flag. 63 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 64 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 65 | } 66 | 67 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 68 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 69 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 70 | } 71 | 72 | // IP defines an net.IP flag with specified name, default value, and usage string. 73 | // The return value is the address of an net.IP variable that stores the value of the flag. 74 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 75 | p := new(net.IP) 76 | f.IPVarP(p, name, "", value, usage) 77 | return p 78 | } 79 | 80 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 81 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 82 | p := new(net.IP) 83 | f.IPVarP(p, name, shorthand, value, usage) 84 | return p 85 | } 86 | 87 | // IP defines an net.IP flag with specified name, default value, and usage string. 88 | // The return value is the address of an net.IP variable that stores the value of the flag. 89 | func IP(name string, value net.IP, usage string) *net.IP { 90 | return CommandLine.IPP(name, "", value, usage) 91 | } 92 | 93 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 94 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 95 | return CommandLine.IPP(name, shorthand, value, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipmask.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strconv" 7 | ) 8 | 9 | // -- net.IPMask value 10 | type ipMaskValue net.IPMask 11 | 12 | func newIPMaskValue(val net.IPMask, p *net.IPMask) *ipMaskValue { 13 | *p = val 14 | return (*ipMaskValue)(p) 15 | } 16 | 17 | func (i *ipMaskValue) String() string { return net.IPMask(*i).String() } 18 | func (i *ipMaskValue) Set(s string) error { 19 | ip := ParseIPv4Mask(s) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP mask: %q", s) 22 | } 23 | *i = ipMaskValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipMaskValue) Type() string { 28 | return "ipMask" 29 | } 30 | 31 | // ParseIPv4Mask written in IP form (e.g. 255.255.255.0). 32 | // This function should really belong to the net package. 33 | func ParseIPv4Mask(s string) net.IPMask { 34 | mask := net.ParseIP(s) 35 | if mask == nil { 36 | if len(s) != 8 { 37 | return nil 38 | } 39 | // net.IPMask.String() actually outputs things like ffffff00 40 | // so write a horrible parser for that as well :-( 41 | m := []int{} 42 | for i := 0; i < 4; i++ { 43 | b := "0x" + s[2*i:2*i+2] 44 | d, err := strconv.ParseInt(b, 0, 0) 45 | if err != nil { 46 | return nil 47 | } 48 | m = append(m, int(d)) 49 | } 50 | s := fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]) 51 | mask = net.ParseIP(s) 52 | if mask == nil { 53 | return nil 54 | } 55 | } 56 | return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15]) 57 | } 58 | 59 | func parseIPv4Mask(sval string) (interface{}, error) { 60 | mask := ParseIPv4Mask(sval) 61 | if mask == nil { 62 | return nil, fmt.Errorf("unable to parse %s as net.IPMask", sval) 63 | } 64 | return mask, nil 65 | } 66 | 67 | // GetIPv4Mask return the net.IPv4Mask value of a flag with the given name 68 | func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error) { 69 | val, err := f.getFlagType(name, "ipMask", parseIPv4Mask) 70 | if err != nil { 71 | return nil, err 72 | } 73 | return val.(net.IPMask), nil 74 | } 75 | 76 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 77 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 78 | func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 79 | f.VarP(newIPMaskValue(value, p), name, "", usage) 80 | } 81 | 82 | // IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 84 | f.VarP(newIPMaskValue(value, p), name, shorthand, usage) 85 | } 86 | 87 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 88 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 89 | func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 90 | CommandLine.VarP(newIPMaskValue(value, p), name, "", usage) 91 | } 92 | 93 | // IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 94 | func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 95 | CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage) 96 | } 97 | 98 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 99 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 100 | func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask { 101 | p := new(net.IPMask) 102 | f.IPMaskVarP(p, name, "", value, usage) 103 | return p 104 | } 105 | 106 | // IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash. 107 | func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 108 | p := new(net.IPMask) 109 | f.IPMaskVarP(p, name, shorthand, value, usage) 110 | return p 111 | } 112 | 113 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 114 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 115 | func IPMask(name string, value net.IPMask, usage string) *net.IPMask { 116 | return CommandLine.IPMaskP(name, "", value, usage) 117 | } 118 | 119 | // IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash. 120 | func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 121 | return CommandLine.IPMaskP(name, shorthand, value, usage) 122 | } 123 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | var _ = strings.TrimSpace 31 | 32 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 33 | *p = val 34 | return (*ipNetValue)(p) 35 | } 36 | 37 | func ipNetConv(sval string) (interface{}, error) { 38 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 39 | if err == nil { 40 | return *n, nil 41 | } 42 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 43 | } 44 | 45 | // GetIPNet return the net.IPNet value of a flag with the given name 46 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 47 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 48 | if err != nil { 49 | return net.IPNet{}, err 50 | } 51 | return val.(net.IPNet), nil 52 | } 53 | 54 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 55 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 56 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 57 | f.VarP(newIPNetValue(value, p), name, "", usage) 58 | } 59 | 60 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 61 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 62 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 63 | } 64 | 65 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 66 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 67 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 68 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 69 | } 70 | 71 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 72 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 73 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 74 | } 75 | 76 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 77 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 78 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 79 | p := new(net.IPNet) 80 | f.IPNetVarP(p, name, "", value, usage) 81 | return p 82 | } 83 | 84 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 85 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 86 | p := new(net.IPNet) 87 | f.IPNetVarP(p, name, shorthand, value, usage) 88 | return p 89 | } 90 | 91 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 92 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 93 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 94 | return CommandLine.IPNetP(name, "", value, usage) 95 | } 96 | 97 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 98 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 99 | return CommandLine.IPNetP(name, shorthand, value, usage) 100 | } 101 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string_array.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | var _ = fmt.Fprint 8 | 9 | // -- stringArray Value 10 | type stringArrayValue struct { 11 | value *[]string 12 | changed bool 13 | } 14 | 15 | func newStringArrayValue(val []string, p *[]string) *stringArrayValue { 16 | ssv := new(stringArrayValue) 17 | ssv.value = p 18 | *ssv.value = val 19 | return ssv 20 | } 21 | 22 | func (s *stringArrayValue) Set(val string) error { 23 | if !s.changed { 24 | *s.value = []string{val} 25 | s.changed = true 26 | } else { 27 | *s.value = append(*s.value, val) 28 | } 29 | return nil 30 | } 31 | 32 | func (s *stringArrayValue) Type() string { 33 | return "stringArray" 34 | } 35 | 36 | func (s *stringArrayValue) String() string { 37 | str, _ := writeAsCSV(*s.value) 38 | return "[" + str + "]" 39 | } 40 | 41 | func stringArrayConv(sval string) (interface{}, error) { 42 | sval = sval[1 : len(sval)-1] 43 | // An empty string would cause a array with one (empty) string 44 | if len(sval) == 0 { 45 | return []string{}, nil 46 | } 47 | return readAsCSV(sval) 48 | } 49 | 50 | // GetStringArray return the []string value of a flag with the given name 51 | func (f *FlagSet) GetStringArray(name string) ([]string, error) { 52 | val, err := f.getFlagType(name, "stringArray", stringArrayConv) 53 | if err != nil { 54 | return []string{}, err 55 | } 56 | return val.([]string), nil 57 | } 58 | 59 | // StringArrayVar defines a string flag with specified name, default value, and usage string. 60 | // The argument p points to a []string variable in which to store the values of the multiple flags. 61 | // The value of each argument will not try to be separated by comma 62 | func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string) { 63 | f.VarP(newStringArrayValue(value, p), name, "", usage) 64 | } 65 | 66 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. 67 | func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { 68 | f.VarP(newStringArrayValue(value, p), name, shorthand, usage) 69 | } 70 | 71 | // StringArrayVar defines a string flag with specified name, default value, and usage string. 72 | // The argument p points to a []string variable in which to store the value of the flag. 73 | // The value of each argument will not try to be separated by comma 74 | func StringArrayVar(p *[]string, name string, value []string, usage string) { 75 | CommandLine.VarP(newStringArrayValue(value, p), name, "", usage) 76 | } 77 | 78 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. 79 | func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { 80 | CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage) 81 | } 82 | 83 | // StringArray defines a string flag with specified name, default value, and usage string. 84 | // The return value is the address of a []string variable that stores the value of the flag. 85 | // The value of each argument will not try to be separated by comma 86 | func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string { 87 | p := []string{} 88 | f.StringArrayVarP(&p, name, "", value, usage) 89 | return &p 90 | } 91 | 92 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. 93 | func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string { 94 | p := []string{} 95 | f.StringArrayVarP(&p, name, shorthand, value, usage) 96 | return &p 97 | } 98 | 99 | // StringArray defines a string flag with specified name, default value, and usage string. 100 | // The return value is the address of a []string variable that stores the value of the flag. 101 | // The value of each argument will not try to be separated by comma 102 | func StringArray(name string, value []string, usage string) *[]string { 103 | return CommandLine.StringArrayP(name, "", value, usage) 104 | } 105 | 106 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. 107 | func StringArrayP(name, shorthand string, value []string, usage string) *[]string { 108 | return CommandLine.StringArrayP(name, shorthand, value, usage) 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "bytes" 5 | "encoding/csv" 6 | "fmt" 7 | "strings" 8 | ) 9 | 10 | var _ = fmt.Fprint 11 | 12 | // -- stringSlice Value 13 | type stringSliceValue struct { 14 | value *[]string 15 | changed bool 16 | } 17 | 18 | func newStringSliceValue(val []string, p *[]string) *stringSliceValue { 19 | ssv := new(stringSliceValue) 20 | ssv.value = p 21 | *ssv.value = val 22 | return ssv 23 | } 24 | 25 | func readAsCSV(val string) ([]string, error) { 26 | if val == "" { 27 | return []string{}, nil 28 | } 29 | stringReader := strings.NewReader(val) 30 | csvReader := csv.NewReader(stringReader) 31 | return csvReader.Read() 32 | } 33 | 34 | func writeAsCSV(vals []string) (string, error) { 35 | b := &bytes.Buffer{} 36 | w := csv.NewWriter(b) 37 | err := w.Write(vals) 38 | if err != nil { 39 | return "", err 40 | } 41 | w.Flush() 42 | return strings.TrimSuffix(b.String(), fmt.Sprintln()), nil 43 | } 44 | 45 | func (s *stringSliceValue) Set(val string) error { 46 | v, err := readAsCSV(val) 47 | if err != nil { 48 | return err 49 | } 50 | if !s.changed { 51 | *s.value = v 52 | } else { 53 | *s.value = append(*s.value, v...) 54 | } 55 | s.changed = true 56 | return nil 57 | } 58 | 59 | func (s *stringSliceValue) Type() string { 60 | return "stringSlice" 61 | } 62 | 63 | func (s *stringSliceValue) String() string { 64 | str, _ := writeAsCSV(*s.value) 65 | return "[" + str + "]" 66 | } 67 | 68 | func stringSliceConv(sval string) (interface{}, error) { 69 | sval = sval[1 : len(sval)-1] 70 | // An empty string would cause a slice with one (empty) string 71 | if len(sval) == 0 { 72 | return []string{}, nil 73 | } 74 | return readAsCSV(sval) 75 | } 76 | 77 | // GetStringSlice return the []string value of a flag with the given name 78 | func (f *FlagSet) GetStringSlice(name string) ([]string, error) { 79 | val, err := f.getFlagType(name, "stringSlice", stringSliceConv) 80 | if err != nil { 81 | return []string{}, err 82 | } 83 | return val.([]string), nil 84 | } 85 | 86 | // StringSliceVar defines a string flag with specified name, default value, and usage string. 87 | // The argument p points to a []string variable in which to store the value of the flag. 88 | func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) { 89 | f.VarP(newStringSliceValue(value, p), name, "", usage) 90 | } 91 | 92 | // StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. 93 | func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { 94 | f.VarP(newStringSliceValue(value, p), name, shorthand, usage) 95 | } 96 | 97 | // StringSliceVar defines a string flag with specified name, default value, and usage string. 98 | // The argument p points to a []string variable in which to store the value of the flag. 99 | func StringSliceVar(p *[]string, name string, value []string, usage string) { 100 | CommandLine.VarP(newStringSliceValue(value, p), name, "", usage) 101 | } 102 | 103 | // StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. 104 | func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { 105 | CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage) 106 | } 107 | 108 | // StringSlice defines a string flag with specified name, default value, and usage string. 109 | // The return value is the address of a []string variable that stores the value of the flag. 110 | func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string { 111 | p := []string{} 112 | f.StringSliceVarP(&p, name, "", value, usage) 113 | return &p 114 | } 115 | 116 | // StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash. 117 | func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string { 118 | p := []string{} 119 | f.StringSliceVarP(&p, name, shorthand, value, usage) 120 | return &p 121 | } 122 | 123 | // StringSlice defines a string flag with specified name, default value, and usage string. 124 | // The return value is the address of a []string variable that stores the value of the flag. 125 | func StringSlice(name string, value []string, usage string) *[]string { 126 | return CommandLine.StringSliceP(name, "", value, usage) 127 | } 128 | 129 | // StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash. 130 | func StringSliceP(name, shorthand string, value []string, usage string) *[]string { 131 | return CommandLine.StringSliceP(name, shorthand, value, usage) 132 | } 133 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/proxy/direct.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proxy 6 | 7 | import ( 8 | "net" 9 | ) 10 | 11 | type direct struct{} 12 | 13 | // Direct is a direct proxy: one that makes network connections directly. 14 | var Direct = direct{} 15 | 16 | func (direct) Dial(network, addr string) (net.Conn, error) { 17 | return net.Dial(network, addr) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/proxy/per_host.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proxy 6 | 7 | import ( 8 | "net" 9 | "strings" 10 | ) 11 | 12 | // A PerHost directs connections to a default Dialer unless the hostname 13 | // requested matches one of a number of exceptions. 14 | type PerHost struct { 15 | def, bypass Dialer 16 | 17 | bypassNetworks []*net.IPNet 18 | bypassIPs []net.IP 19 | bypassZones []string 20 | bypassHosts []string 21 | } 22 | 23 | // NewPerHost returns a PerHost Dialer that directs connections to either 24 | // defaultDialer or bypass, depending on whether the connection matches one of 25 | // the configured rules. 26 | func NewPerHost(defaultDialer, bypass Dialer) *PerHost { 27 | return &PerHost{ 28 | def: defaultDialer, 29 | bypass: bypass, 30 | } 31 | } 32 | 33 | // Dial connects to the address addr on the given network through either 34 | // defaultDialer or bypass. 35 | func (p *PerHost) Dial(network, addr string) (c net.Conn, err error) { 36 | host, _, err := net.SplitHostPort(addr) 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | return p.dialerForRequest(host).Dial(network, addr) 42 | } 43 | 44 | func (p *PerHost) dialerForRequest(host string) Dialer { 45 | if ip := net.ParseIP(host); ip != nil { 46 | for _, net := range p.bypassNetworks { 47 | if net.Contains(ip) { 48 | return p.bypass 49 | } 50 | } 51 | for _, bypassIP := range p.bypassIPs { 52 | if bypassIP.Equal(ip) { 53 | return p.bypass 54 | } 55 | } 56 | return p.def 57 | } 58 | 59 | for _, zone := range p.bypassZones { 60 | if strings.HasSuffix(host, zone) { 61 | return p.bypass 62 | } 63 | if host == zone[1:] { 64 | // For a zone "example.com", we match "example.com" 65 | // too. 66 | return p.bypass 67 | } 68 | } 69 | for _, bypassHost := range p.bypassHosts { 70 | if bypassHost == host { 71 | return p.bypass 72 | } 73 | } 74 | return p.def 75 | } 76 | 77 | // AddFromString parses a string that contains comma-separated values 78 | // specifying hosts that should use the bypass proxy. Each value is either an 79 | // IP address, a CIDR range, a zone (*.example.com) or a hostname 80 | // (localhost). A best effort is made to parse the string and errors are 81 | // ignored. 82 | func (p *PerHost) AddFromString(s string) { 83 | hosts := strings.Split(s, ",") 84 | for _, host := range hosts { 85 | host = strings.TrimSpace(host) 86 | if len(host) == 0 { 87 | continue 88 | } 89 | if strings.Contains(host, "/") { 90 | // We assume that it's a CIDR address like 127.0.0.0/8 91 | if _, net, err := net.ParseCIDR(host); err == nil { 92 | p.AddNetwork(net) 93 | } 94 | continue 95 | } 96 | if ip := net.ParseIP(host); ip != nil { 97 | p.AddIP(ip) 98 | continue 99 | } 100 | if strings.HasPrefix(host, "*.") { 101 | p.AddZone(host[1:]) 102 | continue 103 | } 104 | p.AddHost(host) 105 | } 106 | } 107 | 108 | // AddIP specifies an IP address that will use the bypass proxy. Note that 109 | // this will only take effect if a literal IP address is dialed. A connection 110 | // to a named host will never match an IP. 111 | func (p *PerHost) AddIP(ip net.IP) { 112 | p.bypassIPs = append(p.bypassIPs, ip) 113 | } 114 | 115 | // AddNetwork specifies an IP range that will use the bypass proxy. Note that 116 | // this will only take effect if a literal IP address is dialed. A connection 117 | // to a named host will never match. 118 | func (p *PerHost) AddNetwork(net *net.IPNet) { 119 | p.bypassNetworks = append(p.bypassNetworks, net) 120 | } 121 | 122 | // AddZone specifies a DNS suffix that will use the bypass proxy. A zone of 123 | // "example.com" matches "example.com" and all of its subdomains. 124 | func (p *PerHost) AddZone(zone string) { 125 | if strings.HasSuffix(zone, ".") { 126 | zone = zone[:len(zone)-1] 127 | } 128 | if !strings.HasPrefix(zone, ".") { 129 | zone = "." + zone 130 | } 131 | p.bypassZones = append(p.bypassZones, zone) 132 | } 133 | 134 | // AddHost specifies a hostname that will use the bypass proxy. 135 | func (p *PerHost) AddHost(host string) { 136 | if strings.HasSuffix(host, ".") { 137 | host = host[:len(host)-1] 138 | } 139 | p.bypassHosts = append(p.bypassHosts, host) 140 | } 141 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/proxy/proxy.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package proxy provides support for a variety of protocols to proxy network 6 | // data. 7 | package proxy // import "golang.org/x/net/proxy" 8 | 9 | import ( 10 | "errors" 11 | "net" 12 | "net/url" 13 | "os" 14 | ) 15 | 16 | // A Dialer is a means to establish a connection. 17 | type Dialer interface { 18 | // Dial connects to the given address via the proxy. 19 | Dial(network, addr string) (c net.Conn, err error) 20 | } 21 | 22 | // Auth contains authentication parameters that specific Dialers may require. 23 | type Auth struct { 24 | User, Password string 25 | } 26 | 27 | // FromEnvironment returns the dialer specified by the proxy related variables in 28 | // the environment. 29 | func FromEnvironment() Dialer { 30 | allProxy := os.Getenv("all_proxy") 31 | if len(allProxy) == 0 { 32 | return Direct 33 | } 34 | 35 | proxyURL, err := url.Parse(allProxy) 36 | if err != nil { 37 | return Direct 38 | } 39 | proxy, err := FromURL(proxyURL, Direct) 40 | if err != nil { 41 | return Direct 42 | } 43 | 44 | noProxy := os.Getenv("no_proxy") 45 | if len(noProxy) == 0 { 46 | return proxy 47 | } 48 | 49 | perHost := NewPerHost(proxy, Direct) 50 | perHost.AddFromString(noProxy) 51 | return perHost 52 | } 53 | 54 | // proxySchemes is a map from URL schemes to a function that creates a Dialer 55 | // from a URL with such a scheme. 56 | var proxySchemes map[string]func(*url.URL, Dialer) (Dialer, error) 57 | 58 | // RegisterDialerType takes a URL scheme and a function to generate Dialers from 59 | // a URL with that scheme and a forwarding Dialer. Registered schemes are used 60 | // by FromURL. 61 | func RegisterDialerType(scheme string, f func(*url.URL, Dialer) (Dialer, error)) { 62 | if proxySchemes == nil { 63 | proxySchemes = make(map[string]func(*url.URL, Dialer) (Dialer, error)) 64 | } 65 | proxySchemes[scheme] = f 66 | } 67 | 68 | // FromURL returns a Dialer given a URL specification and an underlying 69 | // Dialer for it to make network requests. 70 | func FromURL(u *url.URL, forward Dialer) (Dialer, error) { 71 | var auth *Auth 72 | if u.User != nil { 73 | auth = new(Auth) 74 | auth.User = u.User.Username() 75 | if p, ok := u.User.Password(); ok { 76 | auth.Password = p 77 | } 78 | } 79 | 80 | switch u.Scheme { 81 | case "socks5": 82 | return SOCKS5("tcp", u.Host, auth, forward) 83 | } 84 | 85 | // If the scheme doesn't match any of the built-in schemes, see if it 86 | // was registered by another package. 87 | if proxySchemes != nil { 88 | if f, ok := proxySchemes[u.Scheme]; ok { 89 | return f(u, forward) 90 | } 91 | } 92 | 93 | return nil, errors.New("proxy: unknown scheme: " + u.Scheme) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/proxy/socks5.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package proxy 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "net" 11 | "strconv" 12 | ) 13 | 14 | // SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given address 15 | // with an optional username and password. See RFC 1928. 16 | func SOCKS5(network, addr string, auth *Auth, forward Dialer) (Dialer, error) { 17 | s := &socks5{ 18 | network: network, 19 | addr: addr, 20 | forward: forward, 21 | } 22 | if auth != nil { 23 | s.user = auth.User 24 | s.password = auth.Password 25 | } 26 | 27 | return s, nil 28 | } 29 | 30 | type socks5 struct { 31 | user, password string 32 | network, addr string 33 | forward Dialer 34 | } 35 | 36 | const socks5Version = 5 37 | 38 | const ( 39 | socks5AuthNone = 0 40 | socks5AuthPassword = 2 41 | ) 42 | 43 | const socks5Connect = 1 44 | 45 | const ( 46 | socks5IP4 = 1 47 | socks5Domain = 3 48 | socks5IP6 = 4 49 | ) 50 | 51 | var socks5Errors = []string{ 52 | "", 53 | "general failure", 54 | "connection forbidden", 55 | "network unreachable", 56 | "host unreachable", 57 | "connection refused", 58 | "TTL expired", 59 | "command not supported", 60 | "address type not supported", 61 | } 62 | 63 | // Dial connects to the address addr on the network net via the SOCKS5 proxy. 64 | func (s *socks5) Dial(network, addr string) (net.Conn, error) { 65 | switch network { 66 | case "tcp", "tcp6", "tcp4": 67 | default: 68 | return nil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + network) 69 | } 70 | 71 | conn, err := s.forward.Dial(s.network, s.addr) 72 | if err != nil { 73 | return nil, err 74 | } 75 | closeConn := &conn 76 | defer func() { 77 | if closeConn != nil { 78 | (*closeConn).Close() 79 | } 80 | }() 81 | 82 | host, portStr, err := net.SplitHostPort(addr) 83 | if err != nil { 84 | return nil, err 85 | } 86 | 87 | port, err := strconv.Atoi(portStr) 88 | if err != nil { 89 | return nil, errors.New("proxy: failed to parse port number: " + portStr) 90 | } 91 | if port < 1 || port > 0xffff { 92 | return nil, errors.New("proxy: port number out of range: " + portStr) 93 | } 94 | 95 | // the size here is just an estimate 96 | buf := make([]byte, 0, 6+len(host)) 97 | 98 | buf = append(buf, socks5Version) 99 | if len(s.user) > 0 && len(s.user) < 256 && len(s.password) < 256 { 100 | buf = append(buf, 2 /* num auth methods */, socks5AuthNone, socks5AuthPassword) 101 | } else { 102 | buf = append(buf, 1 /* num auth methods */, socks5AuthNone) 103 | } 104 | 105 | if _, err := conn.Write(buf); err != nil { 106 | return nil, errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error()) 107 | } 108 | 109 | if _, err := io.ReadFull(conn, buf[:2]); err != nil { 110 | return nil, errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 111 | } 112 | if buf[0] != 5 { 113 | return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " has unexpected version " + strconv.Itoa(int(buf[0]))) 114 | } 115 | if buf[1] == 0xff { 116 | return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " requires authentication") 117 | } 118 | 119 | if buf[1] == socks5AuthPassword { 120 | buf = buf[:0] 121 | buf = append(buf, 1 /* password protocol version */) 122 | buf = append(buf, uint8(len(s.user))) 123 | buf = append(buf, s.user...) 124 | buf = append(buf, uint8(len(s.password))) 125 | buf = append(buf, s.password...) 126 | 127 | if _, err := conn.Write(buf); err != nil { 128 | return nil, errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error()) 129 | } 130 | 131 | if _, err := io.ReadFull(conn, buf[:2]); err != nil { 132 | return nil, errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 133 | } 134 | 135 | if buf[1] != 0 { 136 | return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " rejected username/password") 137 | } 138 | } 139 | 140 | buf = buf[:0] 141 | buf = append(buf, socks5Version, socks5Connect, 0 /* reserved */) 142 | 143 | if ip := net.ParseIP(host); ip != nil { 144 | if ip4 := ip.To4(); ip4 != nil { 145 | buf = append(buf, socks5IP4) 146 | ip = ip4 147 | } else { 148 | buf = append(buf, socks5IP6) 149 | } 150 | buf = append(buf, ip...) 151 | } else { 152 | if len(host) > 255 { 153 | return nil, errors.New("proxy: destination hostname too long: " + host) 154 | } 155 | buf = append(buf, socks5Domain) 156 | buf = append(buf, byte(len(host))) 157 | buf = append(buf, host...) 158 | } 159 | buf = append(buf, byte(port>>8), byte(port)) 160 | 161 | if _, err := conn.Write(buf); err != nil { 162 | return nil, errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error()) 163 | } 164 | 165 | if _, err := io.ReadFull(conn, buf[:4]); err != nil { 166 | return nil, errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 167 | } 168 | 169 | failure := "unknown error" 170 | if int(buf[1]) < len(socks5Errors) { 171 | failure = socks5Errors[buf[1]] 172 | } 173 | 174 | if len(failure) > 0 { 175 | return nil, errors.New("proxy: SOCKS5 proxy at " + s.addr + " failed to connect: " + failure) 176 | } 177 | 178 | bytesToDiscard := 0 179 | switch buf[3] { 180 | case socks5IP4: 181 | bytesToDiscard = net.IPv4len 182 | case socks5IP6: 183 | bytesToDiscard = net.IPv6len 184 | case socks5Domain: 185 | _, err := io.ReadFull(conn, buf[:1]) 186 | if err != nil { 187 | return nil, errors.New("proxy: failed to read domain length from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 188 | } 189 | bytesToDiscard = int(buf[0]) 190 | default: 191 | return nil, errors.New("proxy: got unknown address type " + strconv.Itoa(int(buf[3])) + " from SOCKS5 proxy at " + s.addr) 192 | } 193 | 194 | if cap(buf) < bytesToDiscard { 195 | buf = make([]byte, bytesToDiscard) 196 | } else { 197 | buf = buf[:bytesToDiscard] 198 | } 199 | if _, err := io.ReadFull(conn, buf); err != nil { 200 | return nil, errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 201 | } 202 | 203 | // Also need to discard the port number 204 | if _, err := io.ReadFull(conn, buf[:2]); err != nil { 205 | return nil, errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error()) 206 | } 207 | 208 | closeConn = nil 209 | return conn, nil 210 | } 211 | -------------------------------------------------------------------------------- /version/cmd.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | var ( 6 | // Cmd can be added to other commands to provide a version subcommand with 7 | // the correct version of swarm. 8 | Cmd = &cobra.Command{ 9 | Use: "version", 10 | Short: "Print version number of docker-volume-ipfs", 11 | Run: func(cmd *cobra.Command, args []string) { 12 | PrintVersion() 13 | }, 14 | } 15 | ) 16 | -------------------------------------------------------------------------------- /version/print.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | ) 8 | 9 | // FprintVersion outputs the version string to the writer, in the following 10 | // format, followed by a newline: 11 | // 12 | // 13 | // 14 | // For example, a binary "registry" built from github.com/docker/distribution 15 | // with version "v2.0" would print the following: 16 | // 17 | // registry github.com/docker/distribution v2.0 18 | // 19 | func FprintVersion(w io.Writer) { 20 | fmt.Fprintln(w, os.Args[0], Package, Version) 21 | } 22 | 23 | // PrintVersion outputs the version information, from Fprint, to stdout. 24 | func PrintVersion() { 25 | FprintVersion(os.Stdout) 26 | } 27 | -------------------------------------------------------------------------------- /version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | // Package is the overall, canonical project import path under which the 4 | // package was built. 5 | var Package = "github.com/vdemeester/docker-volume-ipfs" 6 | 7 | // Version indicates which version of the binary is running. This is set to 8 | // the latest release tag by hand, always suffixed by "+unknown". During 9 | // build, it will be replaced by the actual version. The value here will be 10 | // used if the registry is run after a go get based install. 11 | var Version = "c1491d8.m+unknown" 12 | -------------------------------------------------------------------------------- /version/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This bash script outputs the current, desired content of version.go, using 4 | # git describe. For best effect, pipe this to the target file. Generally, this 5 | # only needs to updated for releases. The actual value of will be replaced 6 | # during build time if the makefile is used. 7 | 8 | set -e 9 | 10 | cat <