vendor: add freeport package
This commit is contained in:
parent
34a24a5ed2
commit
008809931f
|
@ -1,5 +1,5 @@
|
||||||
hash: 9099fc50c197f3783ebc0a260c2e75405761ebcffac9b161c1b061e6e6f9ef40
|
hash: 586b41b5eee9053da918e7fcd053abfce93572b24d37f699e299754101672f19
|
||||||
updated: 2017-08-14T11:13:55.694170589+08:00
|
updated: 2017-08-14T14:01:32.710933452+08:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/aristanetworks/goarista
|
- name: github.com/aristanetworks/goarista
|
||||||
version: 8e44bec0a94d7c1f0cdf28ed5215e5cfab441ad0
|
version: 8e44bec0a94d7c1f0cdf28ed5215e5cfab441ad0
|
||||||
|
@ -198,6 +198,8 @@ imports:
|
||||||
- specs-go/v1
|
- specs-go/v1
|
||||||
- name: github.com/pborman/uuid
|
- name: github.com/pborman/uuid
|
||||||
version: e790cca94e6cc75c7064b1332e63811d4aae1a53
|
version: e790cca94e6cc75c7064b1332e63811d4aae1a53
|
||||||
|
- name: github.com/phayes/freeport
|
||||||
|
version: e7681b37614941bf73b404e0caa37f19e33b5fed
|
||||||
- name: github.com/pkg/errors
|
- name: github.com/pkg/errors
|
||||||
version: c605e284fe17294bda444b34710735b29d1a9d90
|
version: c605e284fe17294bda444b34710735b29d1a9d90
|
||||||
- name: github.com/rcrowley/go-metrics
|
- name: github.com/rcrowley/go-metrics
|
||||||
|
|
|
@ -29,3 +29,4 @@ import:
|
||||||
- package: github.com/onsi/gomega
|
- package: github.com/onsi/gomega
|
||||||
version: ^1.2.0
|
version: ^1.2.0
|
||||||
- package: gopkg.in/yaml.v2
|
- package: gopkg.in/yaml.v2
|
||||||
|
- package: github.com/phayes/freeport
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
Open Source License (BSD 3-Clause)
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2014, Patrick Hayes / HighWire Press
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,27 @@
|
||||||
|
FreePort
|
||||||
|
========
|
||||||
|
|
||||||
|
Get a free open TCP port that is ready to use
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ask the kernel to give us an open port.
|
||||||
|
export port=$(freeport)
|
||||||
|
|
||||||
|
# Start standalone httpd server for testing
|
||||||
|
httpd -X -c "Listen $port" &
|
||||||
|
|
||||||
|
# Curl local server on the selected port
|
||||||
|
curl localhost:$port
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Binary Downloads
|
||||||
|
- Mac: https://phayes.github.io/bin/current/freeport/mac/freeport.gz
|
||||||
|
- Linux: https://phayes.github.io/bin/current/freeport/linux/freeport.gz
|
||||||
|
|
||||||
|
#### Building From Source
|
||||||
|
```bash
|
||||||
|
sudo apt-get install golang # Download go. Alternativly build from source: https://golang.org/doc/install/source
|
||||||
|
mkdir ~/.gopath && export GOPATH=~/.gopath # Replace with desired GOPATH
|
||||||
|
export PATH=$PATH:$GOPATH/bin # For convenience, add go's bin dir to your PATH
|
||||||
|
go get github.com/phayes/freeport/cmd/freeport
|
||||||
|
```
|
|
@ -0,0 +1,11 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/phayes/freeport"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(strconv.Itoa(freeport.GetPort()))
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package freeport
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ask the kernel for a free open port that is ready to use
|
||||||
|
func GetPort() int {
|
||||||
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
l, err := net.ListenTCP("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer l.Close()
|
||||||
|
return l.Addr().(*net.TCPAddr).Port
|
||||||
|
}
|
Loading…
Reference in New Issue